sokko-g/website/src/features/toolboxes/ToolboxPages.jsx
Shinuwa f423fa30fa
All checks were successful
Validate and deploy Sokko G / validate (push) Successful in 20m39s
Validate and deploy Sokko G / deploy (push) Successful in 12s
Use the share icon and space the share dialog footer
- Show the new share icon on the toolbox card and drawer send buttons.
- Separate the single-use option from the dialog buttons.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-11 17:11:14 +01:00

554 lines
26 KiB
JavaScript

// Rôle : affiche les pages toolbox, le panneau latéral et leurs contrôles.
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { GuidedTooltipTour } from "../../components/GuidedTooltipTour.jsx";
import { Icon } from "../../components/Icon.jsx";
import { ImportButton } from "../../components/ImportButton.jsx";
import { ToolboxManagementModal } from "../../components/ToolboxModals.jsx";
import { useGuideChecklist } from "../games/useGuideChecklist.js";
import { StorageQuota } from "../../components/StorageQuota.jsx";
import { useGroupedReorder } from "../../hooks/useGroupedReorder.js";
import { useInlineEdit } from "../../hooks/useInlineEdit.js";
import { compressImage } from "../../utils/imageCompression.js";
import { getGameCardCover, ToolboxCard, ToolboxGameIcon, ToolboxIconPicker } from "./ToolboxCard.jsx";
import { AddToolControls, ToolboxModules } from "./modules/index.jsx";
import { getMemosDataAfterPlannerRemoval } from "./modules/memosPlannerUtils.js";
import { ToolboxSpaces } from "./ToolboxSpaces.jsx";
import {
addModuleToToolboxSpace,
decodeSpaceColumn,
encodeSpaceColumn,
getActiveToolboxSpace,
getModuleSpace,
moveToolboxModule,
removeModuleFromToolboxSpaces
} from "./toolboxSpaceUtils.js";
import {
clampQty,
hostnameFromUrl,
normalizeCalculatorData,
normalizeCalendarData,
normalizeChecklistData,
normalizeCombosData,
normalizeCountersData,
normalizeEquipmentPlannerData,
normalizeGoalTreeData,
normalizeImageAnnotationData,
normalizeLinksData,
normalizeMemosData,
normalizeNotepadData,
normalizeRandomizerData,
normalizeRngSimulatorData,
normalizeTableData,
normalizeTaskPlannerData,
normalizeTimerData,
summarizeEquipmentPlannerData,
normalizeUrl,
uid
} from "./storage/toolboxStorage.js";
const DRAWER_INITIAL_WIDTH = 700;
function getDrawerMaxWidth() {
return Math.max(DRAWER_INITIAL_WIDTH, Math.floor(window.innerWidth * 0.94));
}
async function copyText(value) {
try {
await navigator.clipboard.writeText(value);
return true;
} catch {
return false;
}
}
export function ToolboxesPage({ siteContent, toolboxes, getToolboxGame, actions, storageUsage, toastPosition, setToastPosition }) {
const content = siteContent.toolboxes;
const [managementOpen, setManagementOpen] = useState(false);
const {
itemReorder,
getItemProps,
isItemDragging,
isItemDropTarget,
getDropPlacement
} = useGroupedReorder({
namespace: "toolbox-cards",
items: toolboxes,
getItemId: (toolbox) => toolbox.id,
orientation: "horizontal",
getPlacement: (event, target) => {
const rect = target.getBoundingClientRect();
return event.clientY > rect.top + rect.height / 2 || event.clientX > rect.left + rect.width / 2 ? "after" : "before";
},
onItemMove: (operation) => {
const nextIds = toolboxes.map((toolbox) => toolbox.id).filter((id) => id !== operation.sourceId);
const targetIndex = nextIds.indexOf(operation.targetId);
nextIds.splice(operation.placement === "after" ? targetIndex + 1 : targetIndex, 0, operation.sourceId);
actions.updateToolboxOrder(nextIds);
}
});
return (
<div className="toolbox-page">
<section className="page-hero nds-page-hero primary-list-hero toolbox-list-hero">
<div>
<p className="eyebrow">{content.eyebrow}</p>
<h1>{content.title}</h1>
<p>{content.summary}</p>
<div className="actions nds-toolbar toolbox-list-primary-actions" aria-label={content.primaryActionsLabel}>
<button className="nds-button" data-size="sm" data-variant="primary" aria-label={content.newButton} onClick={() => actions.setCreateModal({})}><Icon name="add" />{content.createShortButton}</button>
<ImportButton className="nds-button" data-size="sm" label={content.importOne} icon="import" onFile={actions.importToolbox} />
</div>
</div>
</section>
<section className="toolbox-list-actions nds-toolbar" aria-label={content.collectionActionsLabel}>
<button className="nds-button" data-size="sm" type="button" onClick={() => setManagementOpen(true)}><Icon name="settings" />{content.manageButton}</button>
<a className="library-link-button nds-button" data-size="sm" href="#/library" aria-label={content.libraryLink} title={content.libraryLink}><Icon name="book" /><span className="toolbox-list-action-label">{content.libraryLink}</span></a>
</section>
<section className="toolbox-collection" aria-labelledby="toolbox-collection-title">
<header className="toolbox-collection-heading">
<div>
<p className="eyebrow">{content.collectionEyebrow}</p>
<div className="toolbox-collection-title-row">
<h2 id="toolbox-collection-title">{content.collectionTitle}</h2>
<span className="nds-badge" data-variant="neutral">{toolboxes.length}</span>
</div>
</div>
</header>
<div className="cards">
{toolboxes.length ? toolboxes.map((toolbox) => (
<ToolboxCard
key={toolbox.id}
toolbox={toolbox}
game={getToolboxGame(toolbox)}
actions={actions}
reorder={{ itemReorder, getItemProps, isItemDragging, isItemDropTarget, getDropPlacement }}
/>
)) : (
<div className="empty nds-empty-state toolbox-list-empty">
<h2>{content.emptyTitle}</h2>
<p>{content.emptyText}</p>
<button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => actions.setCreateModal({})}>{content.emptyAction}</button>
</div>
)}
</div>
</section>
<StorageQuota usage={storageUsage} />
{managementOpen && <ToolboxManagementModal
content={content}
toastPosition={toastPosition}
setToastPosition={setToastPosition}
actions={actions}
onClose={() => setManagementOpen(false)}
/>}
</div>
);
}
export function ToolboxPage(props) {
const { toolboxId, toolboxes, getToolboxGame } = props;
const toolbox = toolboxes.find((item) => item.id === toolboxId);
if (!toolbox) return <div className="empty nds-empty-state"><h1>Toolbox introuvable</h1><a className="nds-button" data-size="sm" href="#/toolboxes">Retour</a></div>;
return <ToolboxView {...props} toolbox={toolbox} toolboxGame={getToolboxGame(toolbox)} embedded={false} />;
}
function shouldShowTutorial(toolbox, pendingTutorialToolboxId) {
return toolbox?.tutorial === true || pendingTutorialToolboxId === toolbox?.id;
}
function ToolboxView({ siteContent, toolbox, toolboxGame, embedded, actions, storageUsage, storageReady = true, getModuleData, updateToolbox, updateModuleData, addImageFiles, pendingTutorialToolboxId = "", setPendingTutorialToolboxId, guideChecklist }) {
const toolboxId = toolbox.id;
const moduleColumns = embedded || Number(toolbox.moduleColumns) === 1 ? 1 : 2;
const activeSpace = getActiveToolboxSpace(toolbox);
const spacesText = siteContent.toolboxes.spaces;
const toolboxGameCover = getGameCardCover(toolboxGame);
const moduleText = siteContent.toolboxes.modules;
const [showTutorial, setShowTutorial] = useState(() => shouldShowTutorial(toolbox, pendingTutorialToolboxId));
const [pendingModuleId, setPendingModuleId] = useState("");
const dragOriginSpaceRef = useRef("");
const dragSucceededRef = useRef(false);
const hoverActivatedRef = useRef(false);
const previousDraggingIdRef = useRef("");
const tutorialRequested = shouldShowTutorial(toolbox, pendingTutorialToolboxId);
const [previousTutorial, setPreviousTutorial] = useState({ toolboxId, requested: tutorialRequested });
// Consommer la demande de lancement ne doit pas interrompre la visite en cours.
if (previousTutorial.toolboxId !== toolboxId || previousTutorial.requested !== tutorialRequested) {
setPreviousTutorial({ toolboxId, requested: tutorialRequested });
if (previousTutorial.toolboxId !== toolboxId || tutorialRequested) setShowTutorial(tutorialRequested);
}
const moduleContext = {
guideChecklist,
getModuleData,
ensureModuleData: actions.ensureModuleData,
isModuleDataReady: actions.isModuleDataReady,
storageStatus: siteContent.toolboxes.storageStatus,
storageReady,
toolboxModules: toolbox.modules,
moduleText,
moduleConfigurationText: siteContent.toolboxes.moduleConfiguration,
normalizeChecklistData,
normalizeCombosData,
normalizeLinksData,
normalizeMemosData,
normalizeCountersData,
normalizeEquipmentPlannerData,
normalizeGoalTreeData,
normalizeCalculatorData,
normalizeCalendarData,
normalizeImageAnnotationData,
normalizeNotepadData,
normalizeRandomizerData,
normalizeRngSimulatorData,
normalizeTableData,
normalizeTimerData,
normalizeTaskPlannerData,
summarizeEquipmentPlannerData,
normalizeUrl,
hostnameFromUrl,
copyText,
notify: actions.notify,
compressImageFile: compressImage,
clampQty,
uid,
setModuleData: updateModuleData,
addImageFiles,
createImageAnnotationModule,
setImage: actions.setImage,
refresh: () => {}
};
const moduleLocations = useMemo(() => {
const locations = new Map();
toolbox.spaces.forEach((space) => {
space.moduleOrder.one.forEach((moduleId) => {
const column = space.moduleOrder.two[1].includes(moduleId) ? "right" : "left";
locations.set(moduleId, { spaceId: space.id, column });
});
});
return locations;
}, [toolbox.spaces]);
const rawModuleReorder = useGroupedReorder({
namespace: `toolbox-modules-${toolbox.id}`,
items: toolbox.modules,
getItemId: (module) => module.id,
getItemGroup: (module) => {
const location = moduleLocations.get(module.id);
return encodeSpaceColumn(location?.spaceId || toolbox.defaultSpaceId, moduleColumns === 1 ? "one" : location?.column || "left");
},
getEffectiveGroup: (module) => {
const location = moduleLocations.get(module.id);
return encodeSpaceColumn(location?.spaceId || toolbox.defaultSpaceId, moduleColumns === 1 ? "one" : location?.column || "left");
},
getParentId: () => toolbox.id,
reorderFeatures: { item: { groupChange: true, boundaryDrop: true } },
canMoveItem: (operation) => operation.targetType !== "group" || decodeSpaceColumn(operation.sourceGroup).spaceId !== operation.targetGroup,
onItemMove: (operation) => {
let targetSpaceId = "";
let targetColumn = "";
let targetModuleId = "";
if (operation.targetType === "group") {
targetSpaceId = operation.targetGroup;
} else if (operation.targetType === "item") {
targetModuleId = operation.targetId;
targetSpaceId = getModuleSpace(toolbox, targetModuleId)?.id || "";
} else if (operation.targetType === "boundary") {
const target = decodeSpaceColumn(operation.targetGroup);
targetSpaceId = target.spaceId;
targetColumn = target.column;
}
if (!targetSpaceId) return;
const sourceSpace = getModuleSpace(toolbox, operation.sourceId);
dragSucceededRef.current = true;
updateToolbox(moveToolboxModule(toolbox, operation.sourceId, {
targetSpaceId,
targetModuleId,
targetColumn,
placement: operation.placement,
moduleColumns
}));
if (sourceSpace?.id !== targetSpaceId) {
const destination = toolbox.spaces.find((space) => space.id === targetSpaceId);
actions.notify(spacesText.moveSuccess.replace("{space}", destination?.name || ""));
}
},
hierarchy: { enabled: true, stickyParents: true }
});
const moduleReorder = {
...rawModuleReorder,
itemReorder: {
...rawModuleReorder.itemReorder,
startDrag: (event, moduleId) => {
dragOriginSpaceRef.current = getModuleSpace(toolbox, moduleId)?.id || activeSpace.id;
dragSucceededRef.current = false;
hoverActivatedRef.current = false;
rawModuleReorder.itemReorder.startDrag(event, moduleId);
}
}
};
const activateHoveredSpace = useCallback((spaceId) => {
if (spaceId === toolbox.activeSpaceId) return;
hoverActivatedRef.current = true;
updateToolbox({ ...toolbox, activeSpaceId: spaceId });
}, [toolbox, updateToolbox]);
useEffect(() => {
const draggingId = rawModuleReorder.itemReorder.draggingId;
if (previousDraggingIdRef.current && !draggingId) {
if (!dragSucceededRef.current && hoverActivatedRef.current && toolbox.spaces.some((space) => space.id === dragOriginSpaceRef.current)) {
updateToolbox({ ...toolbox, activeSpaceId: dragOriginSpaceRef.current });
}
dragOriginSpaceRef.current = "";
dragSucceededRef.current = false;
hoverActivatedRef.current = false;
}
previousDraggingIdRef.current = draggingId;
}, [rawModuleReorder.itemReorder.draggingId, toolbox, updateToolbox]);
function addModule(type, initialData = null) {
if (!type) return;
const module = { id: uid("mod"), type };
updateToolbox(addModuleToToolboxSpace(toolbox, module, activeSpace.id));
setPendingModuleId(module.id);
if (initialData) updateModuleData(toolbox.id, module.id, initialData, type);
}
function createImageAnnotationModule(dataUrl) {
if (!dataUrl) return;
const moduleId = uid("mod");
updateToolbox(addModuleToToolboxSpace(toolbox, { id: moduleId, type: "imageAnnotation" }, activeSpace.id));
setPendingModuleId(moduleId);
updateModuleData(toolbox.id, moduleId, { image: dataUrl, markers: [] }, "imageAnnotation");
}
return (
<div className={embedded ? "toolbox-embedded" : "toolbox-page"}>
<section className={embedded ? "toolbox-head page-hero nds-page-hero toolbox-head-embedded" : "toolbox-head page-hero nds-page-hero"}>
<div>
<p className="eyebrow">Toolbox</p>
<div className="toolbox-title-row">
{!embedded && !toolboxGame && <ToolboxIconPicker toolbox={toolbox} onChange={(icon, customCover = toolbox.customCover) => updateToolbox({ ...toolbox, icon, customCover })} tutorialTarget="icon" />}
{!embedded && toolboxGameCover && <ToolboxGameIcon game={toolboxGame} />}
{embedded ? <h1>{toolbox.name}</h1> : (
<EditableTitle className="toolbox-title" value={toolbox.name} fallback="Nouvelle toolbox" tutorialTarget="title" onSave={(name) => name !== toolbox.name && updateToolbox({ ...toolbox, name })} />
)}
</div>
{toolboxGame && (
<a
className="toolbox-hero-link nds-button"
data-size="sm"
href={embedded ? `#/toolbox/${toolbox.id}` : `#/games/${toolboxGame.id}`}
onClick={embedded ? () => actions.setDrawerGameId("") : undefined}
>
<Icon name="enter" />
<span>{embedded ? "Vers la toolbox complète" : "Vers la page de jeu"}</span>
</a>
)}
</div>
<div className="actions nds-toolbar">
<AddToolControls
categories={siteContent.library.categories}
descriptions={siteContent.toolboxes.addToolDescriptions}
onAdd={addModule}
/>
</div>
</section>
<ToolboxSpaces
toolbox={toolbox}
text={spacesText}
moduleReorder={moduleReorder}
onUpdateToolbox={updateToolbox}
onHoverActivate={activateHoveredSpace}
onConfirm={actions.setConfirmModal}
/>
{!embedded && showTutorial && (
<GuidedTooltipTour
key={toolboxId}
steps={siteContent.toolboxes.tutorial?.items || []}
labels={{
dismiss: siteContent.toolboxes.tutorial?.dismissLabel,
next: siteContent.toolboxes.tutorial?.nextLabel,
done: siteContent.toolboxes.tutorial?.doneLabel
}}
targetAttribute="data-toolbox-tutorial-target"
onDismiss={() => {
if (pendingTutorialToolboxId === toolbox.id) setPendingTutorialToolboxId?.("");
setShowTutorial(false);
}}
onStarted={() => {
if (pendingTutorialToolboxId === toolbox.id) setPendingTutorialToolboxId?.("");
if (toolbox.tutorial === true) updateToolbox({ ...toolbox, tutorial: false });
}}
/>
)}
{!embedded && (
<section className="modules-toolbar" aria-label="Options d'affichage des outils">
<div className="layout-switch nds-radio-button-group" data-size="sm" role="group" aria-label="Mode d'affichage des outils">
<button className={moduleColumns === 1 ? "active" : ""} onClick={() => updateToolbox({ ...toolbox, moduleColumns: 1 })} aria-pressed={moduleColumns === 1} aria-label="Afficher en lignes" title="Afficher en lignes"><Icon name="rows" /></button>
<button className={moduleColumns === 2 ? "active" : ""} onClick={() => updateToolbox({ ...toolbox, moduleColumns: 2 })} aria-pressed={moduleColumns === 2} aria-label="Afficher en colonnes" title="Afficher en colonnes"><Icon name="columns" /></button>
</div>
</section>
)}
<ToolboxModules
toolbox={toolbox}
space={activeSpace}
moduleColumns={moduleColumns}
context={moduleContext}
reorder={moduleReorder}
spacesText={spacesText}
configurationText={siteContent.toolboxes.moduleConfiguration}
scrollToModuleId={pendingModuleId}
onModuleScrolled={() => setPendingModuleId("")}
onRename={(moduleId, title) => updateToolbox({ ...toolbox, modules: toolbox.modules.map((module) => module.id === moduleId ? { ...module, title } : module) })}
onUpdateModule={(moduleId, updater) => updateToolbox({ ...toolbox, modules: toolbox.modules.map((module) => module.id === moduleId ? updater(module) : module) })}
onMoveToSpace={(moduleId, targetSpaceId) => {
const destination = toolbox.spaces.find((space) => space.id === targetSpaceId);
updateToolbox(moveToolboxModule(toolbox, moduleId, { targetSpaceId, moduleColumns }));
actions.notify(spacesText.moveSuccess.replace("{space}", destination?.name || ""));
}}
onDelete={(moduleId) => actions.setConfirmModal({
title: "Retirer l'outil",
message: "Retirer cet outil de la toolbox ?",
confirmLabel: "Retirer",
danger: true,
onResolve: (confirmed) => {
if (!confirmed) return;
const removedModule = toolbox.modules.find((module) => module.id === moduleId);
const remainingModules = toolbox.modules.filter((module) => module.id !== moduleId);
if (removedModule?.type === "taskPlanner") {
toolbox.modules.filter((module) => module.type === "memos").forEach((memosModule) => {
const memosData = normalizeMemosData(getModuleData(toolbox.id, memosModule.id, { items: [] }));
const nextMemosData = getMemosDataAfterPlannerRemoval(memosData, moduleId, remainingModules);
if (nextMemosData !== memosData) updateModuleData(toolbox.id, memosModule.id, nextMemosData, "memos");
});
}
actions.removeModuleData(toolbox.id, moduleId);
updateToolbox(removeModuleFromToolboxSpaces(toolbox, moduleId));
}
})}
/>
{!embedded && <StorageQuota usage={storageUsage} />}
</div>
);
}
export function ToolboxDrawer({ gameId, game, siteContent, toolboxes, links, actions, storageUsage, storageReady = true, getModuleData, updateToolbox, updateModuleData, addImageFiles, visible = true, compact = false }) {
const checklist = useGuideChecklist();
const guideChecklist = checklist.available && checklist.guideId.split("/")[0] === gameId ? checklist : undefined;
const selectedId = links[gameId] || "";
const toolbox = toolboxes.find((item) => item.id === selectedId);
const [width, setWidth] = useState(DRAWER_INITIAL_WIDTH);
const panelRef = useRef(null);
useEffect(() => {
const clampToViewport = () => {
if (window.innerWidth < DRAWER_INITIAL_WIDTH) return;
setWidth((currentWidth) => Math.min(currentWidth, getDrawerMaxWidth()));
};
window.addEventListener("resize", clampToViewport);
return () => window.removeEventListener("resize", clampToViewport);
}, []);
function startResize(event) {
const panel = panelRef.current;
if (!panel) return;
event.preventDefault();
const startX = event.clientX;
const startWidth = panel.getBoundingClientRect().width;
const maxWidth = getDrawerMaxWidth();
document.body.classList.add("is-resizing-drawer");
const onMove = (moveEvent) => {
const nextWidth = Math.min(Math.max(startWidth + startX - moveEvent.clientX, DRAWER_INITIAL_WIDTH), maxWidth);
setWidth(nextWidth);
};
const stop = () => {
document.body.classList.remove("is-resizing-drawer");
window.removeEventListener("pointermove", onMove);
window.removeEventListener("pointerup", stop);
window.removeEventListener("pointercancel", stop);
};
window.addEventListener("pointermove", onMove);
window.addEventListener("pointerup", stop);
window.addEventListener("pointercancel", stop);
}
return (
<aside className={`drawer ${compact ? "is-compact" : ""}`} id="toolbox-drawer" aria-hidden={!visible} inert={!visible || undefined} style={{ "--drawer-panel-width": `${width}px` }}>
<span className="drawer-resize-handle nds-drawer-resize-handle" aria-hidden="true" onPointerDown={startResize} />
<section className="drawer-panel nds-drawer-panel legacy-scrollbar" ref={panelRef}>
<div className="drawer-content">
<header>
<div>
<p className="eyebrow">Toolbox liée</p>
<div className="drawer-toolbox-actions nds-toolbar" aria-label="Actions toolbox liée">
<button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.setLinkModalGameId(gameId)} aria-label="Lier une toolbox" title="Lier"><Icon name="link" /></button>
<ImportButton className="drawer-action-button nds-icon-button import-icon-button" data-size="sm" ariaLabel="Importer une toolbox" title="Importer" icon="import" onFile={(file) => actions.importToolbox(file, gameId)} />
<button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.exportToolbox(selectedId)} disabled={!selectedId} aria-label="Exporter la toolbox liée" title="Exporter"><Icon name="export" /></button>
{actions.sharingEnabled && <button className="drawer-action-button nds-icon-button" data-size="sm" onClick={() => actions.openShareToolbox(selectedId)} disabled={!selectedId} aria-label="Envoyer la toolbox liée" title="Envoyer"><Icon name="share" /></button>}
</div>
</div>
<button className="drawer-close-button nds-icon-button" data-size="sm" onClick={() => actions.setDrawerGameId("")} aria-label="Fermer" title="Fermer"><Icon name="close" /></button>
</header>
{toolbox ? <ToolboxView siteContent={siteContent} toolbox={toolbox} toolboxGame={game} embedded actions={actions} storageUsage={storageUsage} storageReady={storageReady} getModuleData={getModuleData} updateToolbox={updateToolbox} updateModuleData={updateModuleData} addImageFiles={addImageFiles} guideChecklist={guideChecklist} /> : (
<ToolboxDrawerEmptyState gameId={gameId} toolboxes={toolboxes} links={links} actions={actions} content={siteContent.toolboxes.drawer} />
)}
<StorageQuota usage={storageUsage} />
</div>
</section>
</aside>
);
}
function ToolboxDrawerEmptyState({ gameId, toolboxes, links, actions, content }) {
const linkedToolboxIds = useMemo(() => new Set(Object.values(links).filter(Boolean)), [links]);
const availableToolboxes = useMemo(
() => toolboxes.filter((toolbox) => !linkedToolboxIds.has(toolbox.id)),
[linkedToolboxIds, toolboxes]
);
const [selectedId, setSelectedId] = useState("");
const validSelectedId = availableToolboxes.some((toolbox) => toolbox.id === selectedId) ? selectedId : "";
const hasAvailableToolboxes = availableToolboxes.length > 0;
return (
<div className="drawer-empty-toolbox">
<section className="empty nds-empty-state">
<p>{content.emptyText}</p>
<button className="nds-button" data-size="sm" data-variant="primary" type="button" onClick={() => actions.setCreateModal({ gameId })}>{content.createLabel}</button>
</section>
<section className="drawer-link-existing nds-empty-state" aria-labelledby="drawer-link-existing-title">
<h2 id="drawer-link-existing-title">{content.linkExistingTitle}</h2>
<form onSubmit={(event) => {
event.preventDefault();
if (validSelectedId) actions.linkToolboxToGame(gameId, validSelectedId);
}}>
<label className="drawer-link-existing-field">
<span>{content.selectLabel}</span>
<select className="nds-select" data-size="sm" value={validSelectedId} disabled={!hasAvailableToolboxes} onChange={(event) => setSelectedId(event.target.value)}>
<option value="">{hasAvailableToolboxes ? content.selectPlaceholder : content.noAvailable}</option>
{availableToolboxes.map((availableToolbox) => <option key={availableToolbox.id} value={availableToolbox.id}>{availableToolbox.name}</option>)}
</select>
</label>
<button className="nds-button" data-size="sm" data-variant="primary" type="submit" disabled={!validSelectedId}>{content.linkLabel}</button>
</form>
</section>
</div>
);
}
function EditableTitle({ value, fallback, onSave, className = "module-title", tutorialTarget = "" }) {
const inlineEdit = useInlineEdit({
value,
onCommit: (title) => onSave(title || fallback),
blurOnEscape: true
});
return (
<h1
{...inlineEdit.getContentEditableProps({
className,
"data-toolbox-tutorial-target": tutorialTarget || undefined,
title: "Cliquer pour renommer"
})}
>{value}</h1>
);
}