|
|
@ -50,6 +50,7 @@ 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 { useParams } from "react-router-dom"
|
|
|
|
import { useParams } from "react-router-dom"
|
|
|
|
|
|
|
|
import { DEFAULT_TACTIC_NAME } from "./NewTacticPage.tsx"
|
|
|
|
|
|
|
|
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
const ERROR_STYLE: CSSProperties = {
|
|
|
|
borderColor: "red",
|
|
|
|
borderColor: "red",
|
|
|
@ -57,31 +58,12 @@ 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
|
|
|
|
onContentChange: (tactic: TacticContent) => Promise<SaveState>
|
|
|
|
onContentChange: (tactic: TacticContent) => Promise<SaveState>
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
onNameChange: (name: string) => Promise<boolean>
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
type EditorCreateNewAction = { type: "new", courtType: CourtType }
|
|
|
|
|
|
|
|
type EditorOpenAction = { type: "open" }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
type EditorAction = EditorCreateNewAction | EditorOpenAction
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export interface EditorPageProps {
|
|
|
|
|
|
|
|
action: EditorAction
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
export default function EditorPage({ action }: EditorPageProps) {
|
|
|
|
|
|
|
|
console.log(action)
|
|
|
|
|
|
|
|
if (action.type === "new") {
|
|
|
|
|
|
|
|
return <EditorCreateNew {...action} />
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return <EditorOpen />
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface TacticDto {
|
|
|
|
interface TacticDto {
|
|
|
|
id: number
|
|
|
|
id: number
|
|
|
|
name: string
|
|
|
|
name: string
|
|
|
@ -89,14 +71,22 @@ interface TacticDto {
|
|
|
|
content: string
|
|
|
|
content: string
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interface EditorPageProps {
|
|
|
|
|
|
|
|
guestMode: boolean
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function EditorOpen() {
|
|
|
|
export default function EditorPage({ guestMode }: EditorPageProps) {
|
|
|
|
const { tacticId: idStr } = useParams()
|
|
|
|
|
|
|
|
const id = parseInt(idStr!)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const [tactic, setTactic] = useState<TacticDto>()
|
|
|
|
const [tactic, setTactic] = useState<TacticDto>()
|
|
|
|
|
|
|
|
const { tacticId: idStr } = useParams()
|
|
|
|
|
|
|
|
const id = guestMode ? -1 : parseInt(idStr!)
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (guestMode) {
|
|
|
|
|
|
|
|
setTactic({id: -1, courtType: "PLAIN", content: "{\"components\": []}", name: DEFAULT_TACTIC_NAME})
|
|
|
|
|
|
|
|
return
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function initialize() {
|
|
|
|
async function initialize() {
|
|
|
|
console.log("initializing")
|
|
|
|
console.log("initializing")
|
|
|
|
const infoResponse = fetchAPIGet(`tactics/${id}`)
|
|
|
|
const infoResponse = fetchAPIGet(`tactics/${id}`)
|
|
|
@ -109,7 +99,7 @@ function EditorOpen() {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
initialize()
|
|
|
|
initialize()
|
|
|
|
}, [id])
|
|
|
|
}, [guestMode, id, idStr])
|
|
|
|
|
|
|
|
|
|
|
|
if (tactic) {
|
|
|
|
if (tactic) {
|
|
|
|
return <Editor
|
|
|
|
return <Editor
|
|
|
@ -123,33 +113,6 @@ function EditorOpen() {
|
|
|
|
return <EditorLoadingScreen />
|
|
|
|
return <EditorLoadingScreen />
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function EditorCreateNew({ courtType }: EditorCreateNewAction) {
|
|
|
|
|
|
|
|
const [id, setId] = useState<number>()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
|
|
async function initialize() {
|
|
|
|
|
|
|
|
const response = await fetchAPI("tactics", {
|
|
|
|
|
|
|
|
name: DEFAULT_TACTIC_NAME,
|
|
|
|
|
|
|
|
courtType
|
|
|
|
|
|
|
|
}, "POST")
|
|
|
|
|
|
|
|
const { id } = await response.json()
|
|
|
|
|
|
|
|
setId(id)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
initialize()
|
|
|
|
|
|
|
|
}, [courtType])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (id) {
|
|
|
|
|
|
|
|
return <Editor
|
|
|
|
|
|
|
|
id={id}
|
|
|
|
|
|
|
|
courtType={courtType}
|
|
|
|
|
|
|
|
content={JSON.stringify({ components: [] })}
|
|
|
|
|
|
|
|
name={DEFAULT_TACTIC_NAME}
|
|
|
|
|
|
|
|
/>
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return <EditorLoadingScreen />
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function EditorLoadingScreen() {
|
|
|
|
function EditorLoadingScreen() {
|
|
|
|
return <div>Loading Editor, please wait...</div>
|
|
|
|
return <div>Loading Editor, please wait...</div>
|
|
|
@ -165,13 +128,13 @@ export interface EditorProps {
|
|
|
|
function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
function Editor({ id, name, courtType, content }: EditorProps) {
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
const isInGuestMode = id == -1
|
|
|
|
|
|
|
|
|
|
|
|
const storage_content = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
const storageContent = localStorage.getItem(GUEST_MODE_CONTENT_STORAGE_KEY)
|
|
|
|
const editorContent =
|
|
|
|
const editorContent =
|
|
|
|
isInGuestMode && storage_content != null ? storage_content : content
|
|
|
|
isInGuestMode && storageContent != null ? storageContent : content
|
|
|
|
|
|
|
|
|
|
|
|
const storage_name = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
|
const storageName = localStorage.getItem(GUEST_MODE_TITLE_STORAGE_KEY)
|
|
|
|
const editorName =
|
|
|
|
const editorName =
|
|
|
|
isInGuestMode && storage_name != null ? storage_name : name
|
|
|
|
isInGuestMode && storageName != null ? storageName : name
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
return (
|
|
|
|
<EditorView
|
|
|
|
<EditorView
|
|
|
|