2023-12-29 11:17:37 +01:00
|
|
|
//Made by Lumaa
|
|
|
|
|
|
|
|
import Foundation
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
@Observable
|
2024-01-02 14:23:36 +01:00
|
|
|
public class Navigator: ObservableObject {
|
2023-12-29 11:17:37 +01:00
|
|
|
public var path: [RouterDestination] = []
|
|
|
|
public var presentedSheet: SheetDestination?
|
|
|
|
public var selectedTab: TabDestination = .timeline
|
|
|
|
|
|
|
|
public func navigate(to: RouterDestination) {
|
|
|
|
path.append(to)
|
2024-01-02 14:23:36 +01:00
|
|
|
print("appended view")
|
2023-12-29 11:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum TabDestination: Identifiable {
|
|
|
|
case timeline
|
|
|
|
case search
|
|
|
|
case activity
|
|
|
|
case profile
|
|
|
|
|
|
|
|
public var id: String {
|
|
|
|
switch self {
|
|
|
|
case .timeline:
|
|
|
|
return "timeline"
|
|
|
|
case .search:
|
|
|
|
return "search"
|
|
|
|
case .activity:
|
|
|
|
return "activity"
|
|
|
|
case .profile:
|
|
|
|
return "profile"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum SheetDestination: Identifiable {
|
|
|
|
case welcome
|
|
|
|
case mastodonLogin(logged: Binding<Bool>)
|
2024-01-02 14:23:36 +01:00
|
|
|
case post(content: String = "")
|
2023-12-29 11:17:37 +01:00
|
|
|
|
|
|
|
public var id: String {
|
|
|
|
switch self {
|
|
|
|
case .welcome:
|
|
|
|
return "welcome"
|
|
|
|
case .mastodonLogin:
|
|
|
|
return "login"
|
|
|
|
case .post:
|
|
|
|
return "post"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public var isCover: Bool {
|
|
|
|
switch self {
|
|
|
|
case .welcome:
|
|
|
|
return true
|
|
|
|
|
|
|
|
case .mastodonLogin:
|
|
|
|
return false
|
|
|
|
|
|
|
|
case .post:
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum RouterDestination: Hashable {
|
|
|
|
case settings
|
|
|
|
case privacy
|
|
|
|
case account(acc: Account)
|
2023-12-30 20:59:09 +01:00
|
|
|
case about
|
2023-12-29 11:17:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
extension View {
|
2024-01-02 14:23:36 +01:00
|
|
|
func withAppRouter(_ navigator: Navigator) -> some View {
|
2023-12-29 11:17:37 +01:00
|
|
|
navigationDestination(for: RouterDestination.self) { destination in
|
|
|
|
switch destination {
|
|
|
|
case .settings:
|
2024-01-02 14:23:36 +01:00
|
|
|
SettingsView(navigator: navigator)
|
2023-12-29 11:17:37 +01:00
|
|
|
case .privacy:
|
|
|
|
PrivacyView()
|
|
|
|
case .account(let acc):
|
2024-01-02 14:23:36 +01:00
|
|
|
AccountView(account: acc, navigator: navigator)
|
2023-12-30 20:59:09 +01:00
|
|
|
case .about:
|
|
|
|
AboutView()
|
2023-12-29 11:17:37 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withSheets(sheetDestination: Binding<SheetDestination?>) -> some View {
|
|
|
|
sheet(item: sheetDestination) { destination in
|
|
|
|
viewRepresentation(destination: destination, isCover: false)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func withCovers(sheetDestination: Binding<SheetDestination?>) -> some View {
|
|
|
|
fullScreenCover(item: sheetDestination) { destination in
|
|
|
|
viewRepresentation(destination: destination, isCover: true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private func viewRepresentation(destination: SheetDestination, isCover: Bool) -> some View {
|
|
|
|
Group {
|
|
|
|
if destination.isCover {
|
|
|
|
switch destination {
|
|
|
|
case .welcome:
|
|
|
|
ConnectView()
|
|
|
|
default:
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
switch destination {
|
2024-01-02 14:23:36 +01:00
|
|
|
case .post(let content):
|
|
|
|
NavigationStack {
|
|
|
|
PostingView(initialString: content)
|
|
|
|
.tint(Color(uiColor: UIColor.label))
|
|
|
|
}
|
2023-12-29 11:17:37 +01:00
|
|
|
case let .mastodonLogin(logged):
|
|
|
|
AddInstanceView(logged: logged)
|
|
|
|
.tint(Color.accentColor)
|
|
|
|
default:
|
|
|
|
EmptyView()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|