80 lines
1.6 KiB
Swift
80 lines
1.6 KiB
Swift
//
|
|
// ContentView.swift
|
|
// BeReal
|
|
//
|
|
// Created by Javier Cicchelli on 29/11/2022.
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
//
|
|
|
|
import Browse
|
|
import DataModels
|
|
import Login
|
|
import KeychainStorage
|
|
import Profile
|
|
import SwiftUI
|
|
|
|
struct ContentView: View {
|
|
|
|
// MARK: Storages
|
|
|
|
@KeychainStorage(key: .KeychainStorage.account) private var account: Account?
|
|
|
|
// MARK: States
|
|
|
|
@State private var user: User?
|
|
@State private var showSheet: SheetView?
|
|
|
|
// MARK: Body
|
|
|
|
var body: some View {
|
|
NavigationView {
|
|
BrowseView {
|
|
// ...
|
|
} uploadFile: {
|
|
// ...
|
|
} showProfile: {
|
|
showSheet = .profile
|
|
}
|
|
}
|
|
.onAppear {
|
|
shouldShowLogin()
|
|
}
|
|
.onChange(of: account) { _ in
|
|
shouldShowLogin()
|
|
}
|
|
.sheet(item: $showSheet) { sheet in
|
|
switch sheet {
|
|
case .login:
|
|
LoginView {
|
|
user = $1
|
|
account = $0
|
|
}
|
|
case .profile:
|
|
ProfileView(user: user) {
|
|
user = nil
|
|
account = nil
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
// MARK: - Helpers
|
|
|
|
private extension ContentView {
|
|
func shouldShowLogin() {
|
|
showSheet = account == nil
|
|
? .login
|
|
: nil
|
|
}
|
|
}
|
|
|
|
// MARK: - Previews
|
|
|
|
struct ContentView_Previews: PreviewProvider {
|
|
static var previews: some View {
|
|
ContentView()
|
|
}
|
|
}
|