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

View file

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