From 3d29c9e600a01493886e9be8bf32a1c1da0cec18 Mon Sep 17 00:00:00 2001 From: Thomas Ricouard Date: Thu, 4 Jan 2024 16:53:10 +0100 Subject: [PATCH] Fix account swap for favorites and bookmarks --- IceCubesApp/App/Tabs/NavigationTab.swift | 10 ++++++++++ .../StatusesLists/AccountStatusesListView.swift | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/IceCubesApp/App/Tabs/NavigationTab.swift b/IceCubesApp/App/Tabs/NavigationTab.swift index 39b58c13..78ecd6ed 100644 --- a/IceCubesApp/App/Tabs/NavigationTab.swift +++ b/IceCubesApp/App/Tabs/NavigationTab.swift @@ -2,6 +2,7 @@ import SwiftUI import Env import AppAccount import DesignSystem +import Network @MainActor struct NavigationTab: View { @@ -11,6 +12,7 @@ struct NavigationTab: View { @Environment(CurrentAccount.self) private var currentAccount @Environment(UserPreferences.self) private var userPreferences @Environment(Theme.self) private var theme + @Environment(Client.self) private var client var content: () -> Content @@ -26,10 +28,18 @@ struct NavigationTab: View { .withEnvironments() .withAppRouter() .withSheetDestinations(sheetDestinations: $routerPath.presentedSheet) + .withSafariRouter() .toolbar { ToolbarTab(routerPath: $routerPath) } .toolbarBackground(theme.primaryBackgroundColor.opacity(0.50), for: .navigationBar) + .onChange(of: client.id) { + routerPath.path = [] + } + .onAppear { + routerPath.client = client + } + .withSafariRouter() } .environment(routerPath) } diff --git a/Packages/Account/Sources/Account/StatusesLists/AccountStatusesListView.swift b/Packages/Account/Sources/Account/StatusesLists/AccountStatusesListView.swift index 8f49366f..a5f530d4 100644 --- a/Packages/Account/Sources/Account/StatusesLists/AccountStatusesListView.swift +++ b/Packages/Account/Sources/Account/StatusesLists/AccountStatusesListView.swift @@ -38,5 +38,13 @@ public struct AccountStatusesListView: View { await viewModel.fetchNewestStatuses(pullToRefresh: false) isLoaded = true } + .onChange(of: client.id) { _, _ in + isLoaded = false + viewModel.client = client + Task { + await viewModel.fetchNewestStatuses(pullToRefresh: false) + isLoaded = true + } + } } }