Fix issue with not finishing followed by loader.

This commit is contained in:
Marcin Czachursk 2023-02-24 07:30:52 +01:00
parent bc55b1ad6b
commit 47a896913c
4 changed files with 25 additions and 20 deletions

View File

@ -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;

View File

@ -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:

View File

@ -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 {

View File

@ -26,6 +26,8 @@ struct HomeFeedView: View {
@FetchRequest var dbStatuses: FetchedResults<StatusData>
private let pullToRefreshViewHigh: CGFloat = 170
init(accountId: String) {
_dbStatuses = FetchRequest<StatusData>(
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 {