5
5
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
6
6
*/
7
7
8
- import { CurrentTreeNode } from 'components/graph/tree-node.type' ;
9
8
import { UUID } from 'crypto' ;
10
9
import { useCallback , useEffect , useMemo } from 'react' ;
11
10
import { useDispatch , useSelector } from 'react-redux' ;
@@ -22,6 +21,7 @@ const useStudyNavigationSync = () => {
22
21
const syncEnabled = useSelector ( ( state : AppState ) => state . syncEnabled ) ;
23
22
const currentRootNetworkUuid = useSelector ( ( state : AppState ) => state . currentRootNetworkUuid ) ;
24
23
const currentTreeNode = useSelector ( ( state : AppState ) => state . currentTreeNode ) ;
24
+ const treeModel = useSelector ( ( state : AppState ) => state . networkModificationTreeModel ) ;
25
25
const dispatch = useDispatch ( ) ;
26
26
27
27
const STORAGE_KEYS = useStudyScopedNavigationKeys ( ) ;
@@ -36,20 +36,23 @@ const useStudyNavigationSync = () => {
36
36
) ;
37
37
38
38
const updateTreeNode = useCallback (
39
- ( treeNode : CurrentTreeNode | null ) => {
40
- if ( treeNode !== null && JSON . stringify ( treeNode ) !== JSON . stringify ( currentTreeNode ) ) {
41
- dispatch ( setCurrentTreeNode ( treeNode ) ) ;
39
+ ( uuid : UUID | null ) => {
40
+ if ( uuid !== null && uuid !== currentTreeNode ?. id ) {
41
+ const currentNode = treeModel ?. treeNodes . find ( ( node ) => node . id === uuid ) ;
42
+ if ( currentNode ) {
43
+ dispatch ( setCurrentTreeNode ( { ...currentNode } ) ) ;
44
+ }
42
45
}
43
46
} ,
44
- [ dispatch , currentTreeNode ]
47
+ [ dispatch , currentTreeNode , treeModel ]
45
48
) ;
46
49
47
50
const keyActions = useMemo (
48
51
( ) => ( {
49
52
[ STORAGE_KEYS . ROOT_NETWORK_UUID ] : updateRootNetworkUuid ,
50
- [ STORAGE_KEYS . TREE_NODE ] : updateTreeNode ,
53
+ [ STORAGE_KEYS . TREE_NODE_UUID ] : updateTreeNode ,
51
54
} ) ,
52
- [ STORAGE_KEYS . ROOT_NETWORK_UUID , STORAGE_KEYS . TREE_NODE , updateRootNetworkUuid , updateTreeNode ]
55
+ [ STORAGE_KEYS . ROOT_NETWORK_UUID , STORAGE_KEYS . TREE_NODE_UUID , updateRootNetworkUuid , updateTreeNode ]
53
56
) ;
54
57
55
58
const syncFromLocalStorage = useCallback ( ( ) => {
0 commit comments