2022-11-29 11:46:02 +01:00
|
|
|
import SwiftUI
|
|
|
|
import Timeline
|
2022-12-22 10:53:36 +01:00
|
|
|
import Env
|
2022-11-29 12:18:06 +01:00
|
|
|
import Network
|
2022-12-24 11:50:05 +01:00
|
|
|
import Combine
|
2022-11-29 11:46:02 +01:00
|
|
|
|
2022-12-01 09:05:26 +01:00
|
|
|
struct TimelineTab: View {
|
2022-12-23 15:53:02 +01:00
|
|
|
@EnvironmentObject private var client: Client
|
2022-11-29 11:46:02 +01:00
|
|
|
@StateObject private var routeurPath = RouterPath()
|
2022-12-27 09:25:26 +01:00
|
|
|
@Binding var popToRootTab: Tab
|
2022-12-26 07:36:54 +01:00
|
|
|
@State private var timeline: TimelineFilter = .home
|
2022-11-29 11:46:02 +01:00
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
NavigationStack(path: $routeurPath.path) {
|
2022-12-26 07:36:54 +01:00
|
|
|
TimelineView(timeline: $timeline)
|
2022-11-29 11:46:02 +01:00
|
|
|
.withAppRouteur()
|
2022-12-20 09:37:07 +01:00
|
|
|
.withSheetDestinations(sheetDestinations: $routeurPath.presentedSheet)
|
2022-12-23 10:41:55 +01:00
|
|
|
.toolbar {
|
2022-12-23 15:53:02 +01:00
|
|
|
if client.isAuth {
|
|
|
|
ToolbarItem(placement: .navigationBarLeading) {
|
|
|
|
Button {
|
2022-12-26 08:24:55 +01:00
|
|
|
routeurPath.presentedSheet = .newStatusEditor
|
2022-12-23 15:53:02 +01:00
|
|
|
} label: {
|
|
|
|
Image(systemName: "square.and.pencil")
|
|
|
|
}
|
2022-12-23 10:41:55 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
ToolbarItem(placement: .navigationBarTrailing) {
|
|
|
|
timelineFilterButton
|
|
|
|
}
|
2022-12-23 10:41:55 +01:00
|
|
|
}
|
|
|
|
}
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
.onAppear {
|
2022-12-27 08:31:47 +01:00
|
|
|
routeurPath.client = client
|
2022-12-26 07:36:54 +01:00
|
|
|
if !client.isAuth {
|
|
|
|
timeline = .pub
|
|
|
|
}
|
|
|
|
}
|
2022-11-29 11:46:02 +01:00
|
|
|
.environmentObject(routeurPath)
|
2022-12-24 11:50:05 +01:00
|
|
|
.onChange(of: $popToRootTab.wrappedValue) { popToRootTab in
|
|
|
|
if popToRootTab == .timeline {
|
|
|
|
routeurPath.path = []
|
|
|
|
}
|
|
|
|
}
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|
2022-12-26 07:36:54 +01:00
|
|
|
|
|
|
|
|
|
|
|
private var timelineFilterButton: some View {
|
|
|
|
Menu {
|
|
|
|
ForEach(TimelineFilter.availableTimeline(), id: \.self) { timeline in
|
|
|
|
Button {
|
|
|
|
self.timeline = timeline
|
|
|
|
} label: {
|
|
|
|
Text(timeline.title())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} label: {
|
|
|
|
Image(systemName: "line.3.horizontal.decrease.circle")
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2022-11-29 11:46:02 +01:00
|
|
|
}
|