This commit is contained in:
Thomas Ricouard 2023-12-26 13:51:41 +01:00
parent c4bff07c40
commit f3a48118f0
3 changed files with 15 additions and 14 deletions

View file

@ -18,16 +18,6 @@ extension IceCubesApp {
SoundEffectManager.shared.playSound(.tabSelection) SoundEffectManager.shared.playSound(.tabSelection)
selectedTab = newTab selectedTab = newTab
DispatchQueue.main.async {
if selectedTab == .notifications,
let token = appAccountsManager.currentAccount.oauthToken
{
userPreferences.notificationsCount[token] = 0
watcher.unreadNotificationsCount = 0
}
}
})) { })) {
ForEach(availableTabs) { tab in ForEach(availableTabs) { tab in
tab.makeContentView(popToRootTab: $popToRootTab) tab.makeContentView(popToRootTab: $popToRootTab)
@ -44,6 +34,7 @@ extension IceCubesApp {
} }
} }
.id(appAccountsManager.currentClient.id) .id(appAccountsManager.currentClient.id)
.environment(\.selectedTab, selectedTab)
} }
private func badgeFor(tab: Tab) -> Int { private func badgeFor(tab: Tab) -> Int {

View file

@ -11,6 +11,7 @@ import Timeline
struct NotificationsTab: View { struct NotificationsTab: View {
@Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool @Environment(\.isSecondaryColumn) private var isSecondaryColumn: Bool
@Environment(\.scenePhase) private var scenePhase @Environment(\.scenePhase) private var scenePhase
@Environment(\.selectedTab) private var selectedTab: Tab
@Environment(Theme.self) private var theme @Environment(Theme.self) private var theme
@Environment(Client.self) private var client @Environment(Client.self) private var client
@ -58,10 +59,8 @@ struct NotificationsTab: View {
} }
.onAppear { .onAppear {
routerPath.client = client routerPath.client = client
if isSecondaryColumn {
clearNotifications() clearNotifications()
} }
}
.withSafariRouter() .withSafariRouter()
.environment(routerPath) .environment(routerPath)
.onChange(of: $popToRootTab.wrappedValue) { _, newValue in .onChange(of: $popToRootTab.wrappedValue) { _, newValue in
@ -101,7 +100,7 @@ struct NotificationsTab: View {
} }
private func clearNotifications() { private func clearNotifications() {
if isSecondaryColumn { if selectedTab == .notifications || isSecondaryColumn {
if let token = appAccount.currentAccount.oauthToken { if let token = appAccount.currentAccount.oauthToken {
userPreferences.notificationsCount[token] = 0 userPreferences.notificationsCount[token] = 0
} }

View file

@ -113,3 +113,14 @@ enum Tab: Int, Identifiable, Hashable {
} }
} }
} }
private struct SelectedTab: EnvironmentKey {
static let defaultValue: Tab = .timeline
}
extension EnvironmentValues {
var selectedTab: Tab {
get { self[SelectedTab.self] }
set { self[SelectedTab.self] = newValue }
}
}