From e601a564d9ef6ae172e18af1531fd36203389820 Mon Sep 17 00:00:00 2001 From: Marcin Czachurski Date: Sun, 8 Oct 2023 11:35:45 +0200 Subject: [PATCH] Fix reblogs in iPad version --- Vernissage.xcodeproj/project.pbxproj | 12 +++---- Vernissage/Views/PaginableStatusesView.swift | 2 +- Vernissage/Views/StatusesView.swift | 18 ++++++++++- Vernissage/Views/TrendStatusesView.swift | 2 +- .../Subviews/UserProfileStatusesView.swift | 2 +- Vernissage/Widgets/WaterfallGrid.swift | 32 ++++++++++++++++--- 6 files changed, 53 insertions(+), 15 deletions(-) diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index 9a29da3..b485c88 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -1348,7 +1348,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1379,7 +1379,7 @@ ASSETCATALOG_COMPILER_WIDGET_BACKGROUND_COLOR_NAME = WidgetBackground; CODE_SIGN_ENTITLEMENTS = VernissageWidget/VernissageWidgetExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageWidget/Info.plist; @@ -1409,7 +1409,7 @@ CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1438,7 +1438,7 @@ ASSETCATALOG_COMPILER_GENERATE_SWIFT_ASSET_SYMBOL_EXTENSIONS = NO; CODE_SIGN_ENTITLEMENTS = VernissageShare/VernissageShareExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_TEAM = B2U9FEKYP8; GENERATE_INFOPLIST_FILE = YES; INFOPLIST_FILE = VernissageShare/Info.plist; @@ -1592,7 +1592,7 @@ CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1635,7 +1635,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_ENTITLEMENTS = Vernissage/Vernissage.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 255; + CURRENT_PROJECT_VERSION = 256; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; diff --git a/Vernissage/Views/PaginableStatusesView.swift b/Vernissage/Views/PaginableStatusesView.swift index 6e6e29e..fd89f5c 100644 --- a/Vernissage/Views/PaginableStatusesView.swift +++ b/Vernissage/Views/PaginableStatusesView.swift @@ -81,7 +81,7 @@ struct PaginableStatusesView: View { private func list() -> some View { ScrollView { if self.imageColumns > 1 { - WaterfallGrid($statusViewModels, columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in + WaterfallGrid($statusViewModels, refreshId: Binding.constant(""), columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in ImageRowAsync(statusViewModel: item, containerWidth: $containerWidth) } onLoadMore: { do { diff --git a/Vernissage/Views/StatusesView.swift b/Vernissage/Views/StatusesView.swift index 4abc9ef..29178fe 100644 --- a/Vernissage/Views/StatusesView.swift +++ b/Vernissage/Views/StatusesView.swift @@ -52,6 +52,7 @@ struct StatusesView: View { @State private var statusViewModels: [StatusModel] = [] @State private var state: ViewState = .loading @State private var lastStatusId: String? + @State private var waterfallId: String = String.randomString(length: 8) // Gallery parameters. @State private var imageColumns = 3 @@ -96,7 +97,7 @@ struct StatusesView: View { private func list() -> some View { ScrollView { if self.imageColumns > 1 { - WaterfallGrid($statusViewModels, columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in + WaterfallGrid($statusViewModels, refreshId: $waterfallId, columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in ImageRowAsync(statusViewModel: item, containerWidth: $containerWidth) } onLoadMore: { do { @@ -142,6 +143,17 @@ struct StatusesView: View { ErrorService.shared.handle(error, message: "statuses.error.loadingStatusesFailed", showToastr: !Task.isCancelled) } } + .onChange(of: self.applicationState.showReboostedStatuses) { _ in + if self.listType != .home { + return + } + + Task { @MainActor in + HapticService.shared.fireHaptic(of: .dataRefresh(intensity: 0.3)) + try await self.loadTopStatuses() + HapticService.shared.fireHaptic(of: .dataRefresh(intensity: 0.7)) + } + } } private func loadData() async { @@ -227,8 +239,12 @@ struct StatusesView: View { for item in statuses.getStatusesWithImagesOnly() { inPlaceStatuses.append(StatusModel(status: item)) } + + // Prefetch images. + self.prefetch(statusModels: inPlaceStatuses) // Replace old collection with new one. + self.waterfallId = String.randomString(length: 8) self.statusViewModels = inPlaceStatuses } diff --git a/Vernissage/Views/TrendStatusesView.swift b/Vernissage/Views/TrendStatusesView.swift index a0ccc9d..907ea91 100644 --- a/Vernissage/Views/TrendStatusesView.swift +++ b/Vernissage/Views/TrendStatusesView.swift @@ -90,7 +90,7 @@ struct TrendStatusesView: View { NoDataView(imageSystemName: "photo.on.rectangle.angled", text: "trendingStatuses.title.noPhotos") } else { if self.imageColumns > 1 { - WaterfallGrid($statusViewModels, columns: $imageColumns, hideLoadMore: Binding.constant(true)) { item in + WaterfallGrid($statusViewModels, refreshId: Binding.constant(""), columns: $imageColumns, hideLoadMore: Binding.constant(true)) { item in ImageRowAsync(statusViewModel: item, containerWidth: $containerWidth) } onLoadMore: { } } else { diff --git a/Vernissage/Views/UserProfileView/Subviews/UserProfileStatusesView.swift b/Vernissage/Views/UserProfileView/Subviews/UserProfileStatusesView.swift index c62bd4d..c4500d7 100644 --- a/Vernissage/Views/UserProfileView/Subviews/UserProfileStatusesView.swift +++ b/Vernissage/Views/UserProfileView/Subviews/UserProfileStatusesView.swift @@ -42,7 +42,7 @@ struct UserProfileStatusesView: View { var body: some View { if firstLoadFinished == true { if self.imageColumns > 1 { - WaterfallGrid($statusViewModels, columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in + WaterfallGrid($statusViewModels, refreshId: Binding.constant(""), columns: $imageColumns, hideLoadMore: $allItemsLoaded) { item in ImageRowAsync(statusViewModel: item, withAvatar: false, containerWidth: $containerWidth) } onLoadMore: { do { diff --git a/Vernissage/Widgets/WaterfallGrid.swift b/Vernissage/Widgets/WaterfallGrid.swift index 4206270..d097f90 100644 --- a/Vernissage/Widgets/WaterfallGrid.swift +++ b/Vernissage/Widgets/WaterfallGrid.swift @@ -13,11 +13,13 @@ struct WaterfallGrid: View where Data: RandomAccessCollection @Binding private var columns: Int @Binding private var hideLoadMore: Bool @Binding private var data: Data + @Binding private var refreshId: String private let content: (Data.Element) -> Content @State private var columnsData: [ColumnData] = [] @State private var processedItems: [Data.Element.ID] = [] + @State private var shouldRecalculate = false private let onLoadMore: () async -> Void private let semaphore = AsyncSemaphore(value: 1) @@ -46,8 +48,16 @@ struct WaterfallGrid: View where Data: RandomAccessCollection .onFirstAppear { self.recalculateArrays() } + .onChange(of: self.refreshId) { _ in + self.shouldRecalculate = true + } .onChange(of: self.data) { _ in - self.appendToArrays() + if self.shouldRecalculate { + self.recalculateArrays() + self.shouldRecalculate = false + } else { + self.appendToArrays() + } } .onChange(of: self.columns) { _ in self.recalculateArrays() @@ -113,25 +123,37 @@ struct WaterfallGrid: View where Data: RandomAccessCollection } extension WaterfallGrid { - init(_ data: Binding, id: KeyPath, columns: Binding, - hideLoadMore: Binding, content: @escaping (Data.Element) -> Content, onLoadMore: @escaping () async -> Void) { + init(_ data: Binding, + refreshId: Binding, + columns: Binding, + hideLoadMore: Binding, + content: @escaping (Data.Element) -> Content, + onLoadMore: @escaping () async -> Void) { + self.content = content self.onLoadMore = onLoadMore self._data = data self._columns = columns self._hideLoadMore = hideLoadMore + self._refreshId = refreshId } } extension WaterfallGrid where ID == Data.Element.ID, Data.Element: Identifiable { - init(_ data: Binding, columns: Binding, - hideLoadMore: Binding, content: @escaping (Data.Element) -> Content, onLoadMore: @escaping () async -> Void) { + init(_ data: Binding, + refreshId: Binding, + columns: Binding, + hideLoadMore: Binding, + content: @escaping (Data.Element) -> Content, + onLoadMore: @escaping () async -> Void) { + self.content = content self.onLoadMore = onLoadMore self._data = data self._columns = columns self._hideLoadMore = hideLoadMore + self._refreshId = refreshId } }