暂无描述

HistoryView.swift 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //
  2. // HistoryView.swift
  3. // Flowerdex
  4. //
  5. // Created by Víctor A. Hernández on 12/21/20.
  6. //
  7. import SwiftUI
  8. struct HistoryView: View {
  9. @EnvironmentObject var hModel: HistoryService
  10. var body: some View {
  11. NavigationView {
  12. ScrollableHistoryContent()
  13. }
  14. .onAppear {
  15. self.hModel.getHistory()
  16. }
  17. }
  18. }
  19. struct ScrollableHistoryContent: View {
  20. @EnvironmentObject var hModel: HistoryService
  21. var body: some View {
  22. if hModel.response == .success {
  23. List {
  24. HistoryList(flowerList: hModel.items)
  25. }
  26. .navigationBarTitle("Discover")
  27. } else if hModel.response == .loading || hModel.response == .unfetched {
  28. // TODO: make this centered vertically within parent ScrollView
  29. ProgressView("Loading...")
  30. } else if hModel.response == .failure {
  31. // TODO: make this centered vertically within parent ScrollView
  32. FailureIcon()
  33. }
  34. }
  35. }
  36. struct HistoryList: View {
  37. var flowerList: [FlowerVerbose]
  38. var body: some View {
  39. ForEach(flowerList) { flower in
  40. NavigationLink(destination: FlowerVerboseDetailView(flower: flower, hasBeenFoundLocal: flower.hasBeenFound)) {
  41. Text(flower.commonName.capitalized)
  42. }
  43. // .foregroundColor(Constants.Colors.blueGray)
  44. }
  45. }
  46. }