Add guided onboarding tour for first toolbox creation
All checks were successful
Deploy Sokko G / deploy (push) Successful in 14s

This commit is contained in:
Shinuwa 2026-08-14 13:20:47 +02:00
parent 3007aa1389
commit 4f73e0068b
20 changed files with 470 additions and 20 deletions

View file

@ -5,6 +5,12 @@ import { ConfirmModal, CreateToolboxModal, LinkToolboxModal, NotificationToast }
import { navigate } from "../router/hashRouter.js";
import { uid } from "../features/toolboxes/storage/toolboxStorage.js";
function scrollToTopAfterNavigation() {
window.requestAnimationFrame(() => {
window.requestAnimationFrame(() => window.scrollTo({ top: 0, left: 0, behavior: "auto" }));
});
}
export function InlineNotice({ className = "", iconName = "link", message, tone = "warning" }) {
if (!message) return null;
const classes = ["inline-notice", `is-${tone}`, className].filter(Boolean).join(" ");
@ -34,7 +40,8 @@ export function AppOverlays({
toastPosition,
getGame,
toolboxes,
links
links,
setPendingTutorialToolboxId
}) {
return (
<>
@ -47,9 +54,13 @@ export function AppOverlays({
const gameId = createModal.gameId || "";
setCreateModal(null);
if (!name) return;
const toolbox = actions.createToolbox(name, gameId);
const toolbox = actions.createToolbox(name, gameId, { tutorial: createModal.tutorial === true });
if (toolbox && createModal.tutorial === true) setPendingTutorialToolboxId?.(toolbox.id);
if (toolbox && gameId) setDrawerGameId(gameId);
else if (toolbox) navigate(`/toolbox/${toolbox.id}`);
else if (toolbox) {
navigate(`/toolbox/${toolbox.id}`);
scrollToTopAfterNavigation();
}
}} />}
{linkModalGameId && <LinkToolboxModal gameId={linkModalGameId} toolboxes={toolboxes} selectedId={links[linkModalGameId] || ""} onClose={(toolboxId) => {
const gameId = linkModalGameId;

View file

@ -0,0 +1,109 @@
// Rôle : rend un tutoriel séquentiel sous forme de tooltips ciblés sur des éléments du DOM.
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from "react";
import { createPortal } from "react-dom";
import { Icon } from "./Icon.jsx";
export function GuidedTooltipTour({ steps, labels = {}, targetAttribute = "data-guided-tooltip-target", onDismiss, onStarted }) {
const [stepIndex, setStepIndex] = useState(0);
const [style, setStyle] = useState(null);
const tooltipRef = useRef(null);
const startedRef = useRef(false);
const currentStep = steps?.[stepIndex];
const isLastStep = stepIndex >= (steps?.length || 0) - 1;
const placeTooltip = useCallback(() => {
if (!currentStep?.target) return;
const target = document.querySelector(`[${targetAttribute}="${currentStep.target}"]`);
if (!target) {
setStyle(null);
return;
}
let rect = target.getBoundingClientRect();
if (rect.top < 72 || rect.bottom > window.innerHeight - 72) {
target.scrollIntoView({ block: "center", inline: "nearest", behavior: "auto" });
rect = target.getBoundingClientRect();
}
const width = Math.min(320, window.innerWidth - 24);
if (currentStep.placement === "right") {
const availableRight = window.innerWidth - rect.right - 24;
const nextWidth = Math.min(300, Math.max(230, availableRight));
const left = Math.min(window.innerWidth - nextWidth - 12, rect.right + 12);
const top = Math.max(12, rect.top + rect.height / 2 - 75);
const arrowTop = Math.min(132, Math.max(18, rect.top + rect.height / 2 - top));
setStyle({ placement: "right", top: `${top}px`, left: `${left}px`, width: `${nextWidth}px`, "--tutorial-arrow-top": `${arrowTop}px` });
if (!startedRef.current) {
startedRef.current = true;
onStarted?.();
}
return;
}
const targetCenter = rect.left + rect.width / 2;
const left = Math.min(window.innerWidth - width - 12, Math.max(12, targetCenter - width / 2));
const arrowLeft = Math.min(width - 18, Math.max(18, targetCenter - left));
const below = rect.bottom + 12;
const placement = below + 170 > window.innerHeight ? "above" : "below";
const top = placement === "above" ? Math.max(12, rect.top - 158) : below;
setStyle({ placement, top: `${top}px`, left: `${left}px`, width: `${width}px`, "--tutorial-arrow-left": `${arrowLeft}px` });
if (!startedRef.current) {
startedRef.current = true;
onStarted?.();
}
}, [currentStep, onStarted, targetAttribute]);
useEffect(() => {
let frameId = 0;
let attempts = 0;
function placeWhenReady() {
attempts += 1;
placeTooltip();
if (attempts < 20 && currentStep?.target && !document.querySelector(`[${targetAttribute}="${currentStep.target}"]`)) {
frameId = window.requestAnimationFrame(placeWhenReady);
}
}
placeWhenReady();
window.addEventListener("resize", placeTooltip);
window.addEventListener("scroll", placeTooltip, true);
return () => {
window.cancelAnimationFrame(frameId);
window.removeEventListener("resize", placeTooltip);
window.removeEventListener("scroll", placeTooltip, true);
};
}, [currentStep, placeTooltip, targetAttribute]);
useLayoutEffect(() => {
const tooltip = tooltipRef.current;
if (!tooltip || !style) return;
const viewportHeight = window.visualViewport?.height || window.innerHeight;
const rect = tooltip.getBoundingClientRect();
const nextTop = Math.min(Math.max(12, rect.top), Math.max(12, viewportHeight - rect.height - 12));
if (Math.abs(nextTop - rect.top) < 1) return;
const arrowTop = style.placement === "right" && style["--tutorial-arrow-top"]
? `${Number.parseFloat(style["--tutorial-arrow-top"]) + rect.top - nextTop}px`
: style["--tutorial-arrow-top"];
setStyle((current) => current ? { ...current, top: `${nextTop}px`, "--tutorial-arrow-top": arrowTop } : current);
}, [style, currentStep]);
if (!steps?.length || !currentStep || !style) return null;
const { placement, ...tooltipStyle } = style;
return createPortal(
<section ref={tooltipRef} className="toolbox-tutorial-tooltip" aria-live="polite" aria-labelledby="toolbox-tutorial-title" data-placement={placement} role="dialog" style={tooltipStyle}>
<button className="toolbox-tutorial-close" type="button" onClick={onDismiss} aria-label={labels.dismiss || "Fermer le tutoriel"} title={labels.dismiss || "Fermer"}>
<Icon name="close" />
</button>
<span className="toolbox-tutorial-count">{stepIndex + 1}/{steps.length}</span>
<div className="toolbox-tutorial-heading">
<Icon name={currentStep.icon || "info"} />
<strong id="toolbox-tutorial-title">{currentStep.title}</strong>
</div>
<p>{currentStep.text}</p>
<footer>
<button className="primary" type="button" onClick={isLastStep ? onDismiss : () => setStepIndex((index) => Math.min(index + 1, steps.length - 1))}>
{isLastStep ? labels.done || "Terminer" : labels.next || "Suivant"}
</button>
</footer>
</section>,
document.body
);
}

View file

@ -32,7 +32,7 @@ export function Shell({ route, content, games, toolboxes, links, actions, childr
<span className="badge">{content.sidebar.badge}</span>
<p>{content.sidebar.note}</p>
<div className="sidebar-storage-actions" aria-label="Actions globales de stockage">
<button className="sidebar-action-button primary" onClick={actions.exportAllToolboxes} aria-label="Exporter toutes les toolboxes" title="Exporter tout"><Icon name="export" /></button>
<button className="sidebar-action-button primary" onClick={actions.exportAllToolboxes} aria-label="Exporter toutes les toolboxes" data-toolbox-tutorial-target="exportAll" title="Exporter tout"><Icon name="export" /></button>
<ImportButton className="sidebar-action-button import-icon-button" title="Importer tout" ariaLabel="Importer toutes les toolboxes" onFile={actions.importAllToolboxes} icon="import" />
</div>
</div>