From 709888a560ab84e2a7e0bd1e709c4ea184ce6e6d Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Mon, 13 Feb 2023 16:10:16 +0100 Subject: [PATCH] Improvements on home timeline. --- Vernissage/Services/ErrorsService.swift | 2 +- Vernissage/Views/HomeFeedView.swift | 1 + Vernissage/Widgets/ImageRow.swift | 22 ++++++++++++++++++---- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/Vernissage/Services/ErrorsService.swift b/Vernissage/Services/ErrorsService.swift index f9cc386..0e0490e 100644 --- a/Vernissage/Services/ErrorsService.swift +++ b/Vernissage/Services/ErrorsService.swift @@ -15,6 +15,6 @@ public class ErrorService { ToastrService.shared.showError(subtitle: message) } - print("Error: \(error.localizedDescription)") + print("Error ['\(message)']: \(error.localizedDescription)") } } diff --git a/Vernissage/Views/HomeFeedView.swift b/Vernissage/Views/HomeFeedView.swift index 2982745..ee20e96 100644 --- a/Vernissage/Views/HomeFeedView.swift +++ b/Vernissage/Views/HomeFeedView.swift @@ -157,6 +157,7 @@ struct HomeFeedView: View { // View is scrolled so high that we can hide view. if offset > 170 { + self.applicationState.amountOfNewStatuses = 0 self.hideNewStatusesView() } } diff --git a/Vernissage/Widgets/ImageRow.swift b/Vernissage/Widgets/ImageRow.swift index d47de8b..4ce1725 100644 --- a/Vernissage/Widgets/ImageRow.swift +++ b/Vernissage/Widgets/ImageRow.swift @@ -19,6 +19,7 @@ struct ImageRow: View { @State private var uiImage:UIImage? @State private var showThumbImage = false @State private var error: Error? + @State private var cancelled = true init(statusData: StatusData) { self.status = statusData @@ -92,13 +93,19 @@ struct ImageRow: View { } .frame(width: self.imageWidth, height: self.imageHeight) } else { - if let error { + if cancelled { + BlurredImage(blurhash: attachmentData.blurhash) + .frame(width: self.imageWidth, height: self.imageHeight) + .task { + await self.downloadImage(attachmentData: attachmentData) + } + } + else if let error { ZStack { BlurredImage(blurhash: attachmentData.blurhash) .frame(width: self.imageWidth, height: self.imageHeight) ErrorView(error: error) { - self.error = nil await self.downloadImage(attachmentData: attachmentData) } .padding() @@ -130,10 +137,17 @@ struct ImageRow: View { self.uiImage = downloadedImage HomeTimelineService.shared.update(attachment: attachmentData, withData: imageData, imageWidth: size.width, imageHeight: size.height) + self.error = nil + self.cancelled = false } } catch { - ErrorService.shared.handle(error, message: "Cannot download the image.") - self.error = error + if !Task.isCancelled { + ErrorService.shared.handle(error, message: "Cannot download the image.") + self.error = error + } else { + ErrorService.shared.handle(error, message: "Download image has been canceled.") + self.cancelled = true + } } }