Skip to content

Commit

Permalink
Fix community account switch behavior (#1443)
Browse files Browse the repository at this point in the history
  • Loading branch information
EricBAndrews authored Nov 19, 2024
1 parent a077367 commit fc41b12
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 52 deletions.
34 changes: 17 additions & 17 deletions Mlem.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,7 @@
CD332D792CA7175500A53988 /* PlayButton.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD332D782CA7175200A53988 /* PlayButton.swift */; };
CD332D7C2CA71E6F00A53988 /* GifView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD332D7B2CA71E6E00A53988 /* GifView.swift */; };
CD332D7E2CA7486000A53988 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD332D7D2CA7485D00A53988 /* String+Extensions.swift */; };
CD3E48262CEBA8D800102E72 /* MlemMiddleware in Frameworks */ = {isa = PBXBuildFile; productRef = CD3E48252CEBA8D800102E72 /* MlemMiddleware */; };
CD4368C12AE23FD400BD8BD1 /* Semaphore in Frameworks */ = {isa = PBXBuildFile; productRef = CD4368C02AE23FD400BD8BD1 /* Semaphore */; };
CD43E8B32BF2C24E007C3D71 /* ContentLoader.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD43E8B22BF2C24E007C3D71 /* ContentLoader.swift */; };
CD4BAD352B4B2C0B00A1E726 /* FeedsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4BAD342B4B2C0B00A1E726 /* FeedsView.swift */; };
Expand All @@ -326,7 +327,6 @@
CD4E386D2C836F8C009B24F2 /* UIUserInterfaceStyle+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4E386C2C836F8C009B24F2 /* UIUserInterfaceStyle+Extensions.swift */; };
CD4ED8472BF110FA00EFA0A2 /* TabReselectTracker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4ED8462BF110FA00EFA0A2 /* TabReselectTracker.swift */; };
CD4ED84A2BF1113800EFA0A2 /* View+TabReselectConsumer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD4ED8492BF1113800EFA0A2 /* View+TabReselectConsumer.swift */; };
CD555F822CE56CBE00E763E7 /* MlemMiddleware in Frameworks */ = {isa = PBXBuildFile; productRef = CD555F812CE56CBE00E763E7 /* MlemMiddleware */; };
CD5581DE2C7B8B820043FAC3 /* ImageFunctions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD5581DD2C7B8B820043FAC3 /* ImageFunctions.swift */; };
CD635E1B2C94DACD00864F75 /* BypassProxyWarningSheet.swift in Sources */ = {isa = PBXBuildFile; fileRef = CD635E1A2C94DACD00864F75 /* BypassProxyWarningSheet.swift */; };
CD64A91A2CA37E8D007CA7E6 /* Gifu in Frameworks */ = {isa = PBXBuildFile; productRef = CD64A9192CA37E8D007CA7E6 /* Gifu */; };
Expand Down Expand Up @@ -830,7 +830,7 @@
636250DC2A18111400FC59B4 /* KeychainAccess in Frameworks */,
CDE4AC452CA370E000981010 /* SDWebImageSwiftUI in Frameworks */,
CD4368C12AE23FD400BD8BD1 /* Semaphore in Frameworks */,
CD555F822CE56CBE00E763E7 /* MlemMiddleware in Frameworks */,
CD3E48262CEBA8D800102E72 /* MlemMiddleware in Frameworks */,
B104A6DE2A59BF3C00B3E725 /* NukeVideo in Frameworks */,
CDE4AC472CA372B600981010 /* SDWebImageWebPCoder in Frameworks */,
B104A6DC2A59BF3C00B3E725 /* NukeUI in Frameworks */,
Expand Down Expand Up @@ -1935,7 +1935,7 @@
CDE4AC442CA370E000981010 /* SDWebImageSwiftUI */,
CDE4AC462CA372B600981010 /* SDWebImageWebPCoder */,
CD64A9192CA37E8D007CA7E6 /* Gifu */,
CD555F812CE56CBE00E763E7 /* MlemMiddleware */,
CD3E48252CEBA8D800102E72 /* MlemMiddleware */,
);
productName = Mlem;
productReference = 6363D5C127EE196700E34822 /* Mlem.app */;
Expand Down Expand Up @@ -2023,7 +2023,7 @@
CDE4AC402CA3706400981010 /* XCRemoteSwiftPackageReference "SDWebImageSwiftUI" */,
CDE4AC412CA3706F00981010 /* XCRemoteSwiftPackageReference "SDWebImageWebPCoder" */,
CD64A9182CA37D63007CA7E6 /* XCRemoteSwiftPackageReference "Gifu" */,
CD555F802CE56CB200E763E7 /* XCRemoteSwiftPackageReference "MlemMiddleware" */,
CDFA5CAE2CEAB8AF00FDF998 /* XCRemoteSwiftPackageReference "MlemMiddleware" */,
);
productRefGroup = 6363D5C227EE196700E34822 /* Products */;
projectDirPath = "";
Expand Down Expand Up @@ -2899,14 +2899,6 @@
minimumVersion = 0.0.8;
};
};
CD555F802CE56CB200E763E7 /* XCRemoteSwiftPackageReference "MlemMiddleware" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.48.0;
};
};
CD64A9182CA37D63007CA7E6 /* XCRemoteSwiftPackageReference "Gifu" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/kaishin/Gifu";
Expand All @@ -2931,6 +2923,14 @@
minimumVersion = 0.14.6;
};
};
CDFA5CAE2CEAB8AF00FDF998 /* XCRemoteSwiftPackageReference "MlemMiddleware" */ = {
isa = XCRemoteSwiftPackageReference;
repositoryURL = "https://github.com/mlemgroup/MlemMiddleware";
requirement = {
kind = upToNextMajorVersion;
minimumVersion = 0.49.0;
};
};
/* End XCRemoteSwiftPackageReference section */

/* Begin XCSwiftPackageProductDependency section */
Expand Down Expand Up @@ -2979,16 +2979,16 @@
package = B104A6D62A59BF3C00B3E725 /* XCRemoteSwiftPackageReference "Nuke" */;
productName = NukeVideo;
};
CD3E48252CEBA8D800102E72 /* MlemMiddleware */ = {
isa = XCSwiftPackageProductDependency;
package = CDFA5CAE2CEAB8AF00FDF998 /* XCRemoteSwiftPackageReference "MlemMiddleware" */;
productName = MlemMiddleware;
};
CD4368C02AE23FD400BD8BD1 /* Semaphore */ = {
isa = XCSwiftPackageProductDependency;
package = CD4368BF2AE23FD400BD8BD1 /* XCRemoteSwiftPackageReference "Semaphore" */;
productName = Semaphore;
};
CD555F812CE56CBE00E763E7 /* MlemMiddleware */ = {
isa = XCSwiftPackageProductDependency;
package = CD555F802CE56CB200E763E7 /* XCRemoteSwiftPackageReference "MlemMiddleware" */;
productName = MlemMiddleware;
};
CD64A9192CA37E8D007CA7E6 /* Gifu */ = {
isa = XCSwiftPackageProductDependency;
package = CD64A9182CA37D63007CA7E6 /* XCRemoteSwiftPackageReference "Gifu" */;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/mlemgroup/MlemMiddleware",
"state" : {
"revision" : "d846b87dcbb9a797b4d38c91aa63de7625d06e80",
"version" : "0.48.0"
"revision" : "0d307c21af9b588ea5583a512b312443b8fca059",
"version" : "0.49.0"
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,20 @@ private struct OutdatedFeedPopupModifier: ViewModifier {
}
.onChange(of: onChangeHash) {
if let newApi = feedLoader.items.first?.api {
showRefreshPopup = newApi !== appState.firstApi && feedLoader.loadingState != .loading
showRefreshPopup = canShowPopup && (newApi !== appState.firstApi && feedLoader.loadingState != .loading)
} else {
showRefreshPopup = false
}
}
.overlay(alignment: .bottom) {
if canShowPopup {
RefreshPopupView("Feed is outdated", isPresented: $showRefreshPopup) {
Task {
do {
showRefreshPopup = false
try await refresh()
} catch {
handleError(error)
}
RefreshPopupView("Feed is outdated", isPresented: $showRefreshPopup) {
Task {
do {
showRefreshPopup = false
await feedLoader.changeApi(to: appState.firstApi)
try await refresh()
} catch {
handleError(error)
}
}
}
Expand All @@ -61,6 +60,7 @@ private struct OutdatedFeedPopupModifier: ViewModifier {

var onChangeHash: Int {
var hasher = Hasher()
hasher.combine(canShowPopup)
hasher.combine(appState.firstApi)
hasher.combine(feedLoader?.loadingState)
hasher.combine(feedLoader?.items.first?.api)
Expand Down
7 changes: 6 additions & 1 deletion Mlem/App/Views/Pages/Community/CommunityView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ struct CommunityView: View {
}

@ViewBuilder
// swiftlint:disable:next function_body_length
func content(community: any Community) -> some View {
FancyScrollView {
HStack {
Expand Down Expand Up @@ -106,7 +107,11 @@ struct CommunityView: View {
.environment(\.communityContext, community)
}
.background(palette.groupedBackground)
.outdatedFeedPopup(feedLoader: postFeedLoader, showPopup: selectedTab == .posts)
// don't show the refresh popup if community api isn't the active api, since that indicates an unresolvable community
.outdatedFeedPopup(
feedLoader: postFeedLoader,
showPopup: selectedTab == .posts && community.api === AppState.main.firstApi
)
.navigationTitle(isAtTop ? "" : community.name)
.isAtTopSubscriber(isAtTop: $isAtTop)
.toolbar {
Expand Down
27 changes: 5 additions & 22 deletions Mlem/App/Views/Root/Tabs/Feeds/FeedsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,32 +109,15 @@ struct FeedsView: View {
scrollToTopTrigger.toggle()
}
.onChange(of: appState.firstApi, initial: false) {
postFeedLoader?.changeApi(to: appState.firstApi)

if appState.firstApi.canInteract, let firstUser = appState.firstAccount as? UserAccount {
if let savedFeedLoader {
Task {
await savedFeedLoader.changeUser(api: appState.firstApi, userId: firstUser.id)
}
} else {
savedFeedLoader = .init(
api: appState.firstApi,
pageSize: internetSpeed.pageSize,
userId: firstUser.id,
sortType: .new,
savedOnly: true,
prefetchingConfiguration: .forPostSize(postSize)
)
}
} else {
savedFeedLoader = nil
}

// ensure we always are showing an appropriate feed
Task {
if !FeedSelection.cases(for: appState.firstAccount.accountType).contains(feedSelection) {
try await postFeedLoader?.changeSortType(to: appState.initialFeedSortType)
feedSelection = appState.firstAccount.accountType == .user ? .subscribed : .all
let newFeedSelection: FeedSelection = appState.firstAccount.accountType == .user ? .subscribed : .all
if newFeedSelection != feedSelection {
await postFeedLoader?.changeApi(to: appState.firstApi)
}
feedSelection = newFeedSelection
}
}
}
Expand Down

0 comments on commit fc41b12

Please sign in to comment.