|
|
|
@ -1,5 +1,5 @@
|
|
|
|
|
import { ServiceError, TacticService } from "../service/MutableTacticService.ts"
|
|
|
|
|
import { useParams } from "react-router-dom"
|
|
|
|
|
import { useNavigate, useParams } from "react-router-dom"
|
|
|
|
|
import { useCallback, useEffect, useMemo, useReducer, useState } from "react"
|
|
|
|
|
import { VisualizerState, VisualizerStateActionKind, visualizerStateReducer } from "../visualizer/VisualizerState.ts"
|
|
|
|
|
import { getParent } from "../domains/StepsDomain.ts"
|
|
|
|
@ -19,25 +19,36 @@ export interface VisualizerPageProps {
|
|
|
|
|
|
|
|
|
|
export function VisualizerPage({ guestMode }: VisualizerPageProps) {
|
|
|
|
|
const { tacticId: idStr } = useParams()
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
if (guestMode || !idStr) {
|
|
|
|
|
return (
|
|
|
|
|
<ServedVisualizerPage service={LocalStorageTacticService.init()} />
|
|
|
|
|
<ServedVisualizerPage service={LocalStorageTacticService.init()}
|
|
|
|
|
openEditor={() => navigate("/tactic/edit-guest")} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ServedVisualizerPage service={new APITacticService(parseInt(idStr))} />
|
|
|
|
|
<ServedVisualizerPage service={new APITacticService(parseInt(idStr))}
|
|
|
|
|
openEditor={() => navigate(`/tactic/${idStr}/edit`)} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface VisualizerService {
|
|
|
|
|
selectStep(step: number): Promise<void | ServiceError>
|
|
|
|
|
|
|
|
|
|
openEditor(): Promise<void>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface ServedVisualizerPageProps {
|
|
|
|
|
service: TacticService
|
|
|
|
|
openEditor: () => void
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps) {
|
|
|
|
|
const [panicMessage, setPanicMessage] = useState<string>()
|
|
|
|
|
const [state, dispatch] = useReducer(visualizerStateReducer, null)
|
|
|
|
|
const [canEdit, setCanEdit] = useState(false)
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
async function init() {
|
|
|
|
@ -45,7 +56,7 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
if (typeof contextResult === "string") {
|
|
|
|
|
setPanicMessage(
|
|
|
|
|
"There has been an error retrieving the editor initial context : " +
|
|
|
|
|
contextResult,
|
|
|
|
|
contextResult,
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
@ -56,11 +67,13 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
if (typeof contentResult === "string") {
|
|
|
|
|
setPanicMessage(
|
|
|
|
|
"There has been an error retrieving the tactic's root step content : " +
|
|
|
|
|
contentResult,
|
|
|
|
|
contentResult,
|
|
|
|
|
)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCanEdit(await service.canBeEdited())
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: VisualizerStateActionKind.INIT,
|
|
|
|
|
state: {
|
|
|
|
@ -96,10 +109,14 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
stepId: step,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async openEditor() {
|
|
|
|
|
openEditor()
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
[service, state],
|
|
|
|
|
[openEditor, service, state],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (panicMessage) {
|
|
|
|
|
return <p>{panicMessage}</p>
|
|
|
|
|
}
|
|
|
|
@ -108,18 +125,20 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
return <p>Retrieving tactic context. Please wait...</p>
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <VisualizerPageContent state={state} service={visualizerService} />
|
|
|
|
|
return <VisualizerPageContent state={state} service={visualizerService} showEditButton={canEdit} />
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
interface VisualizerPageContentProps {
|
|
|
|
|
state: VisualizerState
|
|
|
|
|
service: VisualizerService
|
|
|
|
|
showEditButton: boolean
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function VisualizerPageContent({
|
|
|
|
|
state: { content, parentContent, stepId, stepsTree, courtType, tacticName },
|
|
|
|
|
service,
|
|
|
|
|
}: VisualizerPageContentProps) {
|
|
|
|
|
state: { content, parentContent, stepId, stepsTree, courtType, tacticName },
|
|
|
|
|
service,
|
|
|
|
|
showEditButton,
|
|
|
|
|
}: VisualizerPageContentProps) {
|
|
|
|
|
const [isStepsTreeVisible, setStepsTreeVisible] = useState(false)
|
|
|
|
|
|
|
|
|
|
const [editorContentCurtainWidth, setEditorContentCurtainWidth] =
|
|
|
|
@ -150,13 +169,20 @@ function VisualizerPageContent({
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div id="visualizer">
|
|
|
|
|
<div id="topbar-div">
|
|
|
|
|
<div id="header-page">
|
|
|
|
|
<p id="title">{tacticName}</p>
|
|
|
|
|
<button
|
|
|
|
|
id={"show-steps-button"}
|
|
|
|
|
onClick={() => setStepsTreeVisible((b) => !b)}>
|
|
|
|
|
ETAPES
|
|
|
|
|
</button>
|
|
|
|
|
<div id="header-page-right">
|
|
|
|
|
<button
|
|
|
|
|
id={"show-steps-button"}
|
|
|
|
|
onClick={() => setStepsTreeVisible((b) => !b)}>
|
|
|
|
|
ETAPES
|
|
|
|
|
</button>
|
|
|
|
|
{showEditButton && <button
|
|
|
|
|
onClick={() => service.openEditor()}>
|
|
|
|
|
EDITER
|
|
|
|
|
</button>}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div id="editor-div">
|
|
|
|
|