|
|
|
@ -164,17 +164,14 @@ function GuestModeEditor() {
|
|
|
|
|
setStepContent({ ...JSON.parse(localStorage.getItem(GUEST_MODE_STEP_CONTENT_STORAGE_KEY + step)!) }, false)
|
|
|
|
|
return
|
|
|
|
|
}, [setStepContent])}
|
|
|
|
|
onAddStep={useCallback(async parent => {
|
|
|
|
|
onAddStep={useCallback(async (parent, content) => {
|
|
|
|
|
const root: StepInfoNode = JSON.parse(localStorage.getItem(GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY)!)
|
|
|
|
|
|
|
|
|
|
const nodeId = getAvailableId(root)
|
|
|
|
|
const node = { id: nodeId, children: [] }
|
|
|
|
|
|
|
|
|
|
localStorage.setItem(GUEST_MODE_STEP_ROOT_NODE_INFO_STORAGE_KEY, JSON.stringify(addStepNode(root, parent, node)))
|
|
|
|
|
localStorage.setItem(GUEST_MODE_STEP_CONTENT_STORAGE_KEY + node.id, JSON.stringify({
|
|
|
|
|
stepId: node.id,
|
|
|
|
|
components: [],
|
|
|
|
|
}))
|
|
|
|
|
localStorage.setItem(GUEST_MODE_STEP_CONTENT_STORAGE_KEY + node.id, JSON.stringify(content))
|
|
|
|
|
return node
|
|
|
|
|
}, [])}
|
|
|
|
|
onRemoveStep={useCallback(async step => {
|
|
|
|
@ -240,7 +237,7 @@ function UserModeEditor() {
|
|
|
|
|
}, 250), [id, stepId]),
|
|
|
|
|
)
|
|
|
|
|
const onNameChange = useCallback((name: string) =>
|
|
|
|
|
fetchAPI(`tactics/${id}/edit/name`, { name })
|
|
|
|
|
fetchAPI(`tactics/${id}/name`, { name }, "PUT")
|
|
|
|
|
.then((r) => r.ok)
|
|
|
|
|
, [id])
|
|
|
|
|
|
|
|
|
@ -252,9 +249,10 @@ function UserModeEditor() {
|
|
|
|
|
setStepContent({ ...await response.json() }, false)
|
|
|
|
|
}, [id, setStepContent])
|
|
|
|
|
|
|
|
|
|
const onAddStep = useCallback(async (parent: StepInfoNode) => {
|
|
|
|
|
const onAddStep = useCallback(async (parent: StepInfoNode, content: StepContent) => {
|
|
|
|
|
const response = await fetchAPI(`tactics/${id}/steps`, {
|
|
|
|
|
parentId: parent.id,
|
|
|
|
|
content
|
|
|
|
|
})
|
|
|
|
|
if (!response.ok)
|
|
|
|
|
return null
|
|
|
|
@ -306,7 +304,7 @@ export interface EditorViewProps {
|
|
|
|
|
selectStep: (stepId: number) => void
|
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
|
onRemoveStep: (step: StepInfoNode) => Promise<boolean>
|
|
|
|
|
onAddStep: (parent: StepInfoNode) => Promise<StepInfoNode | null>
|
|
|
|
|
onAddStep: (parent: StepInfoNode, content: StepContent) => Promise<StepInfoNode | null>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -698,7 +696,7 @@ function EditorPage({
|
|
|
|
|
root={rootStepsNode}
|
|
|
|
|
onAddChildren={useCallback(
|
|
|
|
|
async (parent) => {
|
|
|
|
|
const addedNode = await onAddStep(parent)
|
|
|
|
|
const addedNode = await onAddStep(parent, content)
|
|
|
|
|
if (addedNode == null) {
|
|
|
|
|
console.error(
|
|
|
|
|
"could not add step : onAddStep returned null node",
|
|
|
|
@ -709,7 +707,7 @@ function EditorPage({
|
|
|
|
|
addStepNode(root, parent, addedNode),
|
|
|
|
|
)
|
|
|
|
|
},
|
|
|
|
|
[onAddStep],
|
|
|
|
|
[content, onAddStep],
|
|
|
|
|
)}
|
|
|
|
|
onRemoveNode={useCallback(
|
|
|
|
|
async (removed) => {
|
|
|
|
|