From 595d701728aafcfa4a373147f511e54a2a6000cc Mon Sep 17 00:00:00 2001 From: Anass Bouassaba Date: Fri, 29 Nov 2024 05:08:50 +0100 Subject: [PATCH] fix: clear error in store fetchers and timers (#43) --- Sources/Screens/Account/AccountOverview.swift | 12 +++++++++++- Sources/Screens/Account/AccountStore.swift | 4 ++++ Sources/Screens/Browser/BrowserStore.swift | 4 ++++ Sources/Screens/File/FileStore.swift | 8 ++++++++ Sources/Screens/Group/GroupStore.swift | 12 ++---------- Sources/Screens/Insights/InsightsStore.swift | 4 ++++ Sources/Screens/Invitation/InvitationStore.swift | 4 ++++ Sources/Screens/Mosaic/MosaicStore.swift | 2 ++ .../Screens/Organization/OrganizationStore.swift | 12 ++---------- Sources/Screens/Sharing/SharingStore.swift | 4 ++++ Sources/Screens/SignUp/SignUpStore.swift | 2 ++ Sources/Screens/Snapshot/SnapshotStore.swift | 2 ++ Sources/Screens/Task/TaskStore.swift | 2 ++ Sources/Screens/User/UserStore.swift | 2 ++ Sources/Screens/Workspace/WorkspaceStore.swift | 14 ++++++-------- 15 files changed, 59 insertions(+), 29 deletions(-) diff --git a/Sources/Screens/Account/AccountOverview.swift b/Sources/Screens/Account/AccountOverview.swift index 8c03015..6bacd83 100644 --- a/Sources/Screens/Account/AccountOverview.swift +++ b/Sources/Screens/Account/AccountOverview.swift @@ -24,7 +24,17 @@ struct AccountOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycl if isLoading { ProgressView() } else if let error { - VOErrorMessage(error) + VStack { + VOErrorMessage(error) + Button { + performSignOut() + } label: { + VOButtonLabel("Sign Out") + } + .voButton(color: .red500) + .fixedSize() + .padding(.horizontal) + } } else { if let identityUser = accountStore.identityUser { VOAvatar( diff --git a/Sources/Screens/Account/AccountStore.swift b/Sources/Screens/Account/AccountStore.swift index 869a018..40821b2 100644 --- a/Sources/Screens/Account/AccountStore.swift +++ b/Sources/Screens/Account/AccountStore.swift @@ -67,6 +67,7 @@ class AccountStore: ObservableObject { self.identityUserIsLoading = true } success: { self.identityUser = identityUser + self.identityUserError = nil } failure: { message in self.identityUserError = message } invalidCredentials: { @@ -90,6 +91,7 @@ class AccountStore: ObservableObject { self.storageUsageIsLoading = true } success: { self.storageUsage = storageUsage + self.storageUsageError = nil } failure: { message in self.storageUsageError = message } anyways: { @@ -126,6 +128,7 @@ class AccountStore: ObservableObject { if let user { DispatchQueue.main.async { self.identityUser = user + self.identityUserError = nil } } } @@ -136,6 +139,7 @@ class AccountStore: ObservableObject { if let storageUsage { DispatchQueue.main.async { self.storageUsage = storageUsage + self.storageUsageError = nil } } } diff --git a/Sources/Screens/Browser/BrowserStore.swift b/Sources/Screens/Browser/BrowserStore.swift index f39354c..15eefeb 100644 --- a/Sources/Screens/Browser/BrowserStore.swift +++ b/Sources/Screens/Browser/BrowserStore.swift @@ -69,6 +69,7 @@ class BrowserStore: ObservableObject { self.folderIsLoading = true } success: { self.folder = folder + self.folderError = nil } failure: { message in self.folderError = message } anyways: { @@ -108,6 +109,7 @@ class BrowserStore: ObservableObject { if !self.hasNextPage() { return false } nextPage = self.nextPage() list = try await self.fetchList(folderID, page: nextPage) + self.entitiesError = nil return true } before: { self.entitiesIsLoading = true @@ -190,6 +192,7 @@ class BrowserStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } @@ -200,6 +203,7 @@ class BrowserStore: ObservableObject { if let folder { DispatchQueue.main.async { self.folder = folder + self.folderError = nil } } } diff --git a/Sources/Screens/File/FileStore.swift b/Sources/Screens/File/FileStore.swift index b52388a..e49a445 100644 --- a/Sources/Screens/File/FileStore.swift +++ b/Sources/Screens/File/FileStore.swift @@ -124,6 +124,7 @@ class FileStore: ObservableObject { self.fileIsLoading = true } success: { self.file = folder + self.fileError = nil } failure: { message in self.fileError = message } anyways: { @@ -163,6 +164,7 @@ class FileStore: ObservableObject { if !self.hasNextPage() { return false } nextPage = self.nextPage() list = try await self.fetchList(file.id, page: nextPage) + self.entitiesError = nil return true } before: { self.entitiesIsLoading = true @@ -190,6 +192,7 @@ class FileStore: ObservableObject { var taskCount: Int? withErrorHandling { taskCount = try await self.fetchTaskCount() + self.taskCountError = nil return true } before: { self.taskCountIsLoading = true @@ -211,6 +214,7 @@ class FileStore: ObservableObject { var storageUsage: VOStorage.Usage? withErrorHandling { storageUsage = try await self.fetchStorageUsage() + self.storageUsageError = nil return true } before: { self.storageUsageIsLoading = true @@ -232,6 +236,7 @@ class FileStore: ObservableObject { var itemCount: Int? withErrorHandling { itemCount = try await self.fetchItemCount() + self.itemCountError = nil return true } before: { self.itemCountIsLoading = true @@ -364,6 +369,7 @@ class FileStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } @@ -374,6 +380,7 @@ class FileStore: ObservableObject { if let file { DispatchQueue.main.async { self.file = file + self.fileError = nil } } } @@ -383,6 +390,7 @@ class FileStore: ObservableObject { let taskCount = try await self.fetchTaskCount() DispatchQueue.main.async { self.taskCount = taskCount + self.taskCountError = nil } } } diff --git a/Sources/Screens/Group/GroupStore.swift b/Sources/Screens/Group/GroupStore.swift index ebb1918..efecbb8 100644 --- a/Sources/Screens/Group/GroupStore.swift +++ b/Sources/Screens/Group/GroupStore.swift @@ -120,6 +120,7 @@ class GroupStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -210,16 +211,7 @@ class GroupStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data - } - } - } - } - if let current = self.current { - Task { - let group = try await self.groupClient?.fetch(current.id) - if let group { - DispatchQueue.main.async { - self.current = group + self.entitiesError = nil } } } diff --git a/Sources/Screens/Insights/InsightsStore.swift b/Sources/Screens/Insights/InsightsStore.swift index 45dc8d8..02ed0ce 100644 --- a/Sources/Screens/Insights/InsightsStore.swift +++ b/Sources/Screens/Insights/InsightsStore.swift @@ -71,6 +71,7 @@ class InsightsStore: ObservableObject { self.languagesIsLoading = true } success: { self.languages = languages + self.languagesError = nil } failure: { message in self.languagesError = message } anyways: { @@ -87,6 +88,7 @@ class InsightsStore: ObservableObject { var info: VOInsights.Info? withErrorHandling { info = try await self.fetchInfo() + self.infoError = nil return true } before: { self.infoIsLoading = true @@ -148,6 +150,7 @@ class InsightsStore: ObservableObject { if !self.hasNextPage() { return false } nextPage = self.nextPage() list = try await self.fetchEntityList(page: nextPage) + self.entitiesError = nil return true } before: { self.entitiesIsLoading = true @@ -247,6 +250,7 @@ class InsightsStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } diff --git a/Sources/Screens/Invitation/InvitationStore.swift b/Sources/Screens/Invitation/InvitationStore.swift index 941c17e..8d13261 100644 --- a/Sources/Screens/Invitation/InvitationStore.swift +++ b/Sources/Screens/Invitation/InvitationStore.swift @@ -90,6 +90,7 @@ class InvitationStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -110,6 +111,7 @@ class InvitationStore: ObservableObject { self.incomingCountIsLoading = true } success: { self.incomingCount = incomingCount + self.incomingCountError = nil } failure: { message in self.incomingCountError = message } anyways: { @@ -199,6 +201,7 @@ class InvitationStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } @@ -209,6 +212,7 @@ class InvitationStore: ObservableObject { if let incomingCount { DispatchQueue.main.async { self.incomingCount = incomingCount + self.incomingCountError = nil } } } diff --git a/Sources/Screens/Mosaic/MosaicStore.swift b/Sources/Screens/Mosaic/MosaicStore.swift index 787eaed..5bf9a72 100644 --- a/Sources/Screens/Mosaic/MosaicStore.swift +++ b/Sources/Screens/Mosaic/MosaicStore.swift @@ -45,6 +45,7 @@ class MosaicStore: ObservableObject { self.infoIsLoading = true } success: { self.info = info + self.infoError = nil } failure: { message in self.infoError = message } anyways: { @@ -71,6 +72,7 @@ class MosaicStore: ObservableObject { if let info { DispatchQueue.main.async { self.info = info + self.infoError = nil } } } diff --git a/Sources/Screens/Organization/OrganizationStore.swift b/Sources/Screens/Organization/OrganizationStore.swift index 8835338..3c00b47 100644 --- a/Sources/Screens/Organization/OrganizationStore.swift +++ b/Sources/Screens/Organization/OrganizationStore.swift @@ -94,6 +94,7 @@ class OrganizationStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -184,16 +185,7 @@ class OrganizationStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data - } - } - } - } - if let current = self.current { - Task { - let organization = try await self.fetch(current.id) - if let organization { - DispatchQueue.main.async { - self.current = organization + self.entitiesError = nil } } } diff --git a/Sources/Screens/Sharing/SharingStore.swift b/Sources/Screens/Sharing/SharingStore.swift index 99b1095..8d9db20 100644 --- a/Sources/Screens/Sharing/SharingStore.swift +++ b/Sources/Screens/Sharing/SharingStore.swift @@ -58,6 +58,7 @@ class SharingStore: ObservableObject { self.userPermissionsIsLoading = true } success: { self.userPermissions = userPermissions + self.userPermissionsError = nil } failure: { message in self.userPermissionsError = message } anyways: { @@ -75,6 +76,7 @@ class SharingStore: ObservableObject { withErrorHandling { groupPermissions = try await self.fetchGroupPermissions(fileID) + self.groupPermissionsError = nil return true } before: { self.groupPermissionsIsLoading = true @@ -117,6 +119,7 @@ class SharingStore: ObservableObject { if let values { DispatchQueue.main.async { self.userPermissions = values + self.userPermissionsError = nil } } } @@ -127,6 +130,7 @@ class SharingStore: ObservableObject { if let values { DispatchQueue.main.async { self.groupPermissions = values + self.groupPermissionsError = nil } } } diff --git a/Sources/Screens/SignUp/SignUpStore.swift b/Sources/Screens/SignUp/SignUpStore.swift index ff93e85..9307815 100644 --- a/Sources/Screens/SignUp/SignUpStore.swift +++ b/Sources/Screens/SignUp/SignUpStore.swift @@ -34,6 +34,7 @@ class SignUpStore: ObservableObject { self.passwordRequirementsIsLoading = true } success: { self.passwordRequirements = passwordRequirements + self.passwordRequirementsError = nil } failure: { message in self.passwordRequirementsError = message } anyways: { @@ -58,6 +59,7 @@ class SignUpStore: ObservableObject { if let passwordRequirements { DispatchQueue.main.async { self.passwordRequirements = passwordRequirements + self.passwordRequirementsError = nil } } } diff --git a/Sources/Screens/Snapshot/SnapshotStore.swift b/Sources/Screens/Snapshot/SnapshotStore.swift index b574099..fc2e6c8 100644 --- a/Sources/Screens/Snapshot/SnapshotStore.swift +++ b/Sources/Screens/Snapshot/SnapshotStore.swift @@ -86,6 +86,7 @@ class SnapshotStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -166,6 +167,7 @@ class SnapshotStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } diff --git a/Sources/Screens/Task/TaskStore.swift b/Sources/Screens/Task/TaskStore.swift index 83e13f3..a538423 100644 --- a/Sources/Screens/Task/TaskStore.swift +++ b/Sources/Screens/Task/TaskStore.swift @@ -76,6 +76,7 @@ class TaskStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -156,6 +157,7 @@ class TaskStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } diff --git a/Sources/Screens/User/UserStore.swift b/Sources/Screens/User/UserStore.swift index 2377acf..432bbe8 100644 --- a/Sources/Screens/User/UserStore.swift +++ b/Sources/Screens/User/UserStore.swift @@ -139,6 +139,7 @@ class UserStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -209,6 +210,7 @@ class UserStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } diff --git a/Sources/Screens/Workspace/WorkspaceStore.swift b/Sources/Screens/Workspace/WorkspaceStore.swift index ef5206b..a05363e 100644 --- a/Sources/Screens/Workspace/WorkspaceStore.swift +++ b/Sources/Screens/Workspace/WorkspaceStore.swift @@ -112,6 +112,7 @@ class WorkspaceStore: ObservableObject { self.append(list.data) } } + self.entitiesError = nil } failure: { message in self.entitiesError = message } anyways: { @@ -128,6 +129,7 @@ class WorkspaceStore: ObservableObject { var root: VOFile.Entity? withErrorHandling { root = try await self.fetchRoot() + self.rootError = nil return true } before: { self.rootIsLoading = true @@ -149,6 +151,7 @@ class WorkspaceStore: ObservableObject { var storageUsage: VOStorage.Usage? withErrorHandling { storageUsage = try await self.fetchStorageUsage() + self.storageUsageError = nil return true } before: { self.storageUsageIsLoading = true @@ -256,25 +259,19 @@ class WorkspaceStore: ObservableObject { if let list { DispatchQueue.main.async { self.entities = list.data + self.entitiesError = nil } } } } if self.current != nil { - Task { - let workspace = try await self.fetch() - if let workspace { - DispatchQueue.main.async { - self.current = workspace - } - } - } if self.root != nil { Task { let root = try await self.fetchRoot() if let root { DispatchQueue.main.async { self.root = root + self.rootError = nil } } } @@ -285,6 +282,7 @@ class WorkspaceStore: ObservableObject { if let storageUsage { DispatchQueue.main.async { self.storageUsage = storageUsage + self.storageUsageError = nil } } }