Restore React purity checks and streamline inline drafts
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
Some checks failed
Deploy Sokko G / deploy (push) Failing after 2s
This commit is contained in:
parent
2bff58f08c
commit
b9cc77a4d1
8 changed files with 111 additions and 10 deletions
|
|
@ -1,8 +1,9 @@
|
|||
// Rôle : gère l'onglet équipes équilibrées du Randomizer et ses exclusions.
|
||||
import { useEffect, useState } from "react";
|
||||
import { useState } from "react";
|
||||
import { CompactDropdown } from "../../../../components/CompactDropdown.jsx";
|
||||
import { Icon } from "../../../../components/Icon.jsx";
|
||||
import { useDraftForm } from "../../../../hooks/useDraftForm.js";
|
||||
import { useInlineEdit } from "../../../../hooks/useInlineEdit.js";
|
||||
import { RANDOMIZER_LIMITS, addRandomizerHistory, clampNumber, createBalancedTeams, filterExclusionsForPlayers } from "../randomizerUtils.js";
|
||||
import { RandomizerHistory } from "./RandomizerShared.jsx";
|
||||
import { DEFAULT_EXCLUSION_DRAFT, TEAM_REEL_DELAYS, hasReducedMotion, pickRandomItems } from "./randomizerUiUtils.js";
|
||||
|
|
@ -19,15 +20,11 @@ export function TeamsRandomizer({ data, textContent, onChange, context }) {
|
|||
const { queueTimer, clearTimers: clearTeamTimers } = useTimeoutQueue();
|
||||
const activePlayers = data.players.filter((player) => player.active);
|
||||
const storedSelectionCount = clampNumber(data.playerSelectionCount, data.teamCount, RANDOMIZER_LIMITS.teamPlayersMax, data.teamCount);
|
||||
const [selectionCountDraft, setSelectionCountDraft] = useState(String(storedSelectionCount));
|
||||
const { draft: selectionCountDraft, setDraft: setSelectionCountDraft } = useInlineEdit({ value: String(storedSelectionCount) });
|
||||
const selectionCount = clampNumber(selectionCountDraft, data.teamCount, RANDOMIZER_LIMITS.teamPlayersMax, storedSelectionCount);
|
||||
const displayedTeams = animating ? animationTeams : data.teams;
|
||||
const exclusionMode = exclusionDraft.values.mode === "source" ? "source" : "group";
|
||||
|
||||
useEffect(() => {
|
||||
setSelectionCountDraft(String(storedSelectionCount));
|
||||
}, [storedSelectionCount]);
|
||||
|
||||
function commitSelectionCount(value = selectionCountDraft) {
|
||||
const nextSelectionCount = clampNumber(value, data.teamCount, RANDOMIZER_LIMITS.teamPlayersMax, storedSelectionCount);
|
||||
setSelectionCountDraft(String(nextSelectionCount));
|
||||
|
|
|
|||
|
|
@ -22,6 +22,13 @@ export function useInlineEdit({
|
|||
const inputRef = useRef(null);
|
||||
const skipCommitRef = useRef(false);
|
||||
const [draft, setDraft] = useState(value);
|
||||
const [previousValue, setPreviousValue] = useState(value);
|
||||
|
||||
// Réinitialise avant le commit DOM, uniquement si la valeur source a changé.
|
||||
if (!Object.is(previousValue, value)) {
|
||||
setPreviousValue(value);
|
||||
setDraft(value);
|
||||
}
|
||||
|
||||
function syncContentEditable(nextValue, force = false) {
|
||||
if (inputRef.current?.isContentEditable && (force || document.activeElement !== inputRef.current)) {
|
||||
|
|
@ -30,7 +37,6 @@ export function useInlineEdit({
|
|||
}
|
||||
|
||||
useEffect(() => {
|
||||
setDraft(value);
|
||||
syncContentEditable(value);
|
||||
}, [value]);
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ function formatAlertMessage(template, toolbox, label) {
|
|||
export function useToolboxAlerts({ toolboxes, moduleData, links, route, drawerGameId, normalizeTimerData, normalizeCalendarData, textContent, notify }) {
|
||||
const previousTargetsRef = useRef(new Map());
|
||||
const resumedCalendarEventsRef = useRef(new Set());
|
||||
const lastTickRef = useRef(Date.now());
|
||||
const lastTickRef = useRef(null);
|
||||
|
||||
useEffect(() => {
|
||||
const visibleToolboxIds = getVisibleToolboxIds(route, drawerGameId, links);
|
||||
|
|
@ -38,7 +38,7 @@ export function useToolboxAlerts({ toolboxes, moduleData, links, route, drawerGa
|
|||
|
||||
function tick() {
|
||||
const nowMs = Date.now();
|
||||
const lastTickMs = lastTickRef.current;
|
||||
const lastTickMs = lastTickRef.current ?? nowMs;
|
||||
const nextTargets = new Map();
|
||||
|
||||
toolboxes.forEach((toolbox) => {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue