diff --git a/src/components/Visualizer.tsx b/src/components/Visualizer.tsx
index 2ae18ed..28b8dae 100644
--- a/src/components/Visualizer.tsx
+++ b/src/components/Visualizer.tsx
@@ -1,8 +1,23 @@
-import { ReactNode, useCallback, useEffect, useMemo, useRef, useState } from "react"
+import {
+ ReactNode,
+ useCallback,
+ useEffect,
+ useMemo,
+ useRef,
+ useState,
+} from "react"
import { APITacticService } from "../service/APITacticService.ts"
-import { CourtType, StepContent, StepInfoNode, TacticComponent } from "../model/tactic/Tactic.ts"
+import {
+ CourtType,
+ StepContent,
+ StepInfoNode,
+ TacticComponent,
+} from "../model/tactic/Tactic.ts"
import { getParent } from "../domains/StepsDomain.ts"
-import { computeRelativePositions, getPhantomInfo } from "../domains/PlayerDomains.ts"
+import {
+ computeRelativePositions,
+ getPhantomInfo,
+} from "../domains/PlayerDomains.ts"
import { PlayerInfo, PlayerLike } from "../model/tactic/Player.ts"
import { CourtPlayer } from "./editor/CourtPlayer.tsx"
import { BALL_TYPE } from "../model/tactic/CourtObjects.ts"
@@ -11,7 +26,6 @@ import { CourtAction } from "./editor/CourtAction.tsx"
import { BasketCourt, Court } from "./editor/BasketCourt.tsx"
import { TacticService } from "../service/MutableTacticService.ts"
-
export interface VisualizerProps {
tacticId: number
stepId?: number
@@ -33,13 +47,11 @@ export function Visualizer({ tacticId, stepId }: VisualizerProps) {
return
}
-
const rootStep = contextResult.stepsTree
setStepsTree(rootStep)
setCourtType(contextResult.courtType)
}
- if (isNotInit)
- init()
+ if (isNotInit) init()
}, [isNotInit, service])
if (panicMessage) {
@@ -49,12 +61,14 @@ export function Visualizer({ tacticId, stepId }: VisualizerProps) {
return
Loading...
}
- return
+ return (
+
+ )
}
export interface StepVisualizerProps {
@@ -64,7 +78,12 @@ export interface StepVisualizerProps {
service: TacticService
}
-export function StepVisualizer({stepId, stepsTree, courtType, service}: StepVisualizerProps) {
+export function StepVisualizer({
+ stepId,
+ stepsTree,
+ courtType,
+ service,
+}: StepVisualizerProps) {
const [panicMessage, setPanicMessage] = useState(null)
const [content, setContent] = useState(null)
const [parentContent, setParentContent] = useState()
@@ -73,7 +92,6 @@ export function StepVisualizer({stepId, stepsTree, courtType, service}: StepVisu
useEffect(() => {
async function init() {
-
const contentStepId = stepId ?? stepsTree.id
const contentResult = await service.getContent(contentStepId)
@@ -124,11 +142,10 @@ export interface VisualizerFrameProps {
}
export function VisualizerFrame({
- content,
- parentContent,
- courtType,
- }: VisualizerFrameProps) {
-
+ content,
+ parentContent,
+ courtType,
+}: VisualizerFrameProps) {
const courtRef = useRef(null)
const courtBounds = useCallback(
diff --git a/src/components/editor/BasketCourt.tsx b/src/components/editor/BasketCourt.tsx
index 7c69d6d..903767f 100644
--- a/src/components/editor/BasketCourt.tsx
+++ b/src/components/editor/BasketCourt.tsx
@@ -2,7 +2,11 @@ import { ReactElement, ReactNode, RefObject, useEffect, useState } from "react"
import { Action } from "../../model/tactic/Action"
import { CourtAction } from "./CourtAction"
-import { ComponentId, TacticComponent } from "../../model/tactic/Tactic"
+import {
+ ComponentId,
+ CourtType,
+ TacticComponent,
+} from "../../model/tactic/Tactic"
import PlainCourt from "../../assets/court/full_court.svg?react"
import HalfCourt from "../../assets/court/half_court.svg?react"
@@ -34,7 +38,6 @@ export function BasketCourt({
courtImage,
courtRef,
}: BasketCourtProps) {
-
const [court, setCourt] = useState(courtRef.current)
//force update once the court reference is set
@@ -49,15 +52,11 @@ export function BasketCourt({
style={{ position: "relative" }}>
{courtImage}
- {court &&
- parentComponents?.map((i) => renderComponent(i, true))}
- {court &&
- parentComponents?.flatMap((i) => renderActions(i, true))}
+ {court && parentComponents?.map((i) => renderComponent(i, true))}
+ {court && parentComponents?.flatMap((i) => renderActions(i, true))}
- {court &&
- components.map((i) => renderComponent(i, false))}
- {court &&
- components.flatMap((i) => renderActions(i, false))}
+ {court && components.map((i) => renderComponent(i, false))}
+ {court && components.flatMap((i) => renderActions(i, false))}
{previewAction && (
- {courtType == "PLAIN" ? (
-
- ) : (
-
- )}
+
)
}
diff --git a/src/components/editor/StepsTree.tsx b/src/components/editor/StepsTree.tsx
index ddb19ee..0029a5c 100644
--- a/src/components/editor/StepsTree.tsx
+++ b/src/components/editor/StepsTree.tsx
@@ -15,12 +15,12 @@ export interface StepsTreeProps {
}
export default function StepsTree({
- root,
- selectedStepId,
- onAddChildren,
- onRemoveNode,
- onStepSelected,
- }: StepsTreeProps) {
+ root,
+ selectedStepId,
+ onAddChildren,
+ onRemoveNode,
+ onStepSelected,
+}: StepsTreeProps) {
return (
(null)
return (
@@ -67,8 +67,7 @@ function StepsTreeNode({
next: "step-piece-" + child.id,
},
]}
- onSegmentsChanges={() => {
- }}
+ onSegmentsChanges={() => {}}
forceStraight={true}
wavy={false}
readOnly={true}
@@ -80,9 +79,8 @@ function StepsTreeNode({
onAddChildren(node)
- : undefined
+ onAddButtonClicked={
+ onAddChildren ? () => onAddChildren(node) : undefined
}
onRemoveButtonClicked={
rootNode.id === node.id || !onRemoveNode
@@ -126,13 +124,13 @@ interface StepPieceProps {
}
function StepPiece({
- id,
- isSelected,
- onAddButtonClicked,
- onRemoveButtonClicked,
- onSelected,
- children,
- }: StepPieceProps) {
+ id,
+ isSelected,
+ onAddButtonClicked,
+ onRemoveButtonClicked,
+ onSelected,
+ children,
+}: StepPieceProps) {
return (
-
+
navigate("/tactic/edit-guest")} />
+ navigate("/tactic/edit-guest")}
+ />
)
}
return (
- navigate(`/tactic/${idStr}/edit`)} />
+ navigate(`/tactic/${idStr}/edit`)}
+ />
)
}
@@ -45,9 +53,12 @@ interface ServedVisualizerPageProps {
openEditor: () => void
}
-function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps) {
+function ServedVisualizerPage({
+ service,
+ openEditor,
+}: ServedVisualizerPageProps) {
const [panicMessage, setPanicMessage] = useState()
- const [state, dispatch] = useReducer(visualizerStateReducer, null)
+ const [state, dispatch] = useVisualizer(null)
const [canEdit, setCanEdit] = useState(false)
useEffect(() => {
@@ -56,7 +67,7 @@ function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps
if (typeof contextResult === "string") {
setPanicMessage(
"There has been an error retrieving the editor initial context : " +
- contextResult,
+ contextResult,
)
return
}
@@ -67,7 +78,7 @@ function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps
if (typeof contentResult === "string") {
setPanicMessage(
"There has been an error retrieving the tactic's root step content : " +
- contentResult,
+ contentResult,
)
return
}
@@ -116,7 +127,6 @@ function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps
[openEditor, service, state],
)
-
if (panicMessage) {
return {panicMessage}
}
@@ -125,7 +135,13 @@ function ServedVisualizerPage({ service, openEditor }: ServedVisualizerPageProps
return Retrieving tactic context. Please wait...
}
- return
+ return (
+
+ )
}
interface VisualizerPageContentProps {
@@ -135,10 +151,10 @@ interface VisualizerPageContentProps {
}
function VisualizerPageContent({
- state: { content, parentContent, stepId, stepsTree, courtType, tacticName },
- service,
- showEditButton,
- }: VisualizerPageContentProps) {
+ state: { content, parentContent, stepId, stepsTree, courtType, tacticName },
+ service,
+ showEditButton,
+}: VisualizerPageContentProps) {
const [isStepsTreeVisible, setStepsTreeVisible] = useState(true)
const [editorContentCurtainWidth, setEditorContentCurtainWidth] =
@@ -177,12 +193,12 @@ function VisualizerPageContent({
onClick={() => setStepsTreeVisible((b) => !b)}>
ETAPES
- {showEditButton && }
+ {showEditButton && (
+
+ )}
-
diff --git a/src/service/LocalStorageTacticService.ts b/src/service/LocalStorageTacticService.ts
index 7e2b009..32b14c2 100644
--- a/src/service/LocalStorageTacticService.ts
+++ b/src/service/LocalStorageTacticService.ts
@@ -33,7 +33,7 @@ export class LocalStorageTacticService implements MutableTacticService {
)
localStorage.setItem(
GUEST_MODE_STEP_CONTENT_STORAGE_KEY + 1,
- JSON.stringify({components: []})
+ JSON.stringify({ components: [] }),
)
}
diff --git a/src/visualizer/VisualizerState.ts b/src/visualizer/VisualizerState.ts
index cea3fc2..6c80d20 100644
--- a/src/visualizer/VisualizerState.ts
+++ b/src/visualizer/VisualizerState.ts
@@ -1,4 +1,5 @@
import { CourtType, StepContent, StepInfoNode } from "../model/tactic/Tactic.ts"
+import { useReducer } from "react"
export interface VisualizerState {
stepId: number
@@ -9,7 +10,7 @@ export interface VisualizerState {
parentContent: StepContent | null
}
-export enum VisualizerStateActionKind {
+export const enum VisualizerStateActionKind {
INIT,
SET_CONTENTS,
}
@@ -26,7 +27,11 @@ export type VisualizerStateAction =
stepId: number
}
-export function visualizerStateReducer(
+export function useVisualizer(initialState: VisualizerState | null) {
+ return useReducer(visualizerStateReducer, initialState)
+}
+
+function visualizerStateReducer(
state: VisualizerState | null,
action: VisualizerStateAction,
): VisualizerState | null {