diff --git a/Core/CommonViewsKit/Sources/CommonViewsKit/NavigationStore.swift b/Core/CommonViewsKit/Sources/CommonViewsKit/NavigationStore.swift index fed4319b18..eb0df63b9b 100644 --- a/Core/CommonViewsKit/Sources/CommonViewsKit/NavigationStore.swift +++ b/Core/CommonViewsKit/Sources/CommonViewsKit/NavigationStore.swift @@ -33,4 +33,14 @@ public final class NavigationStore { path = path.dropLast() } } + + public func popToRoot(animated: Bool = true) { + if animated { + withAnimation { + path.removeAll() + } + } else { + path.removeAll() + } + } } diff --git a/MockingStar/MockingStar/Modules/Home/SidebarView.swift b/MockingStar/MockingStar/Modules/Home/SidebarView.swift index c57cd904f8..df66a053b3 100644 --- a/MockingStar/MockingStar/Modules/Home/SidebarView.swift +++ b/MockingStar/MockingStar/Modules/Home/SidebarView.swift @@ -14,6 +14,7 @@ import TipKit struct SidebarView: View { @Environment(MockDomainDiscover.self) private var domainDiscover: MockDomainDiscover @SceneStorage("mockDomain") private var mockDomain: String = "" + private let navigationStore = NavigationStore.shared private let logger = Logger(category: "SidebarView") var body: some View { @@ -64,6 +65,10 @@ struct SidebarView: View { .onReceive(NotificationCenter.default.publisher(for: .reloadMockDomains)) { _ in Task { try await reloadMockDomains() } } + .task(id: mockDomain) { + try? await Task.sleep(for: .milliseconds(100)) + navigationStore.popToRoot() + } } @MainActor