Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// MyCapsules.swift// twogetskills//// Created by Efrain Yanez Recanatini on 7/10/22.//import Foundationimport SwiftUIstruct MyCapsulesView: View {@EnvironmentObject private var networkMonitor : NetworkMonitor@EnvironmentObject private var appNavigation : AppNavigation@State private var selectedType: CapsulePickerType = .pending@State private var search : String = ""@State private var searching : Bool = false@State private var showInProgress : Bool = true@StateObject private var listingViewModel : MyCapsulesListingViewModel = MyCapsulesListingViewModel()@StateObject private var inprogressViewModel : MyCapsulesInProgressViewModel = MyCapsulesInProgressViewModel()private let firstName : Stringprivate var appData = AppData.sharedInstanceinit (){let arrayFirstName = appData.userFirstname.split(separator: " ")firstName = String(arrayFirstName[0])}var body: some View {VStack(spacing: 0) {HStack {Image("logo").resizable().frame(width: 32, height: 32, alignment: .center).aspectRatio(contentMode: .fit).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground")).padding(.leading, 16)Text(networkMonitor.status == .disconnected ? Config.LANG_ERROR_NETWORK_MESSAGE_SHORT : Config.LANG_TAB_BAR_BUTTON_MY_CAPSULES).font(Font.custom(Config.FONT_NAME_REGULAR, size: Config.FONT_SIZE_APP_BAR_HEAD1 )).foregroundColor(networkMonitor.status == .disconnected ? Color("color_network_disconnected_foreground") : Color("color_app_bar_foreground")).padding(.leading, 4)Spacer()}.edgesIgnoringSafeArea(.top).frame(height: 50).background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))Divider().background(networkMonitor.status == .disconnected ? Color("color_network_disconnected_background") : Color("color_app_bar_background"))MyCapsulesHeaderView(showInProgress: self.$showInProgress, firstName: self.firstName)if self.showInProgress {MyCapsuleInProgressView(capsuleUuid: self.inprogressViewModel.capsule.uuid).frame(height: 170).transition(.scale).environmentObject(appNavigation)Divider()}MyCapsulesPickerView (selectedType: self.$selectedType).frame(height: 48)Divider()MyCapsulesFilterView(search: self.$search, searching: self.$searching).frame(height: 64)Divider()Spacer()ScrollView {LazyVStack {ForEach(0..<self.listingViewModel.capsules.count) { index inif self.selectedType == .pending && self.listingViewModel.capsules[index].viewSlides == 0 {if(self.search.isEmpty) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)} else {if self.listingViewModel.capsules[index].name.contains(self.search) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)}}}if self.selectedType == .inprogress && self.listingViewModel.capsules[index].viewSlides > 0&& self.listingViewModel.capsules[index].completed == 0 {if(self.search.isEmpty) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)} else {if self.listingViewModel.capsules[index].name.contains(self.search) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)}}}if self.selectedType == .completed && self.listingViewModel.capsules[index].viewSlides > 0&& self.listingViewModel.capsules[index].completed == 1 {if(self.search.isEmpty) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)} else {if self.listingViewModel.capsules[index].name.contains(self.search) {MyCapsuleListItemView(capsuleUuid : self.listingViewModel.capsules[index].uuid).environmentObject(appNavigation)}}}//.id(index)}}}.onAppear {self.listingViewModel.fetch()self.inprogressViewModel.fetch()}.background(Color("color_capsule_list_item_background"))}}}struct MyCapsulesView_Previews: PreviewProvider {static var previews: some View {MyCapsulesView()}}