diff --git a/src/main/webapp/src/pages/competition/editor/CategoryAdminContent.jsx b/src/main/webapp/src/pages/competition/editor/CategoryAdminContent.jsx index fe30a92..951ad1c 100644 --- a/src/main/webapp/src/pages/competition/editor/CategoryAdminContent.jsx +++ b/src/main/webapp/src/pages/competition/editor/CategoryAdminContent.jsx @@ -48,9 +48,9 @@ export function CategoryContent({cat, catId, setCat}) { combDispatch({type: 'SET_ALL', payload: {source: "match", data: [data.c1, data.c2].filter(d => d != null)}}); if (data.c1 !== null && !groupsRef.current.some(g => g.id === data.c1?.id)) - setGroups(prev => [...prev, {id: data.c1?.id, poule: data.poule}]) + setGroups(prev => [...prev, {id: data.c1?.id, poule: data.poule}]); if (data.c2 !== null && !groupsRef.current.some(g => g.id === data.c2?.id)) - setGroups(prev => [...prev, {id: data.c2?.id, poule: data.poule}]) + setGroups(prev => [...prev, {id: data.c2?.id, poule: data.poule}]); } dispatch({type: 'addListener', payload: {callback: treeListener, code: 'sendTreeCategory'}}) @@ -92,10 +92,22 @@ export function CategoryContent({cat, catId, setCat}) { }).finally(() => setLoading(0)) }, [catId]); + const removeGroup = (combId) => { + if (matches.some(d => d.c1 === combId || d.c2 === combId)) { + setGroups(prev => prev.map(g => { + if (g.id === combId) + return {...g, poule: "-"} + return g; + })) + } else { + setGroups(prev => prev.filter(g => g.id !== combId)) + } + } + return <>
- +
{cat && } @@ -103,10 +115,11 @@ export function CategoryContent({cat, catId, setCat}) { } -function AddComb({groups, setGroups}) { +function AddComb({groups, setGroups, removeGroup}) { const {data, setData} = useRequestWS("getRegister", null) - const combDispatch = useCombsDispatch(); - const {dispatch} = useWS(); + const combDispatch = useCombsDispatch() + const {dispatch} = useWS() + const [modalId, setModalId] = useState(null) useEffect(() => { const sendRegister = ({data}) => { @@ -139,14 +152,7 @@ function AddComb({groups, setGroups}) { }, [data]); return <> -
    - {groups.map((comb) => ( -
  1. -
    - {comb.poule} -
  2. ) - )} -
+ @@ -158,9 +164,108 @@ function AddComb({groups, setGroups}) {
+ +
+
+
+ +
+
+
} +function GroupsList({groups, setModalId}) { + const {getComb} = useCombs(); + + const groups2 = groups.map(g => { + const comb = getComb(g.id); + return {...g, name: comb ? comb.fname + " " + comb.lname : ""}; + }).sort((a, b) => { + if (a.poule !== b.poule) + return a.poule.localeCompare(b.poule); + return a.name.localeCompare(b.name); + }).reduce((acc, curr) => { + const poule = curr.poule; + if (!acc[poule]) { + acc[poule] = []; + } + acc[poule].push(curr); + return acc; + }, {}); + + return <> + {Object.keys(groups2).map((poule) => ( +
+
{poule !== '-' ? "Poule: " + poule : "Sans poule"}
+
    + {groups2[poule].map((comb) => ( +
  1. setModalId(comb.id)}> +
    + {comb.poule} +
  2. ) + )} +
+
+ ))} + +} + +function GroupModalContent({combId, groups, setGroups, removeGroup}) { + const inputRef = useRef(null); + const [pouleInput, setPouleInput] = useState(groups.find(g => g.id === combId)?.poule || "") + + useEffect(() => { + setPouleInput(groups.find(g => g.id === combId)?.poule || "") + }, [combId]); + + const handleClick = () => { + if (pouleInput.trim().length !== 1 || pouleInput === "-") + return; + + setGroups(prev => prev.map(g => { + if (g.id === combId) + return {...g, poule: pouleInput} + return g; + })) + // close modal + const modal = document.getElementById("groupeModal"); + const modalInstance = window.bootstrap.Modal.getInstance(modal); + modalInstance.hide(); + } + + if (inputRef.current) { + setTimeout(() => { + inputRef.current.focus() + inputRef.current.select() + }, 500); + } + + return <> +
+
Poule pour:
+ +
+
+ setPouleInput(e.target.value)} + onKeyDown={event => { + if (event.key === 'Enter') + handleClick(); + }}/> +
+
+ + + +
+ + +} + function ListMatch({cat, matches, groups}) { const [type, setType] = useState(1); diff --git a/src/main/webapp/src/pages/competition/editor/SelectCombModalContent.jsx b/src/main/webapp/src/pages/competition/editor/SelectCombModalContent.jsx index b9f7738..e81ffc1 100644 --- a/src/main/webapp/src/pages/competition/editor/SelectCombModalContent.jsx +++ b/src/main/webapp/src/pages/competition/editor/SelectCombModalContent.jsx @@ -277,7 +277,10 @@ export function SelectCombModalContent({data, setGroups}) {
setTargetGroupe(e.target.value)}/> + onChange={(e) => { + if (/^[a-zA-Z0-9]$/.test(e.target.value)) + setTargetGroupe(e.target.value) + }}/>