mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2024-12-23 05:19:42 +01:00
Browse and connect to multiple timelines
This commit is contained in:
parent
864a0b3969
commit
a694c5d80c
@ -4,12 +4,40 @@ import Network
|
||||
|
||||
@main
|
||||
struct IceCubesAppApp: App {
|
||||
@StateObject private var client = Client(server: "mastodon.social")
|
||||
@State private var tabs: [String] = ["mastodon.social"]
|
||||
@State private var isServerSelectDisplayed: Bool = false
|
||||
@State private var newServerURL: String = ""
|
||||
|
||||
var body: some Scene {
|
||||
WindowGroup {
|
||||
TimelineView(kind: .pub)
|
||||
.environmentObject(client)
|
||||
TabView {
|
||||
ForEach(tabs, id: \.self) { tab in
|
||||
NavigationStack {
|
||||
TimelineView(kind: .pub)
|
||||
.environmentObject(Client(server: tab))
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .navigationBarTrailing) {
|
||||
Button {
|
||||
isServerSelectDisplayed.toggle()
|
||||
} label: {
|
||||
Image(systemName: "globe")
|
||||
}
|
||||
}
|
||||
}
|
||||
.alert("Connect to another server", isPresented: $isServerSelectDisplayed) {
|
||||
TextField(tab, text: $newServerURL)
|
||||
Button("Connect", action: {
|
||||
tabs.append(newServerURL)
|
||||
newServerURL = ""
|
||||
})
|
||||
Button("Cancel", role: .cancel, action: {})
|
||||
}
|
||||
}
|
||||
.tabItem {
|
||||
Label(tab, systemImage: "globe")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -20,12 +20,22 @@ public struct TimelineView: View {
|
||||
List(statuses) { status in
|
||||
StatusRowView(status: status)
|
||||
}
|
||||
.listStyle(.plain)
|
||||
.navigationTitle("Public Timeline: \(client.server)")
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.task {
|
||||
do {
|
||||
self.statuses = try await client.fetchArray(endpoint: Timeline.pub)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
await refreshTimeline()
|
||||
}
|
||||
.refreshable {
|
||||
await refreshTimeline()
|
||||
}
|
||||
}
|
||||
|
||||
private func refreshTimeline() async {
|
||||
do {
|
||||
self.statuses = try await client.fetchArray(endpoint: Timeline.pub)
|
||||
} catch {
|
||||
print(error.localizedDescription)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user