Skip to content

Commit

Permalink
fix: file error handling (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
bouassaba authored Nov 24, 2024
1 parent 6a101f5 commit 83be484
Show file tree
Hide file tree
Showing 31 changed files with 435 additions and 385 deletions.
8 changes: 4 additions & 4 deletions Sources/Screens/Browser/BrowserStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -189,12 +189,12 @@ class BrowserStore: ObservableObject {
}
}
}
if let current = self.folder {
if self.folder != nil {
Task {
let file = try await self.fetchFolder()
if let file {
let folder = try await self.fetchFolder()
if let folder {
DispatchQueue.main.async {
self.folder = file
self.folder = folder
}
}
}
Expand Down
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
6 changes: 4 additions & 2 deletions Sources/Screens/File/FileGrid.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import SwiftUI
import VoltaserveCore

struct FileGrid: View {
struct FileGrid: View, ListItemScrollable {
@ObservedObject private var fileStore: FileStore
@ObservedObject private var workspaceStore: WorkspaceStore
@State private var tappedItem: VOFile.Entity?
Expand Down Expand Up @@ -72,7 +72,9 @@ struct FileGrid: View {
}
}

private func onListItemAppear(_ id: String) {
// MARK: - ListItemScrollable

func onListItemAppear(_ id: String) {
if fileStore.isEntityThreshold(id) {
fileStore.fetchNextPage()
}
Expand Down
Loading

0 comments on commit 83be484

Please sign in to comment.