|
|
|
@ -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"
|
|
|
|
@ -20,26 +20,37 @@ export interface VisualizerPageProps {
|
|
|
|
|
|
|
|
|
|
export function VisualizerPage({ guestMode }: VisualizerPageProps) {
|
|
|
|
|
const { tacticId: idStr } = useParams()
|
|
|
|
|
const navigate = useNavigate()
|
|
|
|
|
|
|
|
|
|
const fetcher = useAppFetcher()
|
|
|
|
|
if (guestMode || !idStr) {
|
|
|
|
|
return (
|
|
|
|
|
<ServedVisualizerPage service={LocalStorageTacticService.init()} />
|
|
|
|
|
<ServedVisualizerPage service={LocalStorageTacticService.init()}
|
|
|
|
|
openEditor={() => navigate("/tactic/edit-guest")} />
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<ServedVisualizerPage service={new APITacticService(fetcher, parseInt(idStr))} />
|
|
|
|
|
<ServedVisualizerPage service={new APITacticService(fetcher, 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() {
|
|
|
|
@ -63,6 +74,8 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setCanEdit(await service.canBeEdited())
|
|
|
|
|
|
|
|
|
|
dispatch({
|
|
|
|
|
type: VisualizerStateActionKind.INIT,
|
|
|
|
|
state: {
|
|
|
|
@ -98,10 +111,14 @@ function ServedVisualizerPage({ service }: { service: TacticService }) {
|
|
|
|
|
stepId: step,
|
|
|
|
|
})
|
|
|
|
|
},
|
|
|
|
|
async openEditor() {
|
|
|
|
|
openEditor()
|
|
|
|
|
},
|
|
|
|
|
}),
|
|
|
|
|
[service, state],
|
|
|
|
|
[openEditor, service, state],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (panicMessage) {
|
|
|
|
|
return <p>{panicMessage}</p>
|
|
|
|
|
}
|
|
|
|
@ -110,17 +127,19 @@ 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,
|
|
|
|
|
showEditButton,
|
|
|
|
|
}: VisualizerPageContentProps) {
|
|
|
|
|
const [isStepsTreeVisible, setStepsTreeVisible] = useState(false)
|
|
|
|
|
|
|
|
|
@ -152,13 +171,20 @@ function VisualizerPageContent({
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div id="visualizer">
|
|
|
|
|
<div id="topbar-div">
|
|
|
|
|
<div id="header-page">
|
|
|
|
|
<p id="title">{tacticName}</p>
|
|
|
|
|
<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">
|
|
|
|
|