@@ -2,9 +2,11 @@ import produce from "immer";
22import { Action , SelectNodeAction , SelectPageAction } from "core/actions" ;
33import { EditorState } from "core/states" ;
44import { useRouter } from "next/router" ;
5+ import { CanvasStateStore } from "@code-editor/canvas/stores" ;
56
67export function editorReducer ( state : EditorState , action : Action ) : EditorState {
78 const router = useRouter ( ) ;
9+ const filekey = state . design . key ;
810
911 // TODO: handle actions here.
1012 switch ( action . type ) {
@@ -18,7 +20,14 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
1820 router . push ( router ) ;
1921
2022 return produce ( state , ( draft ) => {
21- draft . selectedNodes = [ node ] . filter ( Boolean ) ;
23+ const _canvas_state_store = new CanvasStateStore (
24+ filekey ,
25+ state . selectedPage
26+ ) ;
27+
28+ const new_selections = [ node ] . filter ( Boolean ) ;
29+ _canvas_state_store . saveLastSelection ( ...new_selections ) ;
30+ draft . selectedNodes = new_selections ;
2231 } ) ;
2332 }
2433 case "select-page" : {
@@ -32,8 +41,16 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
3241 router . push ( router ) ;
3342
3443 return produce ( state , ( draft ) => {
44+ const _canvas_state_store = new CanvasStateStore ( filekey , page ) ;
45+
46+ const last_known_selections_of_this_page =
47+ _canvas_state_store . getLastSelection ( ) ?? [ ] ;
48+ console . log (
49+ "last_known_selections_of_this_page" ,
50+ last_known_selections_of_this_page
51+ ) ;
3552 draft . selectedPage = page ;
36- draft . selectedNodes = [ ] ;
53+ draft . selectedNodes = last_known_selections_of_this_page ;
3754 } ) ;
3855 }
3956 default :
0 commit comments