Let a guide checklist update from its page filters without losing checks, and optionally limit the page to what the checklist contains
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
17e5cd5e63
commit
07a43ef848
17 changed files with 486 additions and 36 deletions
|
|
@ -1,34 +1,114 @@
|
|||
/**
|
||||
* @file Expose le suivi du guide dans chaque checklist compatible et marque les cartes terminées.
|
||||
* @file Expose le suivi du guide dans chaque checklist compatible, sa mise à jour depuis les filtres de la page,
|
||||
* et marque les cartes terminées.
|
||||
*/
|
||||
|
||||
import { useId, useState } from "react";
|
||||
import { Icon } from "../../components/Icon.jsx";
|
||||
import { Modal } from "../../components/Modal.jsx";
|
||||
|
||||
function notify(message) {
|
||||
window.dispatchEvent(new CustomEvent("sokkog:notify", { detail: { message } }));
|
||||
}
|
||||
|
||||
function withCount(template, count) {
|
||||
return String(template || "").replace("{count}", String(count)).replace("{s}", count > 1 ? "s" : "");
|
||||
}
|
||||
|
||||
function GuideChecklistUpdateModal({ checklist, list, onClose }) {
|
||||
const titleId = useId();
|
||||
const descriptionId = useId();
|
||||
const { content } = checklist;
|
||||
const [removeMissing, setRemoveMissing] = useState(false);
|
||||
const [error, setError] = useState("");
|
||||
const preview = checklist.previewPageUpdate(list.id, removeMissing);
|
||||
const summary = preview?.summary;
|
||||
const changed = Boolean(summary && (summary.added || summary.removed));
|
||||
|
||||
function submit() {
|
||||
if (!changed) return;
|
||||
if (!checklist.applyPageUpdate(list.id, removeMissing)) {
|
||||
setError(content.updateError);
|
||||
return;
|
||||
}
|
||||
notify(content.updateDone);
|
||||
onClose();
|
||||
}
|
||||
|
||||
return (
|
||||
<Modal rootClassName="confirm-modal-root results-checklist-modal-root" dialogClassName="confirm-modal nds-modal results-checklist-modal" labelledBy={titleId} describedBy={descriptionId} onRequestClose={onClose}>
|
||||
<header className="results-checklist-modal-header">
|
||||
<h2 id={titleId}>{content.updateTitle}</h2>
|
||||
<button className="nds-icon-button" data-size="sm" type="button" onClick={onClose} aria-label={content.resultsClose} title={content.resultsClose}>
|
||||
<Icon name="close" />
|
||||
</button>
|
||||
</header>
|
||||
<p id={descriptionId} className="results-checklist-modal-description">{content.updateDescription}</p>
|
||||
<div className="results-checklist-modal-summary">
|
||||
<span>{content.updateChecklistLabel}</span>
|
||||
<strong>{list.title}</strong>
|
||||
</div>
|
||||
{summary && preview.results > 0 && (
|
||||
<dl className="guide-checklist-update-stats">
|
||||
<div><dt>{content.updateResults}</dt><dd>{preview.results}</dd></div>
|
||||
<div><dt>{content.updateAdded}</dt><dd>{summary.added}</dd></div>
|
||||
<div><dt>{content.updateKept}</dt><dd>{summary.kept}{summary.completed > 0 && <small>{withCount(content.updateCompletedCount, summary.completed)}</small>}</dd></div>
|
||||
<div><dt>{content.updateMissing}</dt><dd>{summary.missing}{summary.missingCompleted > 0 && <small>{withCount(content.updateCompletedCount, summary.missingCompleted)}</small>}</dd></div>
|
||||
</dl>
|
||||
)}
|
||||
{summary?.missing > 0 && preview.results > 0 && (
|
||||
<button className="guide-checklist-update-option nds-switch" data-size="sm" type="button" aria-pressed={removeMissing} onClick={() => setRemoveMissing((value) => !value)}>
|
||||
<Icon name="trash" /><span>{content.updateRemoveMissing}</span><i aria-hidden="true" />
|
||||
</button>
|
||||
)}
|
||||
{!preview?.results && <p className="results-checklist-modal-notice nds-inline-notice" data-variant="warning" role="status"><Icon name="warning" /><span>{content.updateNoResults}</span></p>}
|
||||
{preview?.results > 0 && !changed && <p className="results-checklist-modal-notice nds-inline-notice" role="status"><Icon name="check" /><span>{content.updateUpToDate}</span></p>}
|
||||
{error && <p className="results-checklist-modal-error nds-inline-notice" data-variant="danger" role="alert"><Icon name="close" /><span>{error}</span></p>}
|
||||
<footer className="nds-modal-footer results-checklist-modal-actions">
|
||||
<button className="nds-button" data-size="sm" type="button" onClick={onClose} data-modal-initial-focus="">{content.updateCancel}</button>
|
||||
<button className="nds-button" data-size="sm" data-variant="primary" type="button" disabled={!changed} onClick={submit}>
|
||||
<Icon name="refresh" />{content.updateConfirm}
|
||||
</button>
|
||||
</footer>
|
||||
</Modal>
|
||||
);
|
||||
}
|
||||
|
||||
export function GuideChecklistControls({ checklist, list, id, open }) {
|
||||
const [updating, setUpdating] = useState(false);
|
||||
if (!list) return null;
|
||||
const { content, selected, hideCompleted } = checklist;
|
||||
const { content, selected, hideCompleted, onlyListed } = checklist;
|
||||
const active = selected?.id === list.id;
|
||||
return <div id={id} hidden={!open} className="guide-checklist-controls" data-linked={active || undefined}>
|
||||
<div className="guide-checklist-actions">
|
||||
<button type="button" className="guide-checklist-link nds-button" data-size="xs" data-variant={active ? "primary" : "secondary"} aria-pressed={active} onClick={() => checklist.associate(active ? "" : list.id)}>{active ? content.unlink : content.associate}</button>
|
||||
<button type="button" className="nds-switch" data-size="xs" disabled={!active} aria-pressed={active && hideCompleted} onClick={checklist.toggleHidden}><Icon name="hide" /><span>{content.hideCompleted}</span><i aria-hidden="true" /></button>
|
||||
<button type="button" className="nds-switch" data-size="xs" disabled={!active} aria-pressed={active && onlyListed} onClick={checklist.toggleOnlyListed}><Icon name="checklist" /><span>{content.onlyListed}</span><i aria-hidden="true" /></button>
|
||||
<button type="button" className="guide-checklist-update nds-button" data-size="xs" data-variant="secondary" onClick={() => setUpdating(true)}><Icon name="refresh" />{content.updateFromPage}</button>
|
||||
</div>
|
||||
<p>{list.count ? `${list.count} ${content.matches}` : content.noMatches}</p>
|
||||
{updating && <GuideChecklistUpdateModal checklist={checklist} list={list} onClose={() => setUpdating(false)} />}
|
||||
</div>;
|
||||
}
|
||||
|
||||
export function GuideChecklistPageControls({ checklist }) {
|
||||
const selectId = useId();
|
||||
if (!checklist.lists.length) return null;
|
||||
const { content, hideCompleted } = checklist;
|
||||
const { content, hideCompleted, onlyListed } = checklist;
|
||||
return (
|
||||
<aside className="guide-checklist-page-controls nds-tool-panel" aria-label={content.label}>
|
||||
<label className="guide-checklist-page-select">
|
||||
<span>{content.selectLabel}</span>
|
||||
<select className="nds-select" data-size="sm" value={checklist.selected?.id || ""} onChange={(event) => checklist.associate(event.target.value)}>
|
||||
<div className="guide-checklist-page-select">
|
||||
<label htmlFor={selectId}>{content.selectLabel}</label>
|
||||
<select id={selectId} className="nds-select" data-size="sm" value={checklist.selected?.id || ""} onChange={(event) => checklist.associate(event.target.value)}>
|
||||
{!checklist.selected && <option value="" disabled>{content.selectPlaceholder}</option>}
|
||||
{checklist.lists.map((list) => <option key={list.id} value={list.id}>{list.title}</option>)}
|
||||
</select>
|
||||
</label>
|
||||
{checklist.selected && (
|
||||
<button className="nds-icon-button" data-size="xs" type="button" onClick={() => checklist.associate("")} aria-label={content.unlink} title={content.unlink}>
|
||||
<Icon name="close" />
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{checklist.selected && (
|
||||
<div className="guide-checklist-page-actions">
|
||||
<button className={`nds-switch ${hideCompleted ? "active" : ""}`} data-size="sm" type="button" aria-pressed={hideCompleted} onClick={checklist.toggleHidden}>
|
||||
|
|
@ -36,7 +116,11 @@ export function GuideChecklistPageControls({ checklist }) {
|
|||
<span>{content.hideCompleted}</span>
|
||||
<i aria-hidden="true" />
|
||||
</button>
|
||||
<button className="nds-button" data-size="xs" data-variant="secondary" type="button" onClick={() => checklist.associate("")}>{content.unlink}</button>
|
||||
<button className={`nds-switch ${onlyListed ? "active" : ""}`} data-size="sm" type="button" aria-pressed={onlyListed} onClick={checklist.toggleOnlyListed}>
|
||||
<Icon name="checklist" />
|
||||
<span>{content.onlyListed}</span>
|
||||
<i aria-hidden="true" />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</aside>
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ function AniimoListing({ game, aniimo, filters, setFilters, content }) {
|
|||
<h1>{content.title}</h1>
|
||||
<span className="results-count aniimo-results-count" role="status"><span data-copy-target={active.grouped || undefined}>{groups.length} / {totalAniimos} {content.title}</span>{" · "}<span data-copy-target={!active.grouped || undefined}>{visible.length} / {aniimo.variants.length} {content.variants.toLowerCase()}</span></span>
|
||||
<CopyChecklistItemsButton
|
||||
labels={active.grouped ? groups.map(([variant]) => t(variant.name)) : visible.map((variant) => `${t(variant.name)} — ${t(variant.form)}`)}
|
||||
labels={checklist.resultLabels(visible)}
|
||||
title={active.grouped ? content.copyChecklist : content.copyVariantsChecklist}
|
||||
filteredResults
|
||||
checklistTitle={active.grouped ? content.title : content.variantsChecklistTitle}
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ export function Diablo4Listing({ game, diablo4, filters, setFilters }) {
|
|||
<h1>Affixes</h1>
|
||||
<span className="results-count">{visible.length} / {diablo4.affixes.length}</span>
|
||||
<CopyChecklistItemsButton
|
||||
labels={visible.map((affix) => affix.label)}
|
||||
labels={checklist.resultLabels(visible)}
|
||||
title="Utiliser les affixes visibles pour une checklist"
|
||||
filteredResults
|
||||
checklistTitle="Affixes"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,16 @@
|
|||
/**
|
||||
* @file Reconnaît les lignes de checklist et valide les associations persistantes des guides.
|
||||
* @file Reconnaît les lignes de checklist, met une checklist à jour depuis les filtres d'un guide
|
||||
* et valide les associations persistantes des guides.
|
||||
*
|
||||
* Utilisé par : useGuideChecklist.js (page et tiroir de toolbox), useGuideChecklistStorage.js.
|
||||
* Attention : la correspondance se fait par libellé normalisé (accents, casse, espaces, français ou anglais),
|
||||
* jamais par identifiant : une ligne renommée dans les données du jeu n'est plus reconnue.
|
||||
*/
|
||||
|
||||
import { aniimoLabel, filterAniimoVariants, groupAniimoVariants } from "./aniimo/utils.js";
|
||||
import { getFilteredDiablo4Affixes } from "./diablo4/utils.js";
|
||||
import { getFilteredMhwildsItems, getMhwildsFilterKey } from "./mhwilds/utils.js";
|
||||
|
||||
export const GUIDE_CHECKLIST_STORAGE_KEY = "sokkog:guide-checklists";
|
||||
const GUIDES = new Set(["aniimo/aniimos", "mhwilds/monsters", "mhwilds/endemic", "diablo4/affixes"]);
|
||||
|
||||
|
|
@ -47,13 +56,18 @@ export function toggleGuideChecklistRows(data, ids, completed) {
|
|||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Associations `{ toolboxId, moduleId, hideCompleted, onlyListed }` encore valides, indexées par guide ;
|
||||
* écarte les guides inconnus, les toolboxes qui ne sont plus liées au jeu et les modules disparus.
|
||||
*/
|
||||
export function validGuideAssociations(value, toolboxes, links) {
|
||||
return Object.fromEntries(Object.entries(value || {}).filter(([guideId, association]) => {
|
||||
if (!GUIDES.has(guideId) || !association || typeof association !== "object") return false;
|
||||
const toolbox = toolboxes.find((item) => item.id === association.toolboxId && item.id === links[guideId.split("/")[0]]);
|
||||
return toolbox?.modules.some((module) => module.id === association.moduleId && module.type === "checklist");
|
||||
}).map(([key, association]) => [key, {
|
||||
toolboxId: association.toolboxId, moduleId: association.moduleId, hideCompleted: association.hideCompleted === true
|
||||
toolboxId: association.toolboxId, moduleId: association.moduleId, hideCompleted: association.hideCompleted === true,
|
||||
onlyListed: association.onlyListed === true
|
||||
}]));
|
||||
}
|
||||
|
||||
|
|
@ -74,3 +88,107 @@ export function getGuideChecklistEntries(guideId, { aniimo, mhwilds, diablo4 })
|
|||
key: item.name, labels: [mhwilds.translations[item.name] || item.name.replace(/_/g, " ")]
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* Éléments d'un guide qui passent les filtres courants, avant le masquage des éléments cochés.
|
||||
* Renvoie null quand le guide n'est pas compatible ou que ses données ne sont pas encore chargées.
|
||||
*/
|
||||
export function filterGuideItems(guideId, { aniimo, mhwilds, diablo4, filters, t }) {
|
||||
if (!GUIDES.has(guideId)) return null;
|
||||
if (guideId === "aniimo/aniimos") return aniimo.loaded ? filterAniimoVariants(aniimo.variants, filters.aniimo) : null;
|
||||
if (guideId === "diablo4/affixes") return diablo4.loaded ? getFilteredDiablo4Affixes({ affixes: diablo4.affixes, filters: filters.diablo4 }) : null;
|
||||
if (!mhwilds.loaded) return null;
|
||||
const category = guideId.split("/")[1];
|
||||
return getFilteredMhwildsItems({ category, filterKey: getMhwildsFilterKey(category, mhwilds), mhwilds, filters, t });
|
||||
}
|
||||
|
||||
/**
|
||||
* Lignes de checklist `{ key, label, labels }` produites par des éléments de guide, dans l'ordre de la page.
|
||||
* `label` nomme une nouvelle ligne ; `labels` liste les libellés (français, anglais) qui reconnaissent une ligne existante.
|
||||
* Aniimo suit le regroupement de la page : une ligne par espèce, ou une par variante « Nom — Forme ».
|
||||
*/
|
||||
export function toGuideChecklistResults(guideId, items, { aniimo, filters, t }) {
|
||||
if (guideId === "aniimo/aniimos") {
|
||||
const french = (key) => aniimoLabel(aniimo.translations, key);
|
||||
const english = (key) => aniimo.englishTranslations?.[key] || "";
|
||||
if (filters.aniimo.grouped) {
|
||||
return groupAniimoVariants(items).map(([variant]) => ({
|
||||
key: variant.aniimoUid, label: french(variant.name), labels: [french(variant.name), english(variant.name)].filter(Boolean)
|
||||
}));
|
||||
}
|
||||
return items.map((variant) => {
|
||||
const label = `${french(variant.name)} — ${french(variant.form)}`;
|
||||
const englishLabel = english(variant.name) && english(variant.form) ? `${english(variant.name)} — ${english(variant.form)}` : "";
|
||||
return { key: variant.key, label, labels: [label, englishLabel].filter(Boolean) };
|
||||
});
|
||||
}
|
||||
if (guideId === "diablo4/affixes") return items.map((affix) => ({ key: affix.id, label: affix.label, labels: [affix.label] }));
|
||||
return items.map((item) => ({ key: item.name, label: t(item.name, { capitalize: true }), labels: [t(item.name)] }));
|
||||
}
|
||||
|
||||
function isChecklistRowComplete(row) {
|
||||
return Number(row.qtyCurrent || 0) >= Math.max(1, Number(row.qtyTarget || 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Fusionne les résultats d'une page de guide dans une checklist, sans modifier `data`.
|
||||
* Une ligne reconnue garde son identifiant, sa cible et sa progression ; un résultat inconnu devient une ligne non cochée,
|
||||
* insérée après la ligne du résultat précédent pour suivre l'ordre de la page. Les lignes absentes des résultats
|
||||
* restent, sauf avec `removeMissing`. Renvoie `{ data, summary }`, où `summary` compte les lignes ajoutées,
|
||||
* conservées (`kept`, dont `completed` cochées), absentes (`missing`, dont `missingCompleted` cochées) et retirées.
|
||||
*/
|
||||
export function mergeGuideChecklistResults(data, results, { removeMissing = false, uid }) {
|
||||
const sourceSections = Array.isArray(data?.sections) && data.sections.length
|
||||
? data.sections
|
||||
: data?.items?.length ? [{ id: uid("section"), title: "", items: data.items }] : [];
|
||||
const sections = sourceSections.map((section) => ({ ...section, items: [...(section.items || [])] }));
|
||||
const byLabel = new Map();
|
||||
const register = (label, row) => {
|
||||
const key = normalizeGuideLabel(label);
|
||||
if (!key) return;
|
||||
if (!byLabel.has(key)) byLabel.set(key, []);
|
||||
byLabel.get(key).push(row);
|
||||
};
|
||||
sections.forEach((section) => section.items.forEach((item) => register(item.label, { section, item })));
|
||||
|
||||
const matched = new Set();
|
||||
const added = new Set();
|
||||
let anchor = null;
|
||||
for (const result of results) {
|
||||
const labels = [...new Set((result.labels?.length ? result.labels : [result.label]).map(normalizeGuideLabel))];
|
||||
const rows = labels.flatMap((label) => byLabel.get(label) || []);
|
||||
if (rows.length) {
|
||||
rows.forEach((row) => { if (!added.has(row.item)) matched.add(row.item); });
|
||||
anchor = rows.at(-1);
|
||||
continue;
|
||||
}
|
||||
const label = String(result.label || "").trim();
|
||||
if (!label) continue;
|
||||
const item = { id: uid("item"), label, qtyTarget: 1, qtyCurrent: 0 };
|
||||
if (!sections.length) sections.push({ id: uid("section"), title: "", items: [] });
|
||||
const section = anchor?.section || sections[0];
|
||||
section.items.splice(anchor ? section.items.indexOf(anchor.item) + 1 : 0, 0, item);
|
||||
added.add(item);
|
||||
anchor = { section, item };
|
||||
labels.forEach((key) => register(key, anchor));
|
||||
}
|
||||
|
||||
const rows = sections.flatMap((section) => section.items).filter((item) => !added.has(item));
|
||||
const missing = rows.filter((item) => !matched.has(item));
|
||||
const nextSections = sections
|
||||
.map((section) => removeMissing ? { ...section, items: section.items.filter((item) => added.has(item) || matched.has(item)) } : section)
|
||||
.filter((section) => section.items.length);
|
||||
const next = { ...data, sections: nextSections };
|
||||
delete next.items;
|
||||
return {
|
||||
data: next,
|
||||
summary: {
|
||||
added: added.size,
|
||||
kept: matched.size,
|
||||
completed: rows.filter((item) => matched.has(item) && isChecklistRowComplete(item)).length,
|
||||
missing: missing.length,
|
||||
missingCompleted: missing.filter(isChecklistRowComplete).length,
|
||||
removed: removeMissing ? missing.length : 0
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ export function MhwildsListing({ category, game, mhwilds, filters, setFilters, t
|
|||
<h1>{label}</h1>
|
||||
<span className="results-count">{visible.length} / {items.length}</span>
|
||||
<CopyChecklistItemsButton
|
||||
labels={visible.map((item) => t(item.name, { capitalize: true }))}
|
||||
labels={checklist.resultLabels(visible)}
|
||||
title={`Utiliser les ${label.toLowerCase()} visibles pour une checklist`}
|
||||
filteredResults
|
||||
checklistTitle={label}
|
||||
|
|
|
|||
|
|
@ -1,20 +1,31 @@
|
|||
/**
|
||||
* @file Partage la progression réactive et les commandes de liaison entre les guides.
|
||||
*
|
||||
* Utilisé par : les pages de guides (Aniimo, MHWilds, Diablo IV) et le tiroir de toolbox (ToolboxPages, ModuleShell).
|
||||
* Dépend de : GuideChecklistContext, fourni par main.jsx avec les données de jeu, les filtres et les toolboxes.
|
||||
* Attention : la mise à jour depuis la page part des filtres courants, pas des éléments visibles : les éléments
|
||||
* masqués par la checklist (cochés, ou absents avec « Seulement la checklist ») restent des résultats.
|
||||
*/
|
||||
|
||||
import { createContext, useContext, useId, useMemo } from "react";
|
||||
import { getGuideChecklistEntries, matchGuideChecklist, toggleGuideChecklistRows } from "./guideChecklist.js";
|
||||
import { uid } from "../toolboxes/storage/modules/shared.js";
|
||||
import { filterGuideItems, getGuideChecklistEntries, matchGuideChecklist, mergeGuideChecklistResults, toGuideChecklistResults, toggleGuideChecklistRows } from "./guideChecklist.js";
|
||||
|
||||
export const GuideChecklistContext = createContext(null);
|
||||
|
||||
/** Liste de guide `{ id, list }` correspondant au module, ou `list` undefined si le module n'est pas une checklist reconnue. */
|
||||
export function useGuideChecklistPanel(checklist, module) {
|
||||
const id = useId();
|
||||
const list = module.type === "checklist" ? checklist?.lists.find((item) => item.id === module.id) : undefined;
|
||||
return { id, list };
|
||||
}
|
||||
|
||||
/**
|
||||
* État et commandes de la checklist associée au guide demandé, ou au guide de la route courante.
|
||||
* `available` est faux hors des guides compatibles ; les commandes ne font rien sans toolbox liée au jeu.
|
||||
*/
|
||||
export function useGuideChecklist(requestedGuideId) {
|
||||
const { toolboxes, links, moduleData, guideChecklistStorage, actions, siteContent, route, aniimo, mhwilds, diablo4 } = useContext(GuideChecklistContext);
|
||||
const { toolboxes, links, moduleData, guideChecklistStorage, actions, siteContent, route, aniimo, mhwilds, diablo4, filters, t } = useContext(GuideChecklistContext);
|
||||
const guideId = requestedGuideId || route.replace(/^\/games\//, "");
|
||||
const entries = useMemo(() => getGuideChecklistEntries(guideId, { aniimo, mhwilds, diablo4 }), [guideId, aniimo, mhwilds, diablo4]);
|
||||
const gameId = guideId.split("/")[0];
|
||||
|
|
@ -28,6 +39,7 @@ export function useGuideChecklist(requestedGuideId) {
|
|||
})), [entries, toolbox, moduleData]);
|
||||
const selected = lists.find((list) => list.id === association?.moduleId);
|
||||
const hideCompleted = Boolean(selected && association.hideCompleted);
|
||||
const onlyListed = Boolean(selected && association.onlyListed);
|
||||
const isCompleted = (key) => Boolean(selected?.completed.has(key));
|
||||
const canToggle = (key) => Boolean(selected?.rowIds.get(key)?.length);
|
||||
function toggleCompleted(key) {
|
||||
|
|
@ -36,12 +48,30 @@ export function useGuideChecklist(requestedGuideId) {
|
|||
const data = moduleData[`${toolbox.id}:${selected.id}`];
|
||||
actions.updateModuleData(toolbox.id, selected.id, toggleGuideChecklistRows(data, ids, !isCompleted(key)), "checklist");
|
||||
}
|
||||
const sources = { aniimo, mhwilds, diablo4, filters, t };
|
||||
function previewPageUpdate(moduleId, removeMissing = false) {
|
||||
const data = toolbox ? moduleData[`${toolbox.id}:${moduleId}`] : undefined;
|
||||
// Données pas encore lues dans IndexedDB : un aperçu partirait d'une checklist vide.
|
||||
if (typeof data === "symbol") return null;
|
||||
const items = toolbox ? filterGuideItems(guideId, sources) : null;
|
||||
if (!items) return null;
|
||||
const results = toGuideChecklistResults(guideId, items, sources);
|
||||
return { results: results.length, ...mergeGuideChecklistResults(data, results, { removeMissing, uid }) };
|
||||
}
|
||||
function applyPageUpdate(moduleId, removeMissing = false) {
|
||||
const preview = previewPageUpdate(moduleId, removeMissing);
|
||||
return Boolean(preview?.results && actions.updateModuleData(toolbox.id, moduleId, preview.data, "checklist"));
|
||||
}
|
||||
return {
|
||||
content, toolbox, selected, hideCompleted, isCompleted, canToggle, toggleCompleted, guideId, available: entries !== null,
|
||||
content, toolbox, selected, hideCompleted, onlyListed, isCompleted, canToggle, toggleCompleted, guideId, available: entries !== null,
|
||||
lists: lists.filter((list) => list.count || list.id === selected?.id),
|
||||
isVisible: (key) => !hideCompleted || !isCompleted(key),
|
||||
isVisible: (key) => (!hideCompleted || !isCompleted(key)) && (!onlyListed || Boolean(selected?.rowIds.has(key))),
|
||||
createChecklistFromResults: (checklist) => actions.createChecklistFromResults(gameId, checklist),
|
||||
associate: (moduleId) => guideChecklistStorage.setAssociation(guideId, moduleId ? { toolboxId: toolbox.id, moduleId, hideCompleted } : null),
|
||||
toggleHidden: () => guideChecklistStorage.setAssociation(guideId, { ...association, hideCompleted: !hideCompleted })
|
||||
resultLabels: (items) => toGuideChecklistResults(guideId, items, sources).map((result) => result.label),
|
||||
previewPageUpdate,
|
||||
applyPageUpdate,
|
||||
associate: (moduleId) => guideChecklistStorage.setAssociation(guideId, moduleId ? { toolboxId: toolbox.id, moduleId, hideCompleted, onlyListed } : null),
|
||||
toggleHidden: () => guideChecklistStorage.setAssociation(guideId, { ...association, hideCompleted: !hideCompleted }),
|
||||
toggleOnlyListed: () => guideChecklistStorage.setAssociation(guideId, { ...association, onlyListed: !onlyListed })
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue