From d393c4b90fbe944acb8efc739ed6cfdb079dbf11 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 29 Dec 2022 06:55:53 +0100 Subject: [PATCH] Fix notifications tab + prepare multi account --- IceCubesApp/App/IceCubesApp.swift | 2 +- IceCubesApp/App/Tabs/Settings/SettingsTab.swift | 13 ++++--------- IceCubesApp/App/Tabs/TimelineTab.swift | 4 +--- Packages/Env/Sources/Env/CurrentAccount.swift | 5 ++++- .../Timeline/Sources/Timeline/TimelineView.swift | 2 +- 5 files changed, 11 insertions(+), 15 deletions(-) diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index bc9f41cc..3b34c69a 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -38,9 +38,9 @@ struct IceCubesApp: App { tab.makeContentView(popToRootTab: $popToRootTab) .tabItem { tab.label - .badge(tab == .notifications ? watcher.unreadNotificationsCount : 0) } .tag(tab) + .badge(tab == .notifications ? watcher.unreadNotificationsCount : 0) } } .tint(theme.tintColor) diff --git a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift index 2caea9f9..58dbf721 100644 --- a/IceCubesApp/App/Tabs/Settings/SettingsTab.swift +++ b/IceCubesApp/App/Tabs/Settings/SettingsTab.swift @@ -9,12 +9,12 @@ import DesignSystem struct SettingsTabs: View { @Environment(\.openURL) private var openURL @EnvironmentObject private var client: Client + @EnvironmentObject private var currentAccount: CurrentAccount @EnvironmentObject private var currentInstance: CurrentInstance @EnvironmentObject private var appAccountsManager: AppAccountsManager @EnvironmentObject private var theme: Theme @State private var signInInProgress = false - @State private var accountData: Account? @State private var signInServer = IceCubesApp.defaultServer var body: some View { @@ -36,7 +36,7 @@ struct SettingsTabs: View { .task { if appAccountsManager.currentAccount.oauthToken != nil { signInInProgress = true - await refreshAccountInfo() + await currentAccount.fetchCurrentAccount() await currentInstance.fetchCurrentInstance() signInInProgress = false } @@ -45,7 +45,7 @@ struct SettingsTabs: View { private var accountSection: some View { Section("Account") { - if let accountData { + if let accountData = currentAccount.account { VStack(alignment: .leading) { Text(appAccountsManager.currentAccount.server) .font(.headline) @@ -133,7 +133,6 @@ struct SettingsTabs: View { private var signOutButton: some View { Button { - accountData = nil appAccountsManager.delete(account: appAccountsManager.currentAccount) } label: { Text("Sign out").foregroundColor(.red) @@ -155,15 +154,11 @@ struct SettingsTabs: View { do { let oauthToken = try await client.continueOauthFlow(url: url) appAccountsManager.add(account: AppAccount(server: client.server, oauthToken: oauthToken)) - await refreshAccountInfo() + await currentAccount.fetchCurrentAccount() await currentInstance.fetchCurrentInstance() signInInProgress = false } catch { signInInProgress = false } } - - private func refreshAccountInfo() async { - accountData = try? await client.get(endpoint: Accounts.verifyCredentials) - } } diff --git a/IceCubesApp/App/Tabs/TimelineTab.swift b/IceCubesApp/App/Tabs/TimelineTab.swift index 6b00a6b3..1848760e 100644 --- a/IceCubesApp/App/Tabs/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/TimelineTab.swift @@ -32,9 +32,7 @@ struct TimelineTab: View { } .onAppear { routeurPath.client = client - if !client.isAuth { - timeline = .pub - } + timeline = client.isAuth ? .home : .pub } .environmentObject(routeurPath) .onChange(of: $popToRootTab.wrappedValue) { popToRootTab in diff --git a/Packages/Env/Sources/Env/CurrentAccount.swift b/Packages/Env/Sources/Env/CurrentAccount.swift index d2dc60eb..64d8783a 100644 --- a/Packages/Env/Sources/Env/CurrentAccount.swift +++ b/Packages/Env/Sources/Env/CurrentAccount.swift @@ -20,7 +20,10 @@ public class CurrentAccount: ObservableObject { } public func fetchCurrentAccount() async { - guard let client = client, client.isAuth else { return } + guard let client = client, client.isAuth else { + account = nil + return + } Task { account = try? await client.get(endpoint: Accounts.verifyCredentials) } diff --git a/Packages/Timeline/Sources/Timeline/TimelineView.swift b/Packages/Timeline/Sources/Timeline/TimelineView.swift index e2fdf233..87af1b78 100644 --- a/Packages/Timeline/Sources/Timeline/TimelineView.swift +++ b/Packages/Timeline/Sources/Timeline/TimelineView.swift @@ -34,7 +34,7 @@ public struct TimelineView: View { } .padding(.top, DS.Constants.layoutPadding) } - if viewModel.timeline == .home { + if viewModel.pendingStatusesEnabled { makePendingNewPostsView(proxy: proxy) } }