From 78940a005b471cbb5975bfc2de1e42f2019ea7a9 Mon Sep 17 00:00:00 2001 From: Arkadiusz Fal Date: Tue, 20 Dec 2022 23:51:04 +0100 Subject: [PATCH] Accounts loading improvements --- Model/Applications/InvidiousAPI.swift | 2 ++ Model/Applications/PipedAPI.swift | 4 +++- Model/Cache/SubscribedChannelsModel.swift | 5 +++++ Model/FeedModel.swift | 1 + Model/PlaylistsModel.swift | 6 ++++++ Shared/Navigation/ContentView.swift | 10 ---------- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/Model/Applications/InvidiousAPI.swift b/Model/Applications/InvidiousAPI.swift index bbdbe141..d5778832 100644 --- a/Model/Applications/InvidiousAPI.swift +++ b/Model/Applications/InvidiousAPI.swift @@ -143,6 +143,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI { updateToken() } else { FeedModel.shared.onAccountChange() + SubscribedChannelsModel.shared.onAccountChange() + PlaylistsModel.shared.onAccountChange() } } diff --git a/Model/Applications/PipedAPI.swift b/Model/Applications/PipedAPI.swift index 76993481..6b5a8b22 100644 --- a/Model/Applications/PipedAPI.swift +++ b/Model/Applications/PipedAPI.swift @@ -110,7 +110,9 @@ final class PipedAPI: Service, ObservableObject, VideosAPI { if account.token.isNil || account.token!.isEmpty { updateToken() } else { - FeedModel.shared.loadResources(force: true) + FeedModel.shared.onAccountChange() + SubscribedChannelsModel.shared.onAccountChange() + PlaylistsModel.shared.onAccountChange() } } diff --git a/Model/Cache/SubscribedChannelsModel.swift b/Model/Cache/SubscribedChannelsModel.swift index 61c20b29..024173a1 100644 --- a/Model/Cache/SubscribedChannelsModel.swift +++ b/Model/Cache/SubscribedChannelsModel.swift @@ -161,4 +161,9 @@ final class SubscribedChannelsModel: ObservableObject, CacheModel { var formattedCacheTime: String { getFormattedDate(channelsTime) } + + func onAccountChange() { + channels = [] + load(force: true) + } } diff --git a/Model/FeedModel.swift b/Model/FeedModel.swift index db768977..7f107a41 100644 --- a/Model/FeedModel.swift +++ b/Model/FeedModel.swift @@ -108,6 +108,7 @@ final class FeedModel: ObservableObject, CacheModel { func onAccountChange() { reset() + error = nil loadResources(force: true) calculateUnwatchedFeed() } diff --git a/Model/PlaylistsModel.swift b/Model/PlaylistsModel.swift index 96633a51..5f8659ad 100644 --- a/Model/PlaylistsModel.swift +++ b/Model/PlaylistsModel.swift @@ -123,4 +123,10 @@ final class PlaylistsModel: ObservableObject { private var resource: Resource? { accounts.api.playlists } + + func onAccountChange() { + error = nil + playlists = [] + load() + } } diff --git a/Shared/Navigation/ContentView.swift b/Shared/Navigation/ContentView.swift index bd94a6df..b7615dd4 100644 --- a/Shared/Navigation/ContentView.swift +++ b/Shared/Navigation/ContentView.swift @@ -38,16 +38,6 @@ struct ContentView: View { TVNavigationView() #endif } - .onChange(of: accounts.current) { _ in - subscriptions.load(force: true) - playlists.load(force: true) - } - .onChange(of: accounts.signedIn) { newValue in - guard newValue else { return } - subscriptions.load(force: true) - playlists.load(force: true) - } - #if os(iOS) .overlay(videoPlayer) .sheet(isPresented: $navigation.presentingShareSheet) {