dev #104

Merged
Thibaut merged 3 commits from dev into master 2026-01-18 15:19:13 +00:00
2 changed files with 32 additions and 6 deletions
Showing only changes of commit eed7a10cfb - Show all commits

View File

@ -231,7 +231,7 @@ function AddComb({groups, setGroups, removeGroup, menuActions}) {
<div className="modal fade" id="selectCombModal" tabIndex="-1" aria-labelledby="selectCombModalLabel" aria-hidden="true"> <div className="modal fade" id="selectCombModal" tabIndex="-1" aria-labelledby="selectCombModalLabel" aria-hidden="true">
<div className="modal-dialog modal-dialog-scrollable modal-lg modal-fullscreen-lg-down"> <div className="modal-dialog modal-dialog-scrollable modal-lg modal-fullscreen-lg-down">
<div className="modal-content"> <div className="modal-content">
<SelectCombModalContent data={data} setGroups={setGroups} teamMode={modalMode}/> <SelectCombModalContent data={data} setGroups={setGroups} teamMode={modalMode} groups={groups}/>
</div> </div>
</div> </div>
</div> </div>

View File

@ -1,5 +1,5 @@
import {useCountries} from "../../../hooks/useCountries.jsx"; import {useCountries} from "../../../hooks/useCountries.jsx";
import {useEffect, useReducer, useState} from "react"; import {useEffect, useReducer, useRef, useState} from "react";
import {CatList, getCatName, getToastMessage} from "../../../utils/Tools.js"; import {CatList, getCatName, getToastMessage} from "../../../utils/Tools.js";
import {CombName} from "../../../hooks/useComb.jsx"; import {CombName} from "../../../hooks/useComb.jsx";
import {useWS} from "../../../hooks/useWS.jsx"; import {useWS} from "../../../hooks/useWS.jsx";
@ -21,6 +21,11 @@ function SelectReducer(state, action) {
return acc; return acc;
}, {}) }, {})
}; };
case 'ADD_ID':
return {
...state,
[action.payload]: false
};
case 'CLEAR_ACTIVE': case 'CLEAR_ACTIVE':
const newState = {...state}; const newState = {...state};
Object.keys(newState).forEach(id => { Object.keys(newState).forEach(id => {
@ -54,12 +59,13 @@ function SelectReducer(state, action) {
} }
} }
export function SelectCombModalContent({data, setGroups, teamMode = false}) { export function SelectCombModalContent({data, groups, setGroups, teamMode = false}) {
const country = useCountries('fr') const country = useCountries('fr')
const {t} = useTranslation("cm"); const {t} = useTranslation("cm");
const {sendRequest, dispatch} = useWS() const {sendRequest, dispatch} = useWS()
const [dispo, dispoReducer] = useReducer(SelectReducer, {}) const [dispo, dispoReducer] = useReducer(SelectReducer, {})
const [select, selectReducer] = useReducer(SelectReducer, {}) const [select, selectReducer] = useReducer(SelectReducer, {})
const lastClick = useRef({time: 0, id: null});
const [targetGroupe, setTargetGroupe] = useState("1") const [targetGroupe, setTargetGroupe] = useState("1")
const [search, setSearch] = useState("") const [search, setSearch] = useState("")
@ -286,8 +292,19 @@ export function SelectCombModalContent({data, setGroups, teamMode = false}) {
<div className="list-group overflow-y-auto" style={{maxHeight: "50vh"}}> <div className="list-group overflow-y-auto" style={{maxHeight: "50vh"}}>
{dispoFiltered && Object.keys(dispoFiltered).length === 0 && <div>{t('select.aucunCombattantDisponible')}</div>} {dispoFiltered && Object.keys(dispoFiltered).length === 0 && <div>{t('select.aucunCombattantDisponible')}</div>}
{Object.keys(dispoFiltered).sort((a, b) => nameCompare(data, a, b)).map((id) => ( {Object.keys(dispoFiltered).sort((a, b) => nameCompare(data, a, b)).map((id) => (
<button key={id} type="button" className={"list-group-item list-group-item-action " + (dispoFiltered[id] ? "active" : "")} <button key={id} type="button"
onClick={() => dispoReducer({type: 'TOGGLE_ID', payload: id})}> className={"list-group-item list-group-item-action " + (dispoFiltered[id] ? "active" : "") + " " +
(groups.find(g => g.id === Number(id) && g.poule !== '-') ? "list-group-item-secondary" : "")}
onClick={() => {
if (lastClick.current.id === id && (Date.now() - lastClick.current.time) < 500) {
// Double click detected
selectReducer({type: 'ADD_ID', payload: id})
dispoReducer({type: 'REMOVE_ID', payload: id})
} else {
dispoReducer({type: 'TOGGLE_ID', payload: id})
}
lastClick.current = {time: Date.now(), id: id};
}}>
<CombName combId={id}/> <CombName combId={id}/>
</button>))} </button>))}
</div> </div>
@ -307,7 +324,16 @@ export function SelectCombModalContent({data, setGroups, teamMode = false}) {
{Object.keys(selectFiltered).sort((a, b) => nameCompare(data, a, b)).map((id) => ( {Object.keys(selectFiltered).sort((a, b) => nameCompare(data, a, b)).map((id) => (
<button key={id} type="button" <button key={id} type="button"
className={"list-group-item list-group-item-action " + (selectFiltered[id] ? "active" : "")} className={"list-group-item list-group-item-action " + (selectFiltered[id] ? "active" : "")}
onClick={() => selectReducer({type: 'TOGGLE_ID', payload: id})}> onClick={() => {
if (lastClick.current.id === id && (Date.now() - lastClick.current.time) < 500) {
// Double click detected
dispoReducer({type: 'ADD_ID', payload: id})
selectReducer({type: 'REMOVE_ID', payload: id})
} else {
selectReducer({type: 'TOGGLE_ID', payload: id})
}
lastClick.current = {time: Date.now(), id: id};
}}>
<CombName combId={id}/> <CombName combId={id}/>
</button>))} </button>))}
</div> </div>