From 8a306aa93e359c746922e0130add0f7c99237608 Mon Sep 17 00:00:00 2001 From: Sjmarf <78750526+Sjmarf@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:29:33 +0100 Subject: [PATCH] Bug fix --- Mlem/Models/Trackers/RecentSearchesTracker.swift | 3 ++- Mlem/Views/Tabs/Search/RecentSearchesView.swift | 4 +--- Mlem/Views/Tabs/Search/SearchView.swift | 8 +++++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/Mlem/Models/Trackers/RecentSearchesTracker.swift b/Mlem/Models/Trackers/RecentSearchesTracker.swift index 9c5f21085..6f9bfddc7 100644 --- a/Mlem/Models/Trackers/RecentSearchesTracker.swift +++ b/Mlem/Models/Trackers/RecentSearchesTracker.swift @@ -20,6 +20,7 @@ class RecentSearchesTracker: ObservableObject { hasLoaded = true let identifiers = persistenceRepository.loadRecentSearches() for id in identifiers { + print(id.contentType, id.contentId) switch id.contentType { case .post: break @@ -27,7 +28,7 @@ class RecentSearchesTracker: ObservableObject { let response = try await apiClient.loadCommunityDetails(id: id.contentId) recentSearches.append(AnyContentModel(CommunityModel(from: response.communityView))) case .user: - let response = try await apiClient.getPersonDetails(for: id.contentId, limit: 0, savedOnly: false) + let response = try await apiClient.getPersonDetails(for: id.contentId, limit: 1, savedOnly: false) recentSearches.append(AnyContentModel(UserModel(from: response.personView)) ) } diff --git a/Mlem/Views/Tabs/Search/RecentSearchesView.swift b/Mlem/Views/Tabs/Search/RecentSearchesView.swift index 31d968757..09ae636d5 100644 --- a/Mlem/Views/Tabs/Search/RecentSearchesView.swift +++ b/Mlem/Views/Tabs/Search/RecentSearchesView.swift @@ -47,9 +47,7 @@ struct RecentSearchesView: View { Spacer() Button { - Task { - recentSearchesTracker.clearRecentSearches() - } + recentSearchesTracker.clearRecentSearches() } label: { Text("Clear") .font(.subheadline) diff --git a/Mlem/Views/Tabs/Search/SearchView.swift b/Mlem/Views/Tabs/Search/SearchView.swift index 69667d5bf..14f9d2105 100644 --- a/Mlem/Views/Tabs/Search/SearchView.swift +++ b/Mlem/Views/Tabs/Search/SearchView.swift @@ -20,6 +20,7 @@ private struct ViewOffsetKey: PreferenceKey { } struct SearchView: View { + @Dependency(\.errorHandler) var errorHandler enum Page { case home, recents, results @@ -55,7 +56,12 @@ struct SearchView: View { .onAppear { Task(priority: .background) { if !recentSearchesTracker.hasLoaded { - try await recentSearchesTracker.loadRecentSearches() + do { + try await recentSearchesTracker.loadRecentSearches() + } catch { + print("Error while loading recent searches: \(error.localizedDescription)") + errorHandler.handle(error) + } } } }