Skip to content

Commit

Permalink
refactor: remove usage of sync() and voErrorAlert()
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba committed Nov 24, 2024
1 parent f56074c commit 6815c4a
Show file tree
Hide file tree
Showing 13 changed files with 118 additions and 93 deletions.
14 changes: 7 additions & 7 deletions Sources/Screens/File/FileCopy.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct FileCopy: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@State private var isProcessing = true
@State private var showError = false
@State private var errorIsPresented = false
@State private var errorSeverity: ErrorSeverity?
@State private var errorMessage: String?
private let destinationID: String
Expand All @@ -28,10 +28,10 @@ struct FileCopy: View {

var body: some View {
VStack {
if isProcessing, !showError {
if isProcessing, !errorIsPresented {
VOSheetProgressView()
Text("Copying \(fileStore.selection.count) item(s).")
} else if showError, errorSeverity == .full {
} else if errorIsPresented, errorSeverity == .full {
VOErrorIcon()
if let errorMessage {
Text(errorMessage)
Expand All @@ -43,7 +43,7 @@ struct FileCopy: View {
}
.voSecondaryButton(colorScheme: colorScheme)
.padding(.horizontal)
} else if showError, errorSeverity == .partial {
} else if errorIsPresented, errorSeverity == .partial {
VOWarningIcon()
if let errorMessage {
Text(errorMessage)
Expand Down Expand Up @@ -80,17 +80,17 @@ struct FileCopy: View {
} else if result.failed.count == fileStore.selection.count {
errorSeverity = .full
}
showError = true
errorIsPresented = true
}
}
return false
} success: {
showError = false
errorIsPresented = false
dismiss()
} failure: { _ in
errorMessage = "Failed to copy \(fileStore.selection.count) item(s)."
errorSeverity = .full
showError = true
errorIsPresented = true
} anyways: {
isProcessing = false
}
Expand Down
14 changes: 7 additions & 7 deletions Sources/Screens/File/FileDelete.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct FileDelete: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@State private var isProcessing = true
@State private var showError = false
@State private var errorIsPresented = false
@State private var errorSeverity: ErrorSeverity?
@State private var errorMessage: String?

Expand All @@ -26,10 +26,10 @@ struct FileDelete: View {

var body: some View {
VStack {
if isProcessing, !showError {
if isProcessing, !errorIsPresented {
VOSheetProgressView()
Text("Deleting \(fileStore.selection.count) item(s).")
} else if showError, errorSeverity == .full {
} else if errorIsPresented, errorSeverity == .full {
VOErrorIcon()
if let errorMessage {
Text(errorMessage)
Expand All @@ -41,7 +41,7 @@ struct FileDelete: View {
}
.voSecondaryButton(colorScheme: colorScheme)
.padding(.horizontal)
} else if showError, errorSeverity == .partial {
} else if errorIsPresented, errorSeverity == .partial {
VOWarningIcon()
if let errorMessage {
Text(errorMessage)
Expand Down Expand Up @@ -76,17 +76,17 @@ struct FileDelete: View {
} else if result.failed.count == fileStore.selection.count {
errorSeverity = .full
}
showError = true
errorIsPresented = true
}
}
return false
} success: {
showError = false
errorIsPresented = false
dismiss()
} failure: { _ in
errorMessage = "Failed to delete \(fileStore.selection.count) item(s)."
errorSeverity = .full
showError = true
errorIsPresented = true
} anyways: {
isProcessing = false
}
Expand Down
12 changes: 6 additions & 6 deletions Sources/Screens/File/FileDownload.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ struct FileDownload: View {
@Environment(\.colorScheme) private var colorScheme
@State private var urls: [URL] = []
@State private var isProcessing = true
@State private var showError = false
@State private var errorIsPresented = false
@State private var errorSeverity: ErrorSeverity?
@State private var errorMessage: String?
private let onCompletion: (([URL]) -> Void)?
Expand All @@ -29,10 +29,10 @@ struct FileDownload: View {

var body: some View {
VStack {
if isProcessing, !showError {
if isProcessing, !errorIsPresented {
VOSheetProgressView()
Text("Downloading \(fileStore.selectionFiles.count) item(s).")
} else if showError, errorSeverity == .full {
} else if errorIsPresented, errorSeverity == .full {
VOErrorIcon()
if let errorMessage {
Text(errorMessage)
Expand All @@ -44,7 +44,7 @@ struct FileDownload: View {
}
.voSecondaryButton(colorScheme: colorScheme)
.padding(.horizontal)
} else if showError, errorSeverity == .partial {
} else if errorIsPresented, errorSeverity == .partial {
VOWarningIcon()
if let errorMessage {
Text(errorMessage)
Expand Down Expand Up @@ -103,7 +103,7 @@ struct FileDownload: View {
}
dispatchGroup.notify(queue: .main) {
if urls.count == fileStore.selection.count {
showError = false
errorIsPresented = false
isProcessing = false
onCompletion?(urls)
dismiss()
Expand All @@ -115,7 +115,7 @@ struct FileDownload: View {
} else {
errorSeverity = .full
}
showError = true
errorIsPresented = true
isProcessing = false
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Screens/File/FileGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ struct FileGrid: View, ListItemScrollable {
}
}
}

// MARK: - ListItemScrollable

func onListItemAppear(_ id: String) {
Expand Down
12 changes: 6 additions & 6 deletions Sources/Screens/File/FileInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -162,17 +162,17 @@ struct FileInfo: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, Toke
case .folder: "Folder"
}
}

// MARK: - LoadStateProvider

var isLoading: Bool {
fileStore.storageUsageIsLoading || fileStore.itemCountIsLoading
}

var error: String? {
fileStore.storageUsageError ?? fileStore.itemCountError
}

// MARK: - ViewDataProvider

func onAppearOrChange() {
Expand All @@ -185,7 +185,7 @@ struct FileInfo: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, Toke
fileStore.fetchItemCount()
}
}

// MARK: - TimerLifecycle

func startTimers() {
Expand All @@ -195,7 +195,7 @@ struct FileInfo: View, ViewDataProvider, LoadStateProvider, TimerLifecycle, Toke
func stopTimers() {
fileStore.stopTimer()
}

// MARK: - TokenDistributing

func assignTokenToStores(_ token: VOToken.Value) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Screens/File/FileList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ struct FileList: View, ListItemScrollable {
}
}
}

// MARK: - ListItemScrollable

func onListItemAppear(_ id: String) {
Expand Down
14 changes: 7 additions & 7 deletions Sources/Screens/File/FileMove.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct FileMove: View {
@Environment(\.dismiss) private var dismiss
@Environment(\.colorScheme) private var colorScheme
@State private var isProcessing = true
@State private var showError = false
@State private var errorIsPresented = false
@State private var errorSeverity: ErrorSeverity?
@State private var errorMessage: String?
private let destinationID: String
Expand All @@ -28,10 +28,10 @@ struct FileMove: View {

var body: some View {
VStack {
if isProcessing, !showError {
if isProcessing, !errorIsPresented {
VOSheetProgressView()
Text("Moving \(fileStore.selection.count) item(s).")
} else if showError, errorSeverity == .full {
} else if errorIsPresented, errorSeverity == .full {
VOErrorIcon()
if let errorMessage {
Text(errorMessage)
Expand All @@ -43,7 +43,7 @@ struct FileMove: View {
}
.voSecondaryButton(colorScheme: colorScheme)
.padding(.horizontal)
} else if showError, errorSeverity == .partial {
} else if errorIsPresented, errorSeverity == .partial {
VOWarningIcon()
if let errorMessage {
Text(errorMessage)
Expand Down Expand Up @@ -78,17 +78,17 @@ struct FileMove: View {
} else if result.failed.count == fileStore.selection.count {
errorSeverity = .full
}
showError = true
errorIsPresented = true
}
}
return false
} success: {
showError = false
errorIsPresented = false
dismiss()
} failure: { _ in
errorMessage = "Failed to move \(fileStore.selection.count) item(s)."
errorSeverity = .full
showError = true
errorIsPresented = true
} anyways: {
isProcessing = false
}
Expand Down
13 changes: 6 additions & 7 deletions Sources/Screens/File/FileOverview.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ struct FileOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
@StateObject private var fileStore = FileStore()
@ObservedObject private var workspaceStore: WorkspaceStore
@State private var searchText = ""
@State private var showError = false
private let file: VOFile.Entity

init(_ file: VOFile.Entity, workspaceStore: WorkspaceStore) {
Expand Down Expand Up @@ -76,17 +75,17 @@ struct FileOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
fileStore.fetchNextPage(replace: true)
}
}

// MARK: - LoadStateProvider

var isLoading: Bool {
fileStore.entities == nil || fileStore.fileIsLoading || fileStore.taskCountIsLoading
}

var error: String? {
fileStore.entitiesError ?? fileStore.fileError ?? fileStore.taskCountError
}

// MARK: - ViewDataProvider

func onAppearOrChange() {
Expand All @@ -98,7 +97,7 @@ struct FileOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
fileStore.fetchNextPage(replace: true)
fileStore.fetchTaskCount()
}

// MARK: - TimerLifecycle

func startTimers() {
Expand All @@ -108,7 +107,7 @@ struct FileOverview: View, ViewDataProvider, LoadStateProvider, TimerLifecycle,
func stopTimers() {
fileStore.stopTimer()
}

// MARK: - TokenDistributing

func assignTokenToStores(_ token: VOToken.Value) {
Expand Down
Loading

0 comments on commit 6815c4a

Please sign in to comment.