|
|
@ -49,6 +49,7 @@ import { Action, ActionKind } from "../model/tactic/Action"
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
import BallAction from "../components/actions/BallAction"
|
|
|
|
import { changePlayerBallState, getOrigin, removePlayer } from "../editor/PlayerDomains"
|
|
|
|
import { changePlayerBallState, getOrigin, removePlayer } from "../editor/PlayerDomains"
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
import { CourtBall } from "../components/editor/CourtBall"
|
|
|
|
|
|
|
|
import { getSession } from "../api/session.ts"
|
|
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
borderColor: "red",
|
|
|
|
borderColor: "red",
|
|
|
@ -56,6 +57,7 @@ const ERROR_STYLE: CSSProperties = {
|
|
|
|
|
|
|
|
|
|
|
|
const GUEST_MODE_CONTENT_STORAGE_KEY = "guest_mode_content"
|
|
|
|
const GUEST_MODE_CONTENT_STORAGE_KEY = "guest_mode_content"
|
|
|
|
const GUEST_MODE_TITLE_STORAGE_KEY = "guest_mode_title"
|
|
|
|
const GUEST_MODE_TITLE_STORAGE_KEY = "guest_mode_title"
|
|
|
|
|
|
|
|
const DEFAULT_TACTIC_NAME = "Nouvelle tactique"
|
|
|
|
|
|
|
|
|
|
|
|
export interface EditorViewProps {
|
|
|
|
export interface EditorViewProps {
|
|
|
|
tactic: Tactic
|
|
|
|
tactic: Tactic
|
|
|
@ -70,12 +72,29 @@ export interface EditorPageProps {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export default function EditorPage({ courtType }: EditorPageProps) {
|
|
|
|
export default function EditorPage({ courtType }: EditorPageProps) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [id, setId] = useState<number>()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
async function initialize() {
|
|
|
|
|
|
|
|
const response = await fetchAPI("tactics", { name: DEFAULT_TACTIC_NAME }, "POST", getSession())
|
|
|
|
|
|
|
|
const { id } = await response.json()
|
|
|
|
|
|
|
|
setId(id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize()
|
|
|
|
|
|
|
|
}, [])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
return <Editor
|
|
|
|
return <Editor
|
|
|
|
id={-1}
|
|
|
|
id={id}
|
|
|
|
courtType={courtType}
|
|
|
|
courtType={courtType}
|
|
|
|
content={JSON.stringify({ components: [] })}
|
|
|
|
content={JSON.stringify({ components: [] })}
|
|
|
|
name={"Nouvelle Tactique"}
|
|
|
|
name={DEFAULT_TACTIC_NAME}
|
|
|
|
/>
|
|
|
|
/>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return <div>Loading Editor, please wait...</div>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
export interface EditorProps {
|
|
|
|
export interface EditorProps {
|
|
|
@ -111,7 +130,7 @@ function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
)
|
|
|
|
)
|
|
|
|
return SaveStates.Guest
|
|
|
|
return SaveStates.Guest
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fetchAPI(`tactic/${id}/save`, { content }).then((r) =>
|
|
|
|
return fetchAPI(`tactics/${id}/1`, { content }, "PUT", getSession()).then((r) =>
|
|
|
|
r.ok ? SaveStates.Ok : SaveStates.Err,
|
|
|
|
r.ok ? SaveStates.Ok : SaveStates.Err,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
}}
|
|
|
@ -120,7 +139,7 @@ function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
localStorage.setItem(GUEST_MODE_TITLE_STORAGE_KEY, name)
|
|
|
|
localStorage.setItem(GUEST_MODE_TITLE_STORAGE_KEY, name)
|
|
|
|
return true //simulate that the name has been changed
|
|
|
|
return true //simulate that the name has been changed
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return fetchAPI(`tactic/${id}/edit/name`, { name }).then(
|
|
|
|
return fetchAPI(`tactics/${id}/name`, { name }, "PUT", getSession()).then(
|
|
|
|
(r) => r.ok,
|
|
|
|
(r) => r.ok,
|
|
|
|
)
|
|
|
|
)
|
|
|
|
}}
|
|
|
|
}}
|
|
|
|