|
1 | 1 | "use client"; |
2 | 2 |
|
3 | 3 | import dynamic from "next/dynamic"; |
4 | | -import { useEffect, useState } from "react"; |
5 | | -import { LifecycleNavigation, type LifecycleKey } from "@/components/LifecycleNavigation"; |
| 4 | +import { useCallback, useEffect, useState } from "react"; |
| 5 | +import { LifecycleNavigation, isLaneKey, type LifecycleKey } from "@/components/LifecycleNavigation"; |
6 | 6 | import { WorkspaceHeader } from "@/components/WorkspaceHeader"; |
7 | 7 | import { ResearchLaunch } from "@/components/ResearchLaunch"; |
8 | 8 | import { FounderContact } from "@/components/FounderContact"; |
@@ -121,9 +121,28 @@ const LibraryNavigator = dynamic( |
121 | 121 | { loading: RouteSkeleton, ssr: false }, |
122 | 122 | ); |
123 | 123 |
|
124 | | -export default function WorkspaceApp() { |
| 124 | +export default function WorkspaceApp({ initialLane }: { initialLane?: string }) { |
125 | 125 | const { project, setProject, update, ready, autosave } = useProject(); |
126 | | - const [active, setActive] = useState<LifecycleKey>("launch"); |
| 126 | + const [active, setActiveInternal] = useState<LifecycleKey>( |
| 127 | + isLaneKey(initialLane) ? initialLane : "launch", |
| 128 | + ); |
| 129 | + |
| 130 | + /** Lane change = shallow URL update, so every lane has a real, shareable URL. */ |
| 131 | + const setActive = useCallback((k: LifecycleKey) => { |
| 132 | + setActiveInternal(k); |
| 133 | + if (typeof window !== "undefined" && window.location.pathname !== `/w/${k}`) { |
| 134 | + window.history.pushState(null, "", `/w/${k}`); |
| 135 | + } |
| 136 | + }, []); |
| 137 | + |
| 138 | + useEffect(() => { |
| 139 | + const onPop = () => { |
| 140 | + const m = window.location.pathname.match(/^\/w\/([\w-]+)/); |
| 141 | + setActiveInternal(m && isLaneKey(m[1]) ? (m[1] as LifecycleKey) : "launch"); |
| 142 | + }; |
| 143 | + window.addEventListener("popstate", onPop); |
| 144 | + return () => window.removeEventListener("popstate", onPop); |
| 145 | + }, []); |
127 | 146 |
|
128 | 147 | useEffect(() => { |
129 | 148 | if (!ready) return; |
|
0 commit comments