2023-12-29 11:17:37 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct ContentView: View {
|
2024-01-04 22:19:35 +01:00
|
|
|
@UIApplicationDelegateAdaptor private var appDelegate: AppDelegate
|
|
|
|
|
2023-12-29 11:17:37 +01:00
|
|
|
@State private var navigator = Navigator()
|
|
|
|
@State private var sheet: SheetDestination?
|
2024-01-02 14:23:36 +01:00
|
|
|
@State private var accountManager: AccountManager = AccountManager()
|
2023-12-29 11:17:37 +01:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
TabView(selection: $navigator.selectedTab, content: {
|
|
|
|
ZStack {
|
2024-01-02 14:23:36 +01:00
|
|
|
if accountManager.getClient() != nil {
|
|
|
|
TimelineView(navigator: navigator, timelineModel: FetchTimeline(client: accountManager.forceClient()))
|
2023-12-29 11:17:37 +01:00
|
|
|
.background(Color.appBackground)
|
|
|
|
.safeAreaPadding()
|
|
|
|
} else {
|
|
|
|
ZStack {
|
|
|
|
Color.appBackground
|
|
|
|
.ignoresSafeArea()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.background(Color.appBackground)
|
|
|
|
.tag(TabDestination.timeline)
|
|
|
|
|
|
|
|
Text(String("Search"))
|
|
|
|
.background(Color.appBackground)
|
|
|
|
.tag(TabDestination.search)
|
|
|
|
|
|
|
|
Text(String("Activity"))
|
|
|
|
.background(Color.appBackground)
|
|
|
|
.tag(TabDestination.activity)
|
|
|
|
|
2024-01-13 13:15:46 +01:00
|
|
|
ZStack {
|
|
|
|
if accountManager.getAccount() != nil {
|
|
|
|
AccountView(isCurrent: true, account: accountManager.forceAccount())
|
|
|
|
.background(Color.appBackground)
|
|
|
|
} else {
|
|
|
|
ZStack {
|
|
|
|
Color.appBackground
|
|
|
|
.ignoresSafeArea()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.background(Color.appBackground)
|
|
|
|
.tag(TabDestination.profile)
|
2024-01-02 14:23:36 +01:00
|
|
|
|
2023-12-29 11:17:37 +01:00
|
|
|
})
|
|
|
|
.overlay(alignment: .bottom) {
|
|
|
|
TabsView(navigator: navigator)
|
|
|
|
.safeAreaPadding(.vertical)
|
|
|
|
.zIndex(10)
|
|
|
|
}
|
|
|
|
.withCovers(sheetDestination: $sheet)
|
2024-01-02 14:23:36 +01:00
|
|
|
.withSheets(sheetDestination: $navigator.presentedSheet)
|
|
|
|
.environment(accountManager)
|
2023-12-29 11:17:37 +01:00
|
|
|
.environment(navigator)
|
2024-01-04 22:19:35 +01:00
|
|
|
.environment(appDelegate)
|
2024-01-10 17:40:05 +01:00
|
|
|
.onAppear {
|
|
|
|
if accountManager.getClient() == nil {
|
|
|
|
Task {
|
|
|
|
await recognizeAccount()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2024-01-02 14:23:36 +01:00
|
|
|
.task {
|
|
|
|
await recognizeAccount()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func recognizeAccount() async {
|
|
|
|
let acc = try? AppAccount.loadAsCurrent()
|
|
|
|
if acc == nil {
|
|
|
|
sheet = .welcome
|
|
|
|
} else {
|
|
|
|
Task {
|
|
|
|
accountManager.setClient(.init(server: acc!.server, oauthToken: acc!.oauthToken))
|
2024-01-10 17:40:05 +01:00
|
|
|
|
|
|
|
// check if token is still working
|
|
|
|
let fetched: Account? = await accountManager.fetchAccount()
|
|
|
|
if fetched == nil {
|
|
|
|
accountManager.clear()
|
|
|
|
AppAccount.clear()
|
|
|
|
sheet = .welcome
|
|
|
|
}
|
2023-12-29 11:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
init() {
|
|
|
|
let appearance = UITabBarAppearance()
|
|
|
|
appearance.configureWithTransparentBackground()
|
|
|
|
appearance.stackedLayoutAppearance.normal.iconColor = .white
|
|
|
|
appearance.stackedLayoutAppearance.normal.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white]
|
|
|
|
|
|
|
|
appearance.stackedLayoutAppearance.selected.iconColor = UIColor(Color.accentColor)
|
|
|
|
appearance.stackedLayoutAppearance.selected.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor(Color.accentColor)]
|
|
|
|
|
|
|
|
UITabBar.appearance().standardAppearance = appearance
|
2024-01-02 14:23:36 +01:00
|
|
|
UINavigationBar.appearance().tintColor = UIColor.label
|
2023-12-29 11:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#Preview {
|
|
|
|
ContentView()
|
|
|
|
}
|