Filter remote local timeline

This commit is contained in:
Thomas Ricouard 2023-02-06 12:24:48 +01:00
parent f32fef6676
commit 5f76a8057c
3 changed files with 71 additions and 13 deletions

View file

@ -82,6 +82,7 @@ struct TimelineTab: View {
} label: { } label: {
Label(TimelineFilter.latest.localizedTitle(), systemImage: TimelineFilter.latest.iconName() ?? "") Label(TimelineFilter.latest.localizedTitle(), systemImage: TimelineFilter.latest.iconName() ?? "")
} }
.keyboardShortcut("r", modifiers: .command)
Divider() Divider()
} }
ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in
@ -120,9 +121,11 @@ struct TimelineTab: View {
Menu("timeline.filter.local") { Menu("timeline.filter.local") {
ForEach(preferences.remoteLocalTimelines, id: \.self) { server in ForEach(preferences.remoteLocalTimelines, id: \.self) { server in
Button { Button {
timeline = .remoteLocal(server: server) timeline = .remoteLocal(server: server, filter: .local)
} label: { } label: {
Label(server, systemImage: "dot.radiowaves.right") VStack {
Label(server, systemImage: "dot.radiowaves.right")
}
} }
} }
Button { Button {
@ -171,13 +174,18 @@ struct TimelineTab: View {
Image(systemName: "list.bullet") Image(systemName: "list.bullet")
} }
} }
case let .remoteLocal(server): case let .remoteLocal(server, _):
ToolbarItem { ToolbarItem {
Button { Menu {
preferences.remoteLocalTimelines.removeAll(where: { $0 == server }) ForEach(RemoteTimelineFilter.allCases, id: \.self) { filter in
timeline = client.isAuth ? .home : .federated Button {
timeline = .remoteLocal(server: server, filter: filter)
} label: {
Label(filter.localizedTitle(), systemImage: filter.iconName())
}
}
} label: { } label: {
Image(systemName: "pin.slash") Image(systemName: "line.3.horizontal.decrease.circle")
} }
} }
default: default:

View file

@ -3,11 +3,37 @@ import Models
import Network import Network
import SwiftUI import SwiftUI
public enum RemoteTimelineFilter: String, CaseIterable, Hashable, Equatable {
case local, federated, trending
public func localizedTitle() -> LocalizedStringKey {
switch self {
case .federated:
return "timeline.federated"
case .local:
return "timeline.local"
case .trending:
return "timeline.trending"
}
}
public func iconName() -> String {
switch self {
case .federated:
return "globe.americas"
case .local:
return "person.2"
case .trending:
return "chart.line.uptrend.xyaxis"
}
}
}
public enum TimelineFilter: Hashable, Equatable { public enum TimelineFilter: Hashable, Equatable {
case home, local, federated, trending case home, local, federated, trending
case hashtag(tag: String, accountId: String?) case hashtag(tag: String, accountId: String?)
case list(list: Models.List) case list(list: Models.List)
case remoteLocal(server: String) case remoteLocal(server: String, filter: RemoteTimelineFilter)
case latest case latest
public func hash(into hasher: inout Hasher) { public func hash(into hasher: inout Hasher) {
@ -37,7 +63,7 @@ public enum TimelineFilter: Hashable, Equatable {
return "#\(tag)" return "#\(tag)"
case let .list(list): case let .list(list):
return list.title return list.title
case let .remoteLocal(server): case let .remoteLocal(server, _):
return server return server
} }
} }
@ -58,7 +84,7 @@ public enum TimelineFilter: Hashable, Equatable {
return "#\(tag)" return "#\(tag)"
case let .list(list): case let .list(list):
return LocalizedStringKey(list.title) return LocalizedStringKey(list.title)
case let .remoteLocal(server): case let .remoteLocal(server, _):
return LocalizedStringKey(server) return LocalizedStringKey(server)
} }
} }
@ -88,7 +114,15 @@ public enum TimelineFilter: Hashable, Equatable {
switch self { switch self {
case .federated: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false) case .federated: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false)
case .local: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true) case .local: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true)
case .remoteLocal: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true) case let .remoteLocal(_, filter):
switch filter {
case .local:
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true)
case .federated:
return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: false)
case .trending:
return Trends.statuses(offset: offset)
}
case .latest: return Timelines.home(sinceId: nil, maxId: nil, minId: nil) case .latest: return Timelines.home(sinceId: nil, maxId: nil, minId: nil)
case .home: return Timelines.home(sinceId: sinceId, maxId: maxId, minId: minId) case .home: return Timelines.home(sinceId: sinceId, maxId: maxId, minId: minId)
case .trending: return Trends.statuses(offset: offset) case .trending: return Trends.statuses(offset: offset)

View file

@ -79,7 +79,23 @@ public struct TimelineView: View {
} }
}) })
} }
.navigationTitle(timeline.localizedTitle()) .toolbar {
ToolbarItem(placement: .principal) {
VStack(alignment: .center) {
switch timeline {
case let .remoteLocal(_, filter):
Text(filter.localizedTitle())
.font(.headline)
Text(timeline.localizedTitle())
.font(.caption)
.foregroundColor(.gray)
default:
Text(timeline.localizedTitle())
.font(.headline)
}
}
}
}
.navigationBarTitleDisplayMode(.inline) .navigationBarTitleDisplayMode(.inline)
.onAppear { .onAppear {
viewModel.isTimelineVisible = true viewModel.isTimelineVisible = true
@ -111,7 +127,7 @@ public struct TimelineView: View {
} }
.onChange(of: timeline) { newTimeline in .onChange(of: timeline) { newTimeline in
switch newTimeline { switch newTimeline {
case let .remoteLocal(server): case let .remoteLocal(server, _):
viewModel.client = Client(server: server) viewModel.client = Client(server: server)
default: default:
viewModel.client = client viewModel.client = client