From d18a4b3c4299a9db9d7f89cec17f4fd02aa6b862 Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sat, 24 Sep 2022 11:31:52 -0400 Subject: [PATCH] Fixing loadInitial happening multiple times --- Tusker/TimelineLikeController.swift | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/Tusker/TimelineLikeController.swift b/Tusker/TimelineLikeController.swift index be89f61d..1bd558c2 100644 --- a/Tusker/TimelineLikeController.swift +++ b/Tusker/TimelineLikeController.swift @@ -29,7 +29,7 @@ actor TimelineLikeController { unowned var delegate: any TimelineLikeControllerDelegate - private(set) var state = State.idle { + private(set) var state = State.notLoadedInitial { willSet { precondition(state.canTransition(to: newValue)) logger.debug("State: \(self.state.debugDescription, privacy: .public) -> \(newValue.debugDescription, privacy: .public)") @@ -41,7 +41,7 @@ actor TimelineLikeController { } func loadInitial() async { - guard state == .idle else { + guard state == .notLoadedInitial else { return } let token = LoadAttemptToken() @@ -120,6 +120,7 @@ actor TimelineLikeController { } enum State: Equatable, CustomDebugStringConvertible { + case notLoadedInitial case idle case loadingInitial(LoadAttemptToken, hasAddedLoadingIndicator: Bool) case loadingNewer(LoadAttemptToken) @@ -128,6 +129,8 @@ actor TimelineLikeController { var debugDescription: String { switch self { + case .notLoadedInitial: + return "notLoadedInitial" case .idle: return "idle" case .loadingInitial(let token, let hasAddedLoadingIndicator): @@ -143,9 +146,16 @@ actor TimelineLikeController { func canTransition(to: State) -> Bool { switch self { + case .notLoadedInitial: + switch to { + case .loadingInitial(_, hasAddedLoadingIndicator: _): + return true + default: + return false + } case .idle: switch to { - case .loadingInitial(_, _), .loadingNewer(_)/*, .waitingForLoadOlderPermission*/, .loadingOlder(_, _): + case .loadingNewer(_)/*, .waitingForLoadOlderPermission*/, .loadingOlder(_, _): return true default: return false