LogView.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // LoopFollow
  2. // LogView.swift
  3. import SwiftUI
  4. struct LogView: View {
  5. var onBack: (() -> Void)?
  6. @ObservedObject var viewModel = LogViewModel()
  7. var body: some View {
  8. NavigationView {
  9. VStack {
  10. Picker("Category", selection: $viewModel.selectedCategory) {
  11. Text("All").tag(LogManager.Category?.none)
  12. ForEach(LogManager.Category.allCases, id: \.self) { category in
  13. Text(category.rawValue).tag(LogManager.Category?.some(category))
  14. }
  15. }
  16. .pickerStyle(MenuPickerStyle())
  17. SearchBar(text: $viewModel.searchText)
  18. .padding([.leading, .trailing])
  19. ScrollView {
  20. LazyVStack(alignment: .leading, spacing: 2) {
  21. ForEach(viewModel.filteredLogEntries) { entry in
  22. Text(entry.text)
  23. .font(.system(size: 12, design: .monospaced))
  24. .frame(maxWidth: .infinity, alignment: .leading)
  25. .padding(.vertical, 0)
  26. }
  27. }
  28. .padding(.horizontal)
  29. }
  30. }
  31. .onAppear {
  32. viewModel.loadLogEntries()
  33. }
  34. .navigationBarTitle("Today's Logs", displayMode: .inline)
  35. .toolbar {
  36. if let onBack {
  37. ToolbarItem(placement: .navigationBarLeading) {
  38. Button(action: onBack) {
  39. Image(systemName: "chevron.left")
  40. }
  41. }
  42. }
  43. }
  44. }
  45. .preferredColorScheme(Storage.shared.appearanceMode.value.colorScheme)
  46. }
  47. }