mirror of
https://github.com/Dimillian/IceCubesApp.git
synced 2025-01-10 21:54:10 +01:00
Browse and connect to multiple timelines
This commit is contained in:
parent
864a0b3969
commit
a694c5d80c
@ -4,12 +4,40 @@ import Network
|
|||||||
|
|
||||||
@main
|
@main
|
||||||
struct IceCubesAppApp: App {
|
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 {
|
var body: some Scene {
|
||||||
WindowGroup {
|
WindowGroup {
|
||||||
TimelineView(kind: .pub)
|
TabView {
|
||||||
.environmentObject(client)
|
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
|
List(statuses) { status in
|
||||||
StatusRowView(status: status)
|
StatusRowView(status: status)
|
||||||
}
|
}
|
||||||
|
.listStyle(.plain)
|
||||||
|
.navigationTitle("Public Timeline: \(client.server)")
|
||||||
|
.navigationBarTitleDisplayMode(.inline)
|
||||||
.task {
|
.task {
|
||||||
do {
|
await refreshTimeline()
|
||||||
self.statuses = try await client.fetchArray(endpoint: Timeline.pub)
|
}
|
||||||
} catch {
|
.refreshable {
|
||||||
print(error.localizedDescription)
|
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