Add Jump to Latest to clear out cache and reload home timeline

This commit is contained in:
Thomas Ricouard 2023-02-04 21:21:36 +01:00
parent f4a2d4fcc3
commit 5afd2dc73c
19 changed files with 38 additions and 0 deletions

View file

@ -76,6 +76,14 @@ struct TimelineTab: View {
@ViewBuilder @ViewBuilder
private var timelineFilterButton: some View { private var timelineFilterButton: some View {
if timeline == .home {
Button {
self.timeline = .latest
} label: {
Label(TimelineFilter.latest.localizedTitle(), systemImage: TimelineFilter.latest.iconName() ?? "")
}
Divider()
}
ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in ForEach(TimelineFilter.availableTimeline(client: client), id: \.self) { timeline in
Button { Button {
self.timeline = timeline self.timeline = timeline

View file

@ -298,6 +298,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federada"; "timeline.federated" = "Federada";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Inici"; "timeline.home" = "Inici";
"timeline.local" = "Local"; "timeline.local" = "Local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld publicació recents de %lld participants"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld publicació recents de %lld participants";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Föderiert"; "timeline.federated" = "Föderiert";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Startseite"; "timeline.home" = "Startseite";
"timeline.local" = "Lokal"; "timeline.local" = "Lokal";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld aktuelle Beiträge von %lld Teilnehmenden"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld aktuelle Beiträge von %lld Teilnehmenden";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federated"; "timeline.federated" = "Federated";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Home"; "timeline.home" = "Home";
"timeline.local" = "Local"; "timeline.local" = "Local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld recent posts from %lld participants"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld recent posts from %lld participants";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federated"; "timeline.federated" = "Federated";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Home"; "timeline.home" = "Home";
"timeline.local" = "Local"; "timeline.local" = "Local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld recent posts from %lld participants"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld recent posts from %lld participants";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federado"; "timeline.federated" = "Federado";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Inicio"; "timeline.home" = "Inicio";
"timeline.local" = "Local"; "timeline.local" = "Local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld publicaciones recientes de %lld participantes"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld publicaciones recientes de %lld participantes";

View file

@ -295,6 +295,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Fédéré"; "timeline.federated" = "Fédéré";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Accueil"; "timeline.home" = "Accueil";
"timeline.local" = "Local"; "timeline.local" = "Local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld publications récentes de %lld participants"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld publications récentes de %lld participants";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federazione"; "timeline.federated" = "Federazione";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Home"; "timeline.home" = "Home";
"timeline.local" = "Locale"; "timeline.local" = "Locale";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld post recenti da %lld partecipanti"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld post recenti da %lld partecipanti";

View file

@ -299,6 +299,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "連合"; "timeline.federated" = "連合";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "ホーム"; "timeline.home" = "ホーム";
"timeline.local" = "ローカル"; "timeline.local" = "ローカル";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld トゥートの投稿 %lld 人が投稿している"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld トゥートの投稿 %lld 人が投稿している";

View file

@ -301,6 +301,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "연합"; "timeline.federated" = "연합";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "홈"; "timeline.home" = "홈";
"timeline.local" = "로컬"; "timeline.local" = "로컬";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld개의 최근 글 (%lld명의 사용자가 이야기 중)"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld개의 최근 글 (%lld명의 사용자가 이야기 중)";

View file

@ -299,6 +299,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Federert"; "timeline.federated" = "Federert";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Hjem"; "timeline.home" = "Hjem";
"timeline.local" = "Lokal"; "timeline.local" = "Lokal";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld nylige innlegg fra %lld deltakere"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld nylige innlegg fra %lld deltakere";

View file

@ -293,6 +293,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Gefedereerd"; "timeline.federated" = "Gefedereerd";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Start"; "timeline.home" = "Start";
"timeline.local" = "Lokaal"; "timeline.local" = "Lokaal";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld recente posts van %lld deelnemers"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld recente posts van %lld deelnemers";

View file

@ -296,6 +296,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Strumień globalny"; "timeline.federated" = "Strumień globalny";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Strona domowa"; "timeline.home" = "Strona domowa";
"timeline.local" = "Strumień lokalny"; "timeline.local" = "Strumień lokalny";
"timeline.trending" = "Teraz popularne"; "timeline.trending" = "Teraz popularne";

View file

@ -299,6 +299,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Linha global"; "timeline.federated" = "Linha global";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Início"; "timeline.home" = "Início";
"timeline.local" = "Linha local"; "timeline.local" = "Linha local";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld postagens recentes de %lld participantes"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld postagens recentes de %lld participantes";

View file

@ -295,6 +295,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "Birleştirilmiş"; "timeline.federated" = "Birleştirilmiş";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Ana Ekran"; "timeline.home" = "Ana Ekran";
"timeline.local" = "Yerel"; "timeline.local" = "Yerel";
"timeline.n-recent-from-n-participants %lld %lld" = "%lld katılımcılar tarafından %lld yeni gönderiler"; "timeline.n-recent-from-n-participants %lld %lld" = "%lld katılımcılar tarafından %lld yeni gönderiler";

View file

@ -300,6 +300,7 @@
// MARK: Package: Timeline // MARK: Package: Timeline
"timeline.federated" = "跨站"; "timeline.federated" = "跨站";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "主页"; "timeline.home" = "主页";
"timeline.local" = "本地"; "timeline.local" = "本地";
"timeline.n-recent-from-n-participants %lld %lld" = "最近 %lld 条嘟文来自 %lld 个参与者"; "timeline.n-recent-from-n-participants %lld %lld" = "最近 %lld 条嘟文来自 %lld 个参与者";

View file

@ -8,6 +8,7 @@ public enum TimelineFilter: Hashable, Equatable {
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)
case latest
public func hash(into hasher: inout Hasher) { public func hash(into hasher: inout Hasher) {
hasher.combine(title) hasher.combine(title)
@ -22,6 +23,8 @@ public enum TimelineFilter: Hashable, Equatable {
public var title: String { public var title: String {
switch self { switch self {
case .latest:
return "Latest"
case .federated: case .federated:
return "Federated" return "Federated"
case .local: case .local:
@ -41,6 +44,8 @@ public enum TimelineFilter: Hashable, Equatable {
public func localizedTitle() -> LocalizedStringKey { public func localizedTitle() -> LocalizedStringKey {
switch self { switch self {
case .latest:
return "timeline.latest"
case .federated: case .federated:
return "timeline.federated" return "timeline.federated"
case .local: case .local:
@ -60,6 +65,8 @@ public enum TimelineFilter: Hashable, Equatable {
public func iconName() -> String? { public func iconName() -> String? {
switch self { switch self {
case .latest:
return "arrow.counterclockwise"
case .federated: case .federated:
return "globe.americas" return "globe.americas"
case .local: case .local:
@ -82,6 +89,7 @@ public enum TimelineFilter: Hashable, Equatable {
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 .remoteLocal: return Timelines.pub(sinceId: sinceId, maxId: maxId, minId: minId, local: true)
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)
case let .list(list): return Timelines.list(listId: list.id, sinceId: sinceId, maxId: maxId, minId: minId) case let .list(list): return Timelines.list(listId: list.id, sinceId: sinceId, maxId: maxId, minId: minId)

View file

@ -115,6 +115,9 @@ public struct TimelineView: View {
} }
viewModel.timeline = newTimeline viewModel.timeline = newTimeline
} }
.onChange(of: viewModel.timeline, perform: { newValue in
timeline = newValue
})
.onChange(of: scenePhase, perform: { scenePhase in .onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase { switch scenePhase {
case .active: case .active:

View file

@ -11,6 +11,10 @@ class TimelineViewModel: ObservableObject {
@Published var timeline: TimelineFilter = .federated { @Published var timeline: TimelineFilter = .federated {
didSet { didSet {
Task { Task {
if timeline == .latest, let client {
await cache.clearCache(for: client)
timeline = .home
}
if oldValue != timeline { if oldValue != timeline {
statuses = [] statuses = []
pendingStatusesObserver.pendingStatuses = [] pendingStatusesObserver.pendingStatuses = []