Skip to content

Commit 202d3a3

Browse files
committed
adding model creation and cleanup
1 parent 794cfa1 commit 202d3a3

File tree

3 files changed

+48
-15
lines changed

3 files changed

+48
-15
lines changed

web-server/plugins/slycat-cca/js/components/CCAWizard.tsx

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,35 +5,69 @@ import * as React from "react";
55
import { CCAModalContent } from "./CCAWizardContent";
66
import { CCAWizardSteps } from "./CCAWizardSteps";
77
import { useCCAWizardFooter } from "./CCAWizardUtils";
8-
import { useAppDispatch } from "./wizard-store/hooks";
9-
import { resetCCAWizard, setPid } from "./wizard-store/reducers/cCAWizardSlice";
8+
import { useAppDispatch, useAppSelector } from "./wizard-store/hooks";
9+
import {
10+
resetCCAWizard,
11+
selectMid,
12+
selectPid,
13+
setMid,
14+
setPid,
15+
} from "./wizard-store/reducers/cCAWizardSlice";
16+
import client from "js/slycat-web-client";
1017

1118
interface CCAWizardParams {
1219
pid: string;
20+
marking?: string;
1321
}
1422

1523
export const CCAWizard = (params: CCAWizardParams) => {
16-
const { pid } = params;
24+
const { pid, marking } = params;
25+
const [modalOpen, setModalOpen] = React.useState(true);
1726
const cCAWizardFooter = useCCAWizardFooter();
1827
const dispatch = useAppDispatch();
28+
const statePid = useAppSelector(selectPid);
29+
const stateMid = useAppSelector(selectMid);
1930

2031
React.useEffect(() => {
21-
dispatch(setPid(pid));
22-
}, [dispatch, pid])
23-
32+
console.log("statePid, pid, selectMid", statePid, pid, stateMid);
33+
if (modalOpen) {
34+
if (!statePid) {
35+
dispatch(setPid(pid));
36+
}
37+
if (!stateMid && statePid) {
38+
// create the model on open so we have something to reference later
39+
client
40+
.post_project_models_fetch({
41+
pid: statePid,
42+
type: "cca",
43+
name: "",
44+
description: "",
45+
marking: marking ?? "",
46+
})
47+
.then((result) => {
48+
dispatch(setMid(result.id));
49+
});
50+
}
51+
}
52+
}, [dispatch, pid, statePid, stateMid]);
53+
2454
return (
2555
<CCAModalContent
2656
key={"slycat-wizard"}
2757
// slycat-wizard is the standard wizard id from knockout
2858
modalId={"slycat-wizard"}
29-
closingCallBack={() => {
30-
console.log("clean and delete model");
59+
closingCallBack={React.useCallback(() => {
60+
setModalOpen(false);
61+
if (stateMid) {
62+
console.log("delete");
63+
client.delete_model_fetch({ mid: stateMid });
64+
}
3165
dispatch(resetCCAWizard());
32-
}}
66+
}, [stateMid])}
3367
title={"New CCA Model"}
3468
footer={cCAWizardFooter}
3569
>
3670
<CCAWizardSteps key={"CCA Steps"} />
3771
</CCAModalContent>
3872
);
39-
};
73+
};

web-server/plugins/slycat-cca/js/components/wizard-store/reducers/cCAWizardSlice.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,5 +57,7 @@ export const {
5757
// Other code such as selectors can use the imported `RootState` type
5858
export const selectTab = (state: RootState) => state.cCAWizard.tab;
5959
export const selectDataLocation = (state: RootState) => state.cCAWizard.dataLocation;
60+
export const selectPid = (state: RootState) => state.cCAWizard.pid;
61+
export const selectMid = (state: RootState) => state.cCAWizard.mid;
6062

6163
export default cCAWizardSlice.reducer;

web-server/plugins/slycat-cca/js/wizard-ui.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@ import { CCAWizard } from ".//components/CCAWizard.tsx";
88
import ccaWizardUI from "../wizard-ui.html";
99
import { Provider } from 'react-redux'
1010
import { cCAWizardStore } from ".//components/wizard-store/store";
11+
import markings from "js/slycat-selectable-markings";
1112

1213
function constructor(params) {
13-
console.log(params.projects()[0]?._id());
1414
const react_wizard_root = createRoot(document.querySelector(".react-wizard"));
1515
react_wizard_root.render(
1616
<Provider store={cCAWizardStore}>
17-
<CCAWizard pid={params.projects()[0]?._id()}/>
17+
<CCAWizard pid={params.projects()[0]?._id()} marking={markings.preselected()}/>
1818
</Provider>
1919
);
20-
21-
// return an empty component since we are just using it to render react
22-
return {};
2320
}
2421

2522
export default {

0 commit comments

Comments
 (0)