Rev 1 | Ir a la última revisión | Autoría | Comparar con el anterior | Ultima modificación | Ver Log |
//// NotificationListView.swift// twogetskills//// Created by Efrain Yanez Recanatini on 7/31/22.//import SwiftUIimport SafariServicesstruct NotificationListView: View {@EnvironmentObject private var networkMonitor : NetworkMonitor@EnvironmentObject private var appNavigation : AppNavigation@ObservedObject var viewModel :NotificationListViewModel@State private var sheetURL: String = ""@State private var sheetShow = falseprivate let appData = AppData.sharedInstanceinit() {let userNotificationDao = UserNotificationDao.sharedInstanceuserNotificationDao.removeExpired(userUuid:appData.userUuid)viewModel = NotificationListViewModel()}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_NOTIFICATIONS).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"))ScrollView {if self.viewModel.notifications.count == 0 {NotificationListItemEmptyView()} else {LazyVStack {ForEach(self.viewModel.notifications) { notificationItem in//let notificationItem = self.viewModel.notifications[index]NotificationListItemView(notification: notificationItem,onExecute: {if notificationItem.command == Constants.NOTIFICATION_COMMAND_REFRESH_CONTENT && notificationItem.viewed == 0 {let notificationDao = UserNotificationDao.sharedInstancenotificationDao.markViewedAllPendingByUserUuidAndCommand(userUuid: appData.userUuid, command: Constants.NOTIFICATION_COMMAND_REFRESH_CONTENT)appData.refreshContentActionRequired = trueappData.save()withAnimation {appNavigation.subpageActive = .topics}} else if notificationItem.command == Constants.NOTIFICATION_COMMAND_OPEN_URL &&!notificationItem.url.isEmpty &¬ificationItem.viewed == 0 {let notificationDao = UserNotificationDao.sharedInstancenotificationDao.markViewed(id: notificationItem.id)self.viewModel.fetchAll()self.sheetURL = notificationItem.urlself.sheetShow = true}}) {DispatchQueue.main.async {let notificationDao = UserNotificationDao.sharedInstancenotificationDao.remove(id: notificationItem.id)self.viewModel.fetchAll()}}}}}}.padding(.top, 5)}.onAppear {viewModel.fetchAll()}.popover(isPresented: self.$sheetShow, content: {SafariView(sURL: self.sheetURL)}) }}struct NotificationListView_Previews: PreviewProvider {static var previews: some View {NotificationListView()}}