Skip to content

Commit 1c4c2be

Browse files
add preview reducers
1 parent 4ec6d32 commit 1c4c2be

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

editor/core/reducers/editor-reducer.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import type {
66
CodeEditorEditComponentCodeAction,
77
CanvasModeSwitchAction,
88
CanvasModeGobackAction,
9+
PreviewBuildingStateUpdateAction,
10+
PreviewSetAction,
911
} from "core/actions";
1012
import { EditorState } from "core/states";
1113
import { useRouter } from "next/router";
@@ -116,9 +118,35 @@ export function editorReducer(state: EditorState, action: Action): EditorState {
116118
draft.canvasMode = dest; // previous or fallback
117119
});
118120
}
121+
case "preview-update-building-state": {
122+
const { isBuilding } = <PreviewBuildingStateUpdateAction>action;
123+
return produce(state, (draft) => {
124+
if (draft.currentPreview) {
125+
draft.currentPreview.isBuilding = isBuilding;
126+
} else {
127+
draft.currentPreview = {
128+
loader: null,
129+
viewtype: "unknown",
130+
isBuilding: true,
131+
widgetKey: null,
132+
componentName: null,
133+
fallbackSource: "loading",
134+
initialSize: null,
135+
meta: null,
136+
source: null,
137+
updatedAt: Date.now(),
138+
};
139+
}
140+
});
141+
}
142+
case "preview-set": {
143+
const { data } = <PreviewSetAction>action;
144+
return produce(state, (draft) => {
145+
draft.currentPreview = data; // set
146+
});
147+
}
119148
default:
120149
throw new Error(`Unhandled action type: ${action["type"]}`);
121150
}
122-
123151
return state;
124152
}

0 commit comments

Comments
 (0)