From 47a896913c313fcf6e9fba5d0e4ea215fb08f98e Mon Sep 17 00:00:00 2001 From: Marcin Czachursk Date: Fri, 24 Feb 2023 07:30:52 +0100 Subject: [PATCH] Fix issue with not finishing followed by loader. --- Vernissage.xcodeproj/project.pbxproj | 4 +-- Vernissage/Views/AccountsView.swift | 35 ++++++++++--------- .../Views/ComposeView/ComposeView.swift | 2 +- Vernissage/Views/HomeFeedView.swift | 4 ++- 4 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Vernissage.xcodeproj/project.pbxproj b/Vernissage.xcodeproj/project.pbxproj index a943b1e..4aa74ef 100644 --- a/Vernissage.xcodeproj/project.pbxproj +++ b/Vernissage.xcodeproj/project.pbxproj @@ -1035,7 +1035,7 @@ ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_IDENTITY = "Apple Development"; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 32; + CURRENT_PROJECT_VERSION = 33; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; @@ -1072,7 +1072,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; ASSETCATALOG_COMPILER_GLOBAL_ACCENT_COLOR_NAME = AccentColor; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 32; + CURRENT_PROJECT_VERSION = 33; DEVELOPMENT_ASSET_PATHS = "\"Vernissage/Preview Content\""; DEVELOPMENT_TEAM = B2U9FEKYP8; ENABLE_PREVIEWS = YES; diff --git a/Vernissage/Views/AccountsView.swift b/Vernissage/Views/AccountsView.swift index 75ae634..2154bdc 100644 --- a/Vernissage/Views/AccountsView.swift +++ b/Vernissage/Views/AccountsView.swift @@ -38,7 +38,7 @@ struct AccountsView: View { case .loading: LoadingIndicator() .task { - await self.loadAccounts(page: self.downloadedPage) + await self.loadData(page: self.downloadedPage) } case .loaded: if self.accounts.isEmpty { @@ -64,7 +64,7 @@ struct AccountsView: View { LoadingIndicator() .task { self.downloadedPage = self.downloadedPage + 1 - await self.loadAccounts(page: self.downloadedPage) + await self.loadData(page: self.downloadedPage) } Spacer() } @@ -80,35 +80,38 @@ struct AccountsView: View { self.downloadedPage = 1 self.allItemsLoaded = false self.accounts = [] - await self.loadAccounts(page: self.downloadedPage) + await self.loadData(page: self.downloadedPage) } .padding() } } - private func loadAccounts(page: Int) async { + private func loadData(page: Int) async { do { - let accountsFromApi = try await self.loadFromApi(page: page) - - if accountsFromApi.isEmpty { - self.allItemsLoaded = true - return - } - - await self.downloadAvatars(accounts: accountsFromApi) - self.accounts.append(contentsOf: accountsFromApi) - + try await self.loadAccounts(page: page) self.state = .loaded } catch { if !Task.isCancelled { - ErrorService.shared.handle(error, message: "Followers not retrieved.", showToastr: true) + ErrorService.shared.handle(error, message: "Accounts not retrieved.", showToastr: true) self.state = .error(error) } else { - ErrorService.shared.handle(error, message: "Followers not retrieved.", showToastr: false) + ErrorService.shared.handle(error, message: "Accounts not retrieved.", showToastr: false) } } } + private func loadAccounts(page: Int) async throws { + let accountsFromApi = try await self.loadFromApi(page: page) + + if accountsFromApi.isEmpty { + self.allItemsLoaded = true + return + } + + await self.downloadAvatars(accounts: accountsFromApi) + self.accounts.append(contentsOf: accountsFromApi) + } + private func getTitle() -> String { switch self.listType { case .followers: diff --git a/Vernissage/Views/ComposeView/ComposeView.swift b/Vernissage/Views/ComposeView/ComposeView.swift index 7db4467..3fb6e16 100644 --- a/Vernissage/Views/ComposeView/ComposeView.swift +++ b/Vernissage/Views/ComposeView/ComposeView.swift @@ -332,7 +332,7 @@ struct ComposeView: View { } private func placeholder() -> String { - self.statusViewModel == nil ? "Attach photography and type what's on your mind" : "Type what's on your mind" + self.statusViewModel == nil ? "Attach a photo and type what's on your mind" : "Type what's on your mind" } private func isPublishButtonDisabled() -> Bool { diff --git a/Vernissage/Views/HomeFeedView.swift b/Vernissage/Views/HomeFeedView.swift index 4481645..07fd038 100644 --- a/Vernissage/Views/HomeFeedView.swift +++ b/Vernissage/Views/HomeFeedView.swift @@ -26,6 +26,8 @@ struct HomeFeedView: View { @FetchRequest var dbStatuses: FetchedResults + private let pullToRefreshViewHigh: CGFloat = 170 + init(accountId: String) { _dbStatuses = FetchRequest( sortDescriptors: [SortDescriptor(\.id, order: .reverse)], @@ -168,7 +170,7 @@ struct HomeFeedView: View { return } - if offset < 170 { + if offset < self.pullToRefreshViewHigh { // View is scrolled up (loader is visible). self.opacity = 1.0 - min((offset / 50.0), 1.0) } else {