@@ -2,9 +2,11 @@ import React, { useCallback } from "react";
22import { TreeView } from "@editor-ui/editor" ;
33import { useDashboard } from "../core/provider" ;
44import { HierarchyRow , IconContainer , LayerIcon } from "../components" ;
5+ import { NextRouter , useRouter } from "next/router" ;
56import type { DashboardItem } from "../core/state" ;
67
78export 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