Skip to content

Commit 033bfc2

Browse files
committed
Loading fixes
1 parent 2a0f132 commit 033bfc2

File tree

4 files changed

+302
-248
lines changed

4 files changed

+302
-248
lines changed

Django Files/Views/Common/LoadingView.swift

Lines changed: 25 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,35 @@ struct LoadingView: View {
1212
@State private var firstAppear = false
1313

1414
var body: some View {
15-
Circle()
16-
.trim(from: 0, to: 0.8)
17-
.stroke(Color.launchScreenBackground, lineWidth: 5)
18-
.rotationEffect(Angle(degrees: isLoading ? 360 : 0))
19-
.opacity(firstAppear ? 1 : 0)
20-
.onAppear {
21-
DispatchQueue.main.async {
22-
if isLoading == false {
23-
withAnimation(
24-
.linear(duration: 1).repeatForever(
25-
autoreverses: false
26-
)
27-
) {
28-
isLoading.toggle()
15+
ZStack{
16+
Circle()
17+
.trim(from: 0, to: 0.8)
18+
.stroke(Color.launchScreenBackground, lineWidth: 5)
19+
.rotationEffect(Angle(degrees: isLoading ? 360 : 0))
20+
.opacity(firstAppear ? 1 : 0)
21+
.onAppear {
22+
DispatchQueue.main.async {
23+
if isLoading == false {
24+
withAnimation(
25+
.linear(duration: 1).repeatForever(
26+
autoreverses: false
27+
)
28+
) {
29+
isLoading.toggle()
30+
}
31+
}
32+
withAnimation(.easeInOut(duration: 0.25)) {
33+
firstAppear = true
2934
}
30-
}
31-
withAnimation(.easeInOut(duration: 0.25)) {
32-
firstAppear = true
3335
}
3436
}
35-
}
36-
.onDisappear {
37-
DispatchQueue.main.async {
38-
withAnimation(.easeInOut(duration: 0.25)) {
39-
firstAppear = true
37+
.onDisappear {
38+
DispatchQueue.main.async {
39+
withAnimation(.easeInOut(duration: 0.25)) {
40+
firstAppear = true
41+
}
4042
}
4143
}
42-
}
44+
}
4345
}
4446
}

Django Files/Views/Lists/AlbumList.swift

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,8 @@ struct AlbumListView: View {
114114
}
115115

116116
if isLoading && hasNextPage {
117-
HStack {
118-
Spacer()
119-
ProgressView()
120-
Spacer()
121-
}
117+
ProgressView()
118+
.frame(width: 50, height: 50)
122119
}
123120
}
124121
}

Django Files/Views/Lists/FileList.swift

Lines changed: 99 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ struct FileListView: View {
262262
previewStateManager.deepLinkTargetFileID = nil
263263
}
264264
foundFile = true
265-
} else if !hasNextPage {
265+
} else if !hasNextPage || errorMessage != nil {
266+
// Stop if we hit an error or no more pages
266267
break
267268
}
268269
currentPage += 1
@@ -289,15 +290,39 @@ struct FileListView: View {
289290
Spacer()
290291
VStack {
291292
Spacer()
292-
Image(systemName: "document.on.document.fill")
293-
.font(.system(size: 50))
294-
.padding(.bottom)
295-
.shadow(color: .purple, radius: 15)
296-
Text("No files found")
297-
.font(.headline)
298-
.shadow(color: .purple, radius: 20)
299-
Text("Upload a file to get started")
300-
.foregroundColor(.secondary)
293+
if let errorMessage = errorMessage {
294+
// Show error message instead of "no files found"
295+
Image(systemName: "exclamationmark.triangle.fill")
296+
.font(.system(size: 50))
297+
.foregroundColor(.orange)
298+
.padding(.bottom)
299+
.shadow(color: .orange, radius: 15)
300+
Text("Error loading files")
301+
.font(.headline)
302+
.shadow(color: .orange, radius: 20)
303+
Text(errorMessage)
304+
.foregroundColor(.secondary)
305+
.multilineTextAlignment(.center)
306+
.padding(.horizontal)
307+
Button("Retry") {
308+
Task {
309+
await refreshFiles()
310+
}
311+
}
312+
.padding(.top)
313+
.buttonStyle(.borderedProminent)
314+
} else {
315+
// Show "no files found" when there's no error
316+
Image(systemName: "document.on.document.fill")
317+
.font(.system(size: 50))
318+
.padding(.bottom)
319+
.shadow(color: .purple, radius: 15)
320+
Text("No files found")
321+
.font(.headline)
322+
.shadow(color: .purple, radius: 20)
323+
Text("Upload a file to get started")
324+
.foregroundColor(.secondary)
325+
}
301326
}
302327
.padding()
303328
Spacer()
@@ -547,6 +572,7 @@ struct FileListView: View {
547572
private func uploadClipboard() async {
548573
guard let serverInstance = server.wrappedValue,
549574
let url = URL(string: serverInstance.url) else {
575+
ToastManager.shared.showToast(message: "Invalid server configuration")
550576
return
551577
}
552578

@@ -560,11 +586,18 @@ struct FileListView: View {
560586
do {
561587
try text.write(to: tempURL, atomically: true, encoding: .utf8)
562588
let delegate = UploadProgressDelegate { _ in }
563-
_ = await api.uploadFile(url: tempURL, taskDelegate: delegate)
589+
let response = await api.uploadFile(url: tempURL, taskDelegate: delegate)
564590
try? FileManager.default.removeItem(at: tempURL)
565-
await refreshFiles()
591+
if response != nil {
592+
await refreshFiles()
593+
ToastManager.shared.showToast(message: "Text uploaded successfully")
594+
} else {
595+
ToastManager.shared.showToast(message: "Failed to upload text")
596+
}
566597
} catch {
598+
try? FileManager.default.removeItem(at: tempURL)
567599
print("Error uploading clipboard text: \(error)")
600+
ToastManager.shared.showToast(message: "Error uploading text: \(error.localizedDescription)")
568601
}
569602
return
570603
}
@@ -577,11 +610,18 @@ struct FileListView: View {
577610
do {
578611
try imageData.write(to: tempURL)
579612
let delegate = UploadProgressDelegate { _ in }
580-
_ = await api.uploadFile(url: tempURL, taskDelegate: delegate)
613+
let response = await api.uploadFile(url: tempURL, taskDelegate: delegate)
581614
try? FileManager.default.removeItem(at: tempURL)
582-
await refreshFiles()
615+
if response != nil {
616+
await refreshFiles()
617+
ToastManager.shared.showToast(message: "Image uploaded successfully")
618+
} else {
619+
ToastManager.shared.showToast(message: "Failed to upload image")
620+
}
583621
} catch {
622+
try? FileManager.default.removeItem(at: tempURL)
584623
print("Error uploading clipboard image: \(error)")
624+
ToastManager.shared.showToast(message: "Error uploading image: \(error.localizedDescription)")
585625
}
586626
}
587627
return
@@ -593,14 +633,24 @@ struct FileListView: View {
593633
do {
594634
try videoData.write(to: tempURL)
595635
let delegate = UploadProgressDelegate { _ in }
596-
_ = await api.uploadFile(url: tempURL, taskDelegate: delegate)
636+
let response = await api.uploadFile(url: tempURL, taskDelegate: delegate)
597637
try? FileManager.default.removeItem(at: tempURL)
598-
await refreshFiles()
638+
if response != nil {
639+
await refreshFiles()
640+
ToastManager.shared.showToast(message: "Video uploaded successfully")
641+
} else {
642+
ToastManager.shared.showToast(message: "Failed to upload video")
643+
}
599644
} catch {
645+
try? FileManager.default.removeItem(at: tempURL)
600646
print("Error uploading clipboard video: \(error)")
647+
ToastManager.shared.showToast(message: "Error uploading video: \(error.localizedDescription)")
601648
}
602649
return
603650
}
651+
652+
// If we get here, no content was found in clipboard
653+
ToastManager.shared.showToast(message: "No content found in clipboard")
604654
}
605655

606656
private func fileContextMenu(for file: DFFile, isPreviewing: Bool, isPrivate: Bool, expirationText: Binding<String>, passwordText: Binding<String>, fileNameText: Binding<String>) -> FileContextMenuButtons {
@@ -710,33 +760,52 @@ struct FileListView: View {
710760
private func fetchFiles(page: Int, append: Bool = false) async {
711761
guard let serverInstance = server.wrappedValue,
712762
let url = URL(string: serverInstance.url) else {
713-
errorMessage = "Invalid server URL"
763+
let errorMsg = "Invalid server URL"
764+
errorMessage = errorMsg
714765
isLoading = false
766+
// Show toast message for the error
767+
ToastManager.shared.showToast(message: errorMsg)
715768
return
716769
}
717770

718771
let api = DFAPI(url: url, token: serverInstance.token)
719772

720-
if let filesResponse = await api.getFiles(page: page, album: albumID, selectedServer: serverInstance, filterUserID: filterUserID) {
721-
if append {
722-
// Only append new files that aren't already in the list
723-
let newFiles = filesResponse.files.filter { newFile in
724-
!files.contains { $0.id == newFile.id }
773+
do {
774+
if let filesResponse = await api.getFiles(page: page, album: albumID, selectedServer: serverInstance, filterUserID: filterUserID) {
775+
if append {
776+
// Only append new files that aren't already in the list
777+
let newFiles = filesResponse.files.filter { newFile in
778+
!files.contains { $0.id == newFile.id }
779+
}
780+
files.append(contentsOf: newFiles)
781+
} else {
782+
files = filesResponse.files
725783
}
726-
files.append(contentsOf: newFiles)
784+
785+
hasNextPage = filesResponse.next != nil
786+
currentPage = page
787+
isLoading = false
788+
// Clear any previous error message on success
789+
errorMessage = nil
727790
} else {
728-
files = filesResponse.files
791+
if !append {
792+
files = []
793+
}
794+
let errorMsg = "Failed to load files from server"
795+
errorMessage = errorMsg
796+
isLoading = false
797+
// Show toast message for the error
798+
ToastManager.shared.showToast(message: errorMsg)
729799
}
730-
731-
hasNextPage = filesResponse.next != nil
732-
currentPage = page
733-
isLoading = false
734-
} else {
800+
} catch {
735801
if !append {
736802
files = []
737803
}
738-
errorMessage = "Failed to load files from server"
804+
let errorMsg = "Error loading files: \(error.localizedDescription)"
805+
errorMessage = errorMsg
739806
isLoading = false
807+
// Show toast message for the error
808+
ToastManager.shared.showToast(message: errorMsg)
740809
}
741810
}
742811

0 commit comments

Comments
 (0)