diff --git a/IceCubesApp.xcodeproj/project.pbxproj b/IceCubesApp.xcodeproj/project.pbxproj index d3a64ba6..376b7dda 100644 --- a/IceCubesApp.xcodeproj/project.pbxproj +++ b/IceCubesApp.xcodeproj/project.pbxproj @@ -9,6 +9,7 @@ /* Begin PBXBuildFile section */ 9F24EEB829360C330042359D /* Preview Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 9F24EEB729360C330042359D /* Preview Assets.xcassets */; }; 9F295540292B6C3400E0E81B /* Timeline in Frameworks */ = {isa = PBXBuildFile; productRef = 9F29553F292B6C3400E0E81B /* Timeline */; }; + 9F2B92F6295AE04800DE16D0 /* Tabs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F2B92F5295AE04800DE16D0 /* Tabs.swift */; }; 9F35DB44294F9A7D00B3281A /* Status in Frameworks */ = {isa = PBXBuildFile; productRef = 9F35DB43294F9A7D00B3281A /* Status */; }; 9F35DB4729506F6600B3281A /* NotificationTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9F35DB4629506F6600B3281A /* NotificationTab.swift */; }; 9F35DB4A29506FA100B3281A /* Notifications in Frameworks */ = {isa = PBXBuildFile; productRef = 9F35DB4929506FA100B3281A /* Notifications */; }; @@ -34,6 +35,7 @@ 9F24EEB729360C330042359D /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = ""; }; 9F29553D292B67B600E0E81B /* Network */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Network; path = Packages/Network; sourceTree = ""; }; 9F29553E292B6AF600E0E81B /* Timeline */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Timeline; path = Packages/Timeline; sourceTree = ""; }; + 9F2B92F5295AE04800DE16D0 /* Tabs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Tabs.swift; sourceTree = ""; }; 9F35DB42294F9A2900B3281A /* Status */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = Status; path = Packages/Status; sourceTree = ""; }; 9F35DB45294FA04C00B3281A /* DesignSystem */ = {isa = PBXFileReference; lastKnownFileType = wrapper; name = DesignSystem; path = Packages/DesignSystem; sourceTree = ""; }; 9F35DB4629506F6600B3281A /* NotificationTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationTab.swift; sourceTree = ""; }; @@ -104,6 +106,7 @@ 9F35DB4629506F6600B3281A /* NotificationTab.swift */, 9F35DB4B2952005C00B3281A /* AccountTab.swift */, 9F55C68C2955968700F94077 /* ExploreTab.swift */, + 9F2B92F5295AE04800DE16D0 /* Tabs.swift */, ); path = Tabs; sourceTree = ""; @@ -259,6 +262,7 @@ 9F35DB4C2952005C00B3281A /* AccountTab.swift in Sources */, 9FAE4ACB293783B000772766 /* SettingsTab.swift in Sources */, 9FAE4AD32937A0C600772766 /* AppAccountsManager.swift in Sources */, + 9F2B92F6295AE04800DE16D0 /* Tabs.swift in Sources */, 9F398AB329360A4C00A889F2 /* TimelineTab.swift in Sources */, 9F398AA62935FE8A00A889F2 /* AppRouteur.swift in Sources */, 9FBFE63D292A715500C250E9 /* IceCubesApp.swift in Sources */, diff --git a/IceCubesApp/App/IceCubesApp.swift b/IceCubesApp/App/IceCubesApp.swift index 6e01798f..65784022 100644 --- a/IceCubesApp/App/IceCubesApp.swift +++ b/IceCubesApp/App/IceCubesApp.swift @@ -7,10 +7,6 @@ import DesignSystem @main struct IceCubesApp: App { - enum Tab: Int { - case timeline, notifications, explore, account, settings, other - } - public static let defaultServer = "mastodon.social" @Environment(\.scenePhase) private var scenePhase @@ -37,34 +33,14 @@ struct IceCubesApp: App { } selectedTab = newTab })) { - TimelineTab(popToRootTab: $popToRootTab) - .tabItem { - Label("Timeline", systemImage: "rectangle.on.rectangle") - } - .tag(Tab.timeline) - if appAccountsManager.currentClient.isAuth { - NotificationsTab(popToRootTab: $popToRootTab) + ForEach(appAccountsManager.currentClient.isAuth ? Tab.loggedInTabs() : Tab.loggedOutTab()) { tab in + tab.makeContentView(popToRootTab: $popToRootTab) .tabItem { - Label("Notifications", systemImage: "bell") + tab.label + .badge(tab == .notifications ? watcher.unreadNotificationsCount : 0) } - .badge(watcher.unreadNotificationsCount) - .tag(Tab.notifications) - ExploreTab(popToRootTab: $popToRootTab) - .tabItem { - Label("Explore", systemImage: "magnifyingglass") - } - .tag(Tab.explore) - AccountTab(popToRootTab: $popToRootTab) - .tabItem { - Label("Profile", systemImage: "person.circle") - } - .tag(Tab.account) + .tag(tab) } - SettingsTabs() - .tabItem { - Label("Settings", systemImage: "gear") - } - .tag(Tab.settings) } .tint(theme.tintColor) .onChange(of: appAccountsManager.currentClient) { newClient in diff --git a/IceCubesApp/App/Tabs/AccountTab.swift b/IceCubesApp/App/Tabs/AccountTab.swift index 4296e3f7..e92d7e77 100644 --- a/IceCubesApp/App/Tabs/AccountTab.swift +++ b/IceCubesApp/App/Tabs/AccountTab.swift @@ -9,7 +9,7 @@ struct AccountTab: View { @EnvironmentObject private var client: Client @EnvironmentObject private var currentAccount: CurrentAccount @StateObject private var routeurPath = RouterPath() - @Binding var popToRootTab: IceCubesApp.Tab + @Binding var popToRootTab: Tab var body: some View { NavigationStack(path: $routeurPath.path) { diff --git a/IceCubesApp/App/Tabs/ExploreTab.swift b/IceCubesApp/App/Tabs/ExploreTab.swift index 09fb4207..c4e00440 100644 --- a/IceCubesApp/App/Tabs/ExploreTab.swift +++ b/IceCubesApp/App/Tabs/ExploreTab.swift @@ -9,7 +9,7 @@ import Network struct ExploreTab: View { @EnvironmentObject private var client: Client @StateObject private var routeurPath = RouterPath() - @Binding var popToRootTab: IceCubesApp.Tab + @Binding var popToRootTab: Tab var body: some View { NavigationStack(path: $routeurPath.path) { diff --git a/IceCubesApp/App/Tabs/NotificationTab.swift b/IceCubesApp/App/Tabs/NotificationTab.swift index e6719914..d7588118 100644 --- a/IceCubesApp/App/Tabs/NotificationTab.swift +++ b/IceCubesApp/App/Tabs/NotificationTab.swift @@ -8,7 +8,7 @@ struct NotificationsTab: View { @EnvironmentObject private var client: Client @EnvironmentObject private var watcher: StreamWatcher @StateObject private var routeurPath = RouterPath() - @Binding var popToRootTab: IceCubesApp.Tab + @Binding var popToRootTab: Tab var body: some View { NavigationStack(path: $routeurPath.path) { diff --git a/IceCubesApp/App/Tabs/Tabs.swift b/IceCubesApp/App/Tabs/Tabs.swift new file mode 100644 index 00000000..f3ffd2e3 --- /dev/null +++ b/IceCubesApp/App/Tabs/Tabs.swift @@ -0,0 +1,58 @@ +import Foundation +import Status +import Account +import Explore +import SwiftUI + +enum Tab: Int, Identifiable { + case timeline, notifications, explore, account, settings, other + + var id: Int { + rawValue + } + + static func loggedOutTab() -> [Tab] { + [.timeline, .settings] + } + + static func loggedInTabs() -> [Tab] { + [.timeline, .notifications, .explore, .account, .settings] + } + + @ViewBuilder + func makeContentView(popToRootTab: Binding) -> some View { + switch self { + case .timeline: + TimelineTab(popToRootTab: popToRootTab) + case .notifications: + NotificationsTab(popToRootTab: popToRootTab) + case .explore: + ExploreTab(popToRootTab: popToRootTab) + case .account: + AccountTab(popToRootTab: popToRootTab) + case .settings: + SettingsTabs() + case .other: + EmptyView() + } + } + + @ViewBuilder + var label: some View { + switch self { + case .timeline: + Label("Timeline", systemImage: "rectangle.on.rectangle") + case .notifications: + Label("Notifications", systemImage: "bell") + case .explore: + Label("Explore", systemImage: "magnifyingglass") + case .account: + Label("Profile", systemImage: "person.circle") + case .settings: + Label("Settings", systemImage: "gear") + case .other: + EmptyView() + } + } +} + diff --git a/IceCubesApp/App/Tabs/TimelineTab.swift b/IceCubesApp/App/Tabs/TimelineTab.swift index 5d6821c0..103cd3a4 100644 --- a/IceCubesApp/App/Tabs/TimelineTab.swift +++ b/IceCubesApp/App/Tabs/TimelineTab.swift @@ -7,7 +7,7 @@ import Combine struct TimelineTab: View { @EnvironmentObject private var client: Client @StateObject private var routeurPath = RouterPath() - @Binding var popToRootTab: IceCubesApp.Tab + @Binding var popToRootTab: Tab @State private var timeline: TimelineFilter = .home var body: some View {