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
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
Button {
self.timeline = timeline

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -295,6 +295,7 @@
// MARK: Package: Timeline
"timeline.federated" = "Birleştirilmiş";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "Ana Ekran";
"timeline.local" = "Yerel";
"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
"timeline.federated" = "跨站";
"timeline.latest" = "Jump to Latest";
"timeline.home" = "主页";
"timeline.local" = "本地";
"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 list(list: Models.List)
case remoteLocal(server: String)
case latest
public func hash(into hasher: inout Hasher) {
hasher.combine(title)
@ -22,6 +23,8 @@ public enum TimelineFilter: Hashable, Equatable {
public var title: String {
switch self {
case .latest:
return "Latest"
case .federated:
return "Federated"
case .local:
@ -41,6 +44,8 @@ public enum TimelineFilter: Hashable, Equatable {
public func localizedTitle() -> LocalizedStringKey {
switch self {
case .latest:
return "timeline.latest"
case .federated:
return "timeline.federated"
case .local:
@ -60,6 +65,8 @@ public enum TimelineFilter: Hashable, Equatable {
public func iconName() -> String? {
switch self {
case .latest:
return "arrow.counterclockwise"
case .federated:
return "globe.americas"
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 .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 .latest: return Timelines.home(sinceId: nil, maxId: nil, minId: nil)
case .home: return Timelines.home(sinceId: sinceId, maxId: maxId, minId: minId)
case .trending: return Trends.statuses(offset: offset)
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
}
.onChange(of: viewModel.timeline, perform: { newValue in
timeline = newValue
})
.onChange(of: scenePhase, perform: { scenePhase in
switch scenePhase {
case .active:

View File

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