LogView.swift 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. //
  2. // LogView.swift
  3. // LoopFollow
  4. //
  5. // Created by Jonas Björkert on 2025-01-13.
  6. // Copyright © 2025 Jon Fawcett. All rights reserved.
  7. //
  8. import SwiftUI
  9. struct LogView: View {
  10. @ObservedObject var viewModel = LogViewModel()
  11. @Environment(\.presentationMode) var presentationMode
  12. var body: some View {
  13. NavigationView {
  14. VStack {
  15. Picker("Category", selection: $viewModel.selectedCategory) {
  16. Text("All").tag(LogManager.Category?.none)
  17. ForEach(LogManager.Category.allCases, id: \.self) { category in
  18. Text(category.rawValue).tag(LogManager.Category?.some(category))
  19. }
  20. }
  21. .pickerStyle(MenuPickerStyle())
  22. SearchBar(text: $viewModel.searchText)
  23. .padding([.leading, .trailing])
  24. ScrollView {
  25. LazyVStack(alignment: .leading, spacing: 2) {
  26. ForEach(viewModel.filteredLogEntries) { entry in
  27. Text(entry.text)
  28. .font(.system(size: 12, design: .monospaced))
  29. .frame(maxWidth: .infinity, alignment: .leading)
  30. .padding(.vertical, 0)
  31. }
  32. }
  33. .padding(.horizontal)
  34. }
  35. }
  36. .navigationBarTitle("Today's Logs", displayMode: .inline)
  37. .toolbar {
  38. ToolbarItem(placement: .navigationBarTrailing) {
  39. Button("Done") {
  40. presentationMode.wrappedValue.dismiss()
  41. }
  42. }
  43. }
  44. .onAppear {
  45. viewModel.loadLogEntries()
  46. }
  47. }
  48. }
  49. }