IceCubesApp/IceCubesApp/App/IceCubesApp.swift

78 lines
2.4 KiB
Swift
Raw Normal View History

2022-12-01 08:05:26 +00:00
import SwiftUI
import Timeline
import Network
import KeychainSwift
2022-12-22 09:53:36 +00:00
import Env
2022-12-01 08:05:26 +00:00
@main
struct IceCubesApp: App {
2022-12-24 10:50:05 +00:00
enum Tab: Int {
case timeline, notifications, explore, account, settings, other
}
2022-12-17 12:37:46 +00:00
public static let defaultServer = "mastodon.social"
2022-12-01 08:05:26 +00:00
@StateObject private var appAccountsManager = AppAccountsManager()
2022-12-22 10:19:56 +00:00
@StateObject private var currentAccount = CurrentAccount()
2022-12-22 09:53:36 +00:00
@StateObject private var quickLook = QuickLook()
2022-12-24 10:50:05 +00:00
@State private var selectedTab: Tab = .timeline
@State private var popToRootTab: Tab = .other
2022-12-01 08:05:26 +00:00
var body: some Scene {
WindowGroup {
2022-12-24 10:50:05 +00:00
TabView(selection: .init(get: {
selectedTab
}, set: { newTab in
if newTab == selectedTab {
/// Stupid hack to trigger onChange binding in tab views.
popToRootTab = .other
DispatchQueue.main.asyncAfter(deadline: .now() + 0.01) {
popToRootTab = selectedTab
}
}
selectedTab = newTab
})) {
TimelineTab(popToRootTab: $popToRootTab)
2022-12-01 08:05:26 +00:00
.tabItem {
Label("Timeline", systemImage: "rectangle.on.rectangle")
2022-12-01 08:05:26 +00:00
}
2022-12-24 10:50:05 +00:00
.tag(Tab.timeline)
2022-12-20 14:37:51 +00:00
if appAccountsManager.currentClient.isAuth {
2022-12-24 10:50:05 +00:00
NotificationsTab(popToRootTab: $popToRootTab)
2022-12-20 14:37:51 +00:00
.tabItem {
Label("Notifications", systemImage: "bell")
}
2022-12-24 10:50:05 +00:00
.tag(Tab.notifications)
ExploreTab(popToRootTab: $popToRootTab)
.tabItem {
Label("Explore", systemImage: "magnifyingglass")
}
2022-12-24 10:50:05 +00:00
.tag(Tab.explore)
AccountTab(popToRootTab: $popToRootTab)
2022-12-20 15:08:09 +00:00
.tabItem {
Label("Profile", systemImage: "person.circle")
}
2022-12-24 10:50:05 +00:00
.tag(Tab.account)
2022-12-20 14:37:51 +00:00
}
2022-12-01 08:05:26 +00:00
SettingsTabs()
.tabItem {
Label("Settings", systemImage: "gear")
}
2022-12-24 10:50:05 +00:00
.tag(Tab.settings)
2022-12-01 08:05:26 +00:00
}
2022-12-20 15:08:09 +00:00
.tint(.brand)
2022-12-22 10:19:56 +00:00
.onChange(of: appAccountsManager.currentClient) { newClient in
currentAccount.setClient(client: newClient)
}
.onAppear {
currentAccount.setClient(client: appAccountsManager.currentClient)
}
2022-12-01 08:05:26 +00:00
.environmentObject(appAccountsManager)
.environmentObject(appAccountsManager.currentClient)
2022-12-22 09:53:36 +00:00
.environmentObject(quickLook)
2022-12-22 10:19:56 +00:00
.environmentObject(currentAccount)
.quickLookPreview($quickLook.url, in: quickLook.urls)
2022-12-01 08:05:26 +00:00
}
}
}