Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Sep 29, 2023
1 parent a9b8af2 commit 8a306aa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Mlem/Models/Trackers/RecentSearchesTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ class RecentSearchesTracker: ObservableObject {
hasLoaded = true
let identifiers = persistenceRepository.loadRecentSearches()
for id in identifiers {
print(id.contentType, id.contentId)
switch id.contentType {
case .post:
break
case .community:
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))
)
}
Expand Down
4 changes: 1 addition & 3 deletions Mlem/Views/Tabs/Search/RecentSearchesView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ struct RecentSearchesView: View {
Spacer()

Button {
Task {
recentSearchesTracker.clearRecentSearches()
}
recentSearchesTracker.clearRecentSearches()
} label: {
Text("Clear")
.font(.subheadline)
Expand Down
8 changes: 7 additions & 1 deletion Mlem/Views/Tabs/Search/SearchView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ private struct ViewOffsetKey: PreferenceKey {
}

struct SearchView: View {
@Dependency(\.errorHandler) var errorHandler

enum Page {
case home, recents, results
Expand Down Expand Up @@ -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)
}
}
}
}
Expand Down

0 comments on commit 8a306aa

Please sign in to comment.