Route saving
This commit is contained in:
+10
-14
@@ -14,9 +14,6 @@ import {
|
||||
} from "@/lib/workspace";
|
||||
|
||||
export default function Workspace() {
|
||||
const [currentWorkspace, setCurrentWorkspace] = useState<string>();
|
||||
const [isInitialized, setIsInitialized] = useState(false);
|
||||
|
||||
const { workspace, loadWorkspace, updateEntity, setWorkspace } =
|
||||
useWorkspace();
|
||||
|
||||
@@ -26,9 +23,10 @@ export default function Workspace() {
|
||||
* Initialize workspace from cookie on mount
|
||||
*/
|
||||
useEffect(() => {
|
||||
const workspaceId = Cookies.get("workspace");
|
||||
setCurrentWorkspace(workspaceId);
|
||||
setIsInitialized(true);
|
||||
const routeString = Cookies.get("route");
|
||||
if (!routeString) return;
|
||||
const route = JSON.parse(routeString) as Route;
|
||||
setRoute(route);
|
||||
}, []);
|
||||
|
||||
/**
|
||||
@@ -41,16 +39,14 @@ export default function Workspace() {
|
||||
* for this case.
|
||||
*/
|
||||
useEffect(() => {
|
||||
if (!isInitialized) return;
|
||||
|
||||
loadWorkspace(currentWorkspace);
|
||||
if (currentWorkspace) {
|
||||
Cookies.set("workspace", currentWorkspace);
|
||||
loadWorkspace(route.workspace);
|
||||
if (route.workspace) {
|
||||
Cookies.set("route", JSON.stringify(route));
|
||||
} else {
|
||||
Cookies.remove("workspace");
|
||||
Cookies.remove("route");
|
||||
}
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [currentWorkspace, isInitialized]);
|
||||
}, [route]);
|
||||
|
||||
/**
|
||||
* Load route (entity) from localStorage when workspace loads
|
||||
@@ -103,7 +99,7 @@ export default function Workspace() {
|
||||
onClick={() => {
|
||||
const w = createDefaultWorkspace();
|
||||
saveWorkspaceToLocalStorage(w);
|
||||
setCurrentWorkspace(w.id);
|
||||
setRoute({ workspace: w.id });
|
||||
}}
|
||||
>
|
||||
<div className="text-center space-y-6">
|
||||
|
||||
Reference in New Issue
Block a user