diff --git a/Mlem/API/Models/Site/APIMyUserInfo.swift b/Mlem/API/Models/Site/APIMyUserInfo.swift index 163c5ba5e..a6cd7e6da 100644 --- a/Mlem/API/Models/Site/APIMyUserInfo.swift +++ b/Mlem/API/Models/Site/APIMyUserInfo.swift @@ -13,3 +13,9 @@ struct APIMyUserInfo: Decodable { var localUserView: APILocalUserView var discussionLanguages: [Int] } + +extension APIMyUserInfo: Equatable { + static func == (lhs: APIMyUserInfo, rhs: APIMyUserInfo) -> Bool { + lhs.localUserView.person.id == rhs.localUserView.person.id + } +} diff --git a/Mlem/Models/Trackers/SiteInformationTracker.swift b/Mlem/Models/Trackers/SiteInformationTracker.swift index 0fd58be25..04024e052 100644 --- a/Mlem/Models/Trackers/SiteInformationTracker.swift +++ b/Mlem/Models/Trackers/SiteInformationTracker.swift @@ -23,7 +23,6 @@ class SiteInformationTracker: ObservableObject { version = account.siteVersion Task { do { - let response = try await apiClient.loadSiteInformation() enableDownvotes = response.siteView.localSite.enableDownvotes version = SiteVersion(response.version) @@ -35,6 +34,7 @@ class SiteInformationTracker: ObservableObject { } myUserInfo = response.myUser allLanguages = response.allLanguages + print("DEBUG version loaded") } catch { errorHandler.handle(error) } diff --git a/Mlem/Views/Tabs/Feeds/Feed Types/SavedFeedView.swift b/Mlem/Views/Tabs/Feeds/Feed Types/SavedFeedView.swift index 89f60022b..83d2aa742 100644 --- a/Mlem/Views/Tabs/Feeds/Feed Types/SavedFeedView.swift +++ b/Mlem/Views/Tabs/Feeds/Feed Types/SavedFeedView.swift @@ -5,13 +5,45 @@ // Created by Eric Andrews on 2024-01-21. // +import Dependencies import Foundation import SwiftUI struct SavedFeedView: View { - // TODO: ERIC this needs its own tracker type + // TODO: ERIC this whole view needs its own PR--needs its own tracker to handle loading user content, needs a different type of feed to handle mixed posts and comments, and needs a good way of determining the current user ID + + @Dependency(\.siteInformation) var siteInformation + @Dependency(\.errorHandler) var errorHandler + + // ugly little hack to deal with the fact that dependencies don't propagate state changes nicely but we need to listen for siteInformation.myUserInfo to resolve + @State var siteInformationLoaded: Bool + + init() { + @Dependency(\.siteInformation) var siteInformation + + _siteInformationLoaded = .init(wrappedValue: siteInformation.myUserInfo != nil) + } var body: some View { - AggregateFeedView(feedType: .saved) + // note to reviewers: this is super ugly but exists just to get the app in a stable running state pending the aforementioned PR to make this view nice + if !siteInformationLoaded { + LoadingView(whatIsLoading: .posts) + .task { + for _ in 0 ..< 5 { + if siteInformation.myUserInfo != nil { + siteInformationLoaded = true + break + } + + do { + try await Task.sleep(nanoseconds: 1_000_000_000) + } catch { + errorHandler.handle(error) + } + } + } + } else { + AggregateFeedView(feedType: .saved) + } } }