Skip to content

Commit

Permalink
Faster loading for own instance page
Browse files Browse the repository at this point in the history
  • Loading branch information
Sjmarf committed Jan 20, 2024
1 parent fa2f0f9 commit d416622
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Mlem/Models/Trackers/SiteInformationTracker.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class SiteInformationTracker: ObservableObject {
@Dependency(\.errorHandler) var errorHandler
@Dependency(\.accountsTracker) var accountsTracker

@Published private(set) var instance: InstanceModel?
@Published private(set) var enableDownvotes = true
@Published var version: SiteVersion?
@Published private(set) var allLanguages: [APILanguage] = .init()
Expand All @@ -23,8 +24,8 @@ class SiteInformationTracker: ObservableObject {
version = account.siteVersion
Task {
do {

let response = try await apiClient.loadSiteInformation()
instance = .init(from: response)
enableDownvotes = response.siteView.localSite.enableDownvotes
version = SiteVersion(response.version)
if version != account.siteVersion {
Expand Down
5 changes: 5 additions & 0 deletions Mlem/Views/Shared/Instance/InstanceView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ enum InstanceViewTab: String, Identifiable, CaseIterable {
struct InstanceView: View {
@Dependency(\.apiClient) var apiClient: APIClient
@Dependency(\.errorHandler) var errorHandler
@Dependency(\.siteInformation) var siteInformation

@Environment(\.navigationPathWithRoutes) private var navigationPath
@Environment(\.scrollViewProxy) private var scrollViewProxy
Expand All @@ -42,6 +43,10 @@ struct InstanceView: View {

init(domainName: String, instance: InstanceModel? = nil) {
_domainName = State(wrappedValue: domainName)
var instance = instance
if domainName == siteInformation.instance?.url.host() {
instance = siteInformation.instance ?? instance
}
_instance = State(wrappedValue: instance)
}

Expand Down

0 comments on commit d416622

Please sign in to comment.