diff --git a/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsView.swift b/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsView.swift index 08d99fc..42eadb0 100644 --- a/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsView.swift +++ b/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsView.swift @@ -20,17 +20,17 @@ struct PushNotificationsSettingsView: View { if #available(iOS 15, *) { pushNotificationsSettingsList() .safeAreaInset(edge: .bottom) { - refreshTokenFooterView() + buttonsFooterView() } } else { ZStack(alignment: .bottom) { pushNotificationsSettingsList() - refreshTokenFooterView() + buttonsFooterView() } } - } .navigationTitle("Push notifications settings") + .onAppear { viewModel.refreshToken(shouldRegenerate: false) } .copiedAlert(isPresented: $viewModel.isShowingCopiedAlert) .alert(isPresented: $viewModel.hasError) { Alert( @@ -80,9 +80,10 @@ private extension PushNotificationsSettingsView { }.buttonStyle(.borderless) } - func refreshTokenFooterView() -> some View { - ButtonFilled(text: "Refresh token") { - viewModel.refreshToken() + func buttonsFooterView() -> some View { + VStack(spacing: 8) { + ButtonFilled(text: "Reload token") { viewModel.refreshToken(shouldRegenerate: false) } + ButtonFilled(text: "Generate new token", style: .danger) { viewModel.refreshToken(shouldRegenerate: true) } } .padding(16) .background(Glass().edgesIgnoringSafeArea(.bottom)) diff --git a/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsViewModel.swift b/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsViewModel.swift index 1b417d4..60e8fb0 100644 --- a/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsViewModel.swift +++ b/Sources/AppDebugMode/Screens/PushNotificationsSettingsView/PushNotificationsSettingsViewModel.swift @@ -26,7 +26,6 @@ final class PushNotificationsSettingsViewModel: ObservableObject { init(pushNotificationsProvider: PushNotificationsProvider) { self.pushNotificationsProvider = pushNotificationsProvider - self.token = pushNotificationsProvider.token } } @@ -41,11 +40,13 @@ extension PushNotificationsSettingsViewModel { isShowingCopiedAlert = true } } - - func refreshToken() { - Task { + + func refreshToken(shouldRegenerate: Bool) { + Task { @MainActor in do { - try await pushNotificationsProvider.deleteToken() + if shouldRegenerate { + try await pushNotificationsProvider.deleteToken() + } token = try await pushNotificationsProvider.getToken() } catch { self.error = error