Skip to content

Commit 7756589

Browse files
update hash routing (dirty fix)
1 parent 9084fca commit 7756589

1 file changed

Lines changed: 31 additions & 1 deletion

File tree

editor-packages/editor-dashboard/scaffold/editor-dashboard-hierarchy.tsx

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@ import React, { useCallback } from "react";
22
import { TreeView } from "@editor-ui/editor";
33
import { useDashboard } from "../core/provider";
44
import { HierarchyRow, IconContainer, LayerIcon } from "../components";
5+
import { NextRouter, useRouter } from "next/router";
56
import type { DashboardItem } from "../core/state";
67

78
export function DashboardHierarchy() {
9+
const router = useRouter();
810
const { hierarchy, selectNode, selection } = useDashboard();
911
const { sections } = hierarchy;
1012

@@ -16,18 +18,26 @@ export function DashboardHierarchy() {
1618
(item: DashboardItem, i: number) => {
1719
const selected = selection.includes(item.id);
1820
const depth = item.path.split("/").length - 1;
21+
1922
return (
2023
<HierarchyRow
2124
key={item.path} // todo: update - this needs to be a unique path
2225
selected={selected}
2326
depth={depth}
2427
name={item.name}
2528
onPress={() => {
29+
if (item.$type === "folder") {
30+
// this is dirty workaround for awaiting the router to update first from the editor-reducer caused by the select node action.
31+
setTimeout(() => {
32+
pushhash(router, item.path);
33+
}, 10);
34+
}
35+
2636
selectNode(item.id);
2737
}}
2838
icon={
2939
<IconContainer>
30-
<LayerIcon type={item.type as any} selected={selected} />
40+
<LayerIcon type={item.$type as any} selected={selected} />
3141
</IconContainer>
3242
}
3343
onMenuClick={() => {
@@ -47,3 +57,23 @@ export function DashboardHierarchy() {
4757
/>
4858
);
4959
}
60+
61+
function pushhash(router: NextRouter, hash: string) {
62+
router
63+
.push(
64+
{
65+
// add anchor to url
66+
hash: hash,
67+
},
68+
null,
69+
{
70+
shallow: true,
71+
}
72+
)
73+
.catch((e) => {
74+
// workaround for https://github.com/vercel/next.js/issues/37362
75+
if (!e.cancelled) {
76+
throw e;
77+
}
78+
});
79+
}

0 commit comments

Comments
 (0)