Accounts loading improvements

This commit is contained in:
Arkadiusz Fal 2022-12-20 23:51:04 +01:00
parent a32f417776
commit 78940a005b
6 changed files with 17 additions and 11 deletions

View File

@ -143,6 +143,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
updateToken()
} else {
FeedModel.shared.onAccountChange()
SubscribedChannelsModel.shared.onAccountChange()
PlaylistsModel.shared.onAccountChange()
}
}

View File

@ -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()
}
}

View File

@ -161,4 +161,9 @@ final class SubscribedChannelsModel: ObservableObject, CacheModel {
var formattedCacheTime: String {
getFormattedDate(channelsTime)
}
func onAccountChange() {
channels = []
load(force: true)
}
}

View File

@ -108,6 +108,7 @@ final class FeedModel: ObservableObject, CacheModel {
func onAccountChange() {
reset()
error = nil
loadResources(force: true)
calculateUnwatchedFeed()
}

View File

@ -123,4 +123,10 @@ final class PlaylistsModel: ObservableObject {
private var resource: Resource? {
accounts.api.playlists
}
func onAccountChange() {
error = nil
playlists = []
load()
}
}

View File

@ -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) {