Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ios-3565 Space hub | Fix deeplink race #2233

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@ struct SpaceHubCoordinatorView: View {
}
.onChange(of: model.navigationPath) { _ in model.onPathChange() }

.task { await model.startHandleWorkspaceInfo() }
.task { await model.setup() }
.task { await model.startHandleAppActions() }

.handleSpaceShareTip()
.handleSharingTip()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class SpaceHubCoordinatorViewModel: ObservableObject {
}

@Published var pathChanging: Bool = false
@Published var navigationPath = HomePath(initalPath: [SpaceHubNavigationItem()])
@Published var navigationPath = HomePath(initialPath: [SpaceHubNavigationItem()])
var pageNavigation: PageNavigation {
PageNavigation(
push: { [weak self] data in
Expand Down Expand Up @@ -117,22 +117,30 @@ final class SpaceHubCoordinatorViewModel: ObservableObject {
await spaceSetupManager.registerSpaceSetter(sceneId: sceneId, setter: activeSpaceManager)
await setupInitialScreen()
await handleVersionAlerts()

await startSubscriptions()
}

private func startSubscriptions() async {
async let subscription1: () = startHandleWorkspaceInfo()
async let subscription2: () = startHandleAppActions()
(_,_) = await (subscription1, subscription2)
}

func setupInitialScreen() async {
guard !loginStateService.isFirstLaunchAfterRegistration else { return }

switch userDefaults.lastOpenedScreen {
case .editor(let editorData):
openObject(screenData: editorData)
try? await push(data: editorData)
case .widgets(let spaceId):
try? await spaceSetupManager.setActiveSpace(sceneId: sceneId, spaceId: spaceId)
try? await openSpace(spaceId: spaceId)
case .none:
return
}
}

func startHandleAppActions() async {
private func startHandleAppActions() async {
for await action in appActionsStorage.$action.values {
if let action {
try? await handleAppAction(action: action)
Expand Down Expand Up @@ -197,6 +205,10 @@ final class SpaceHubCoordinatorViewModel: ObservableObject {
}

let spaceId = data.spaceId
try await openSpace(spaceId: spaceId, data: data)
}

private func openSpace(spaceId: String, data: EditorScreenData? = nil) async throws {
if currentSpaceId != spaceId {
// Check if space is deleted
guard workspaceStorage.spaceView(spaceId: spaceId).isNotNil else { return }
Expand All @@ -206,10 +218,12 @@ final class SpaceHubCoordinatorViewModel: ObservableObject {
currentSpaceId = spaceId

if let spaceInfo {
navigationPath = HomePath(initalPath: [SpaceHubNavigationItem(), spaceInfo, data])
var initialPath: [AnyHashable] = [SpaceHubNavigationItem(), spaceInfo]
if let data { initialPath.append(data) }
navigationPath = HomePath(initialPath: initialPath)
}
} else {
navigationPath.push(data)
data.flatMap { navigationPath.push($0) }
}
}

Expand All @@ -223,7 +237,7 @@ final class SpaceHubCoordinatorViewModel: ObservableObject {
}

if let info {
let newPath = HomePath(initalPath: [SpaceHubNavigationItem(), info])
let newPath = HomePath(initialPath: [SpaceHubNavigationItem(), info])
navigationPath = newPath
if #available(iOS 17.0, *) {
updateSpaceSwitchTip(spaceId: info.accountSpaceId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ struct HomePath: Equatable {
didSet { didChangePath(newPath: path, oldPath: oldValue) }
}

init(initalPath: [AnyHashable] = []) {
path = initalPath
init(initialPath: [AnyHashable] = []) {
path = initialPath
}

var count: Int {
Expand Down
Loading