Add checklist creation for filtered game results
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 18s
This commit is contained in:
parent
0acf5ecf21
commit
962816bbb9
15 changed files with 414 additions and 40 deletions
|
|
@ -116,37 +116,65 @@ export function useToolboxActions({ store, notify, creationTemplate, setConfirmM
|
|||
});
|
||||
}
|
||||
|
||||
function createChecklistFromList(gameId, list) {
|
||||
async function createChecklistFromResults(gameId, checklist) {
|
||||
const toolboxId = store.links[gameId] || "";
|
||||
const toolbox = store.toolboxes.find((item) => item.id === toolboxId);
|
||||
if (!toolbox || !list) return false;
|
||||
if (!toolbox || !checklist) return false;
|
||||
|
||||
const moduleId = uid("mod");
|
||||
const sections = (list.categories || []).map((category) => ({
|
||||
const sourceSections = Array.isArray(checklist.sections)
|
||||
? checklist.sections
|
||||
: [{ title: "", items: checklist.items || [] }];
|
||||
const sections = sourceSections.map((category) => ({
|
||||
id: uid("section"),
|
||||
title: category.title || "",
|
||||
items: (category.items || []).map((item) => ({
|
||||
id: uid("item"),
|
||||
label: item.name,
|
||||
qtyTarget: Math.max(1, Number.parseInt(item.quantity, 10) || 1),
|
||||
label: typeof item === "object" && item !== null ? String(item.label || item.name || "").trim() : String(item || "").trim(),
|
||||
qtyTarget: Math.max(1, Number.parseInt(item?.quantity ?? item?.qtyTarget, 10) || 1),
|
||||
qtyCurrent: 0
|
||||
})).filter((item) => item.label)
|
||||
})).filter((section) => section.items.length);
|
||||
|
||||
if (!sections.length) return false;
|
||||
|
||||
const title = String(checklist.title || "Checklist").trim() || "Checklist";
|
||||
const updatedAt = new Date().toISOString();
|
||||
const data = compactModuleDataForStorage("checklist", { sections });
|
||||
let created = false;
|
||||
const saved = await store.persistToolboxSnapshot((current) => {
|
||||
if (current.links[gameId] !== toolboxId || !current.toolboxes.some((item) => item.id === toolboxId)) return current;
|
||||
created = true;
|
||||
return {
|
||||
...current,
|
||||
toolboxes: current.toolboxes.map((item) => item.id === toolboxId
|
||||
? { ...addModuleToToolboxSpace(item, { id: moduleId, type: "checklist", title }, item.activeSpaceId), updatedAt }
|
||||
: item),
|
||||
moduleData: { ...current.moduleData, [globalModuleKey(toolboxId, moduleId)]: data }
|
||||
};
|
||||
});
|
||||
if (saved && created) notify("Checklist créée dans la toolbox associée.");
|
||||
return Boolean(saved && created);
|
||||
}
|
||||
|
||||
function createChecklistFromList(gameId, list) {
|
||||
const toolboxId = store.links[gameId] || "";
|
||||
const toolbox = store.toolboxes.find((item) => item.id === toolboxId);
|
||||
if (!toolbox || !list) return false;
|
||||
|
||||
setConfirmModal({
|
||||
title: "Créer une checklist",
|
||||
message: `Créer la checklist "${list.title || "Checklist"}" dans la toolbox "${toolbox.name}" ?`,
|
||||
confirmLabel: "Créer",
|
||||
onResolve: (confirmed) => {
|
||||
if (!confirmed) return;
|
||||
const updatedAt = new Date().toISOString();
|
||||
store.setToolboxes((toolboxes) => toolboxes.map((item) => item.id === toolboxId
|
||||
? { ...addModuleToToolboxSpace(item, { id: moduleId, type: "checklist", title: list.title || "Checklist" }, item.activeSpaceId), updatedAt }
|
||||
: item));
|
||||
store.updateModuleData(toolboxId, moduleId, { sections }, "checklist");
|
||||
notify("Checklist créée dans la toolbox associée.");
|
||||
void createChecklistFromResults(gameId, {
|
||||
title: list.title || "Checklist",
|
||||
sections: (list.categories || []).map((category) => ({
|
||||
title: category.title || "",
|
||||
items: category.items || []
|
||||
}))
|
||||
});
|
||||
}
|
||||
});
|
||||
return true;
|
||||
|
|
@ -263,6 +291,7 @@ export function useToolboxActions({ store, notify, creationTemplate, setConfirmM
|
|||
setLinkModalGameId,
|
||||
setDrawerGameId,
|
||||
setImage,
|
||||
createChecklistFromResults,
|
||||
createChecklistFromList,
|
||||
addImageFiles,
|
||||
ensureModuleData: store.ensureModuleData,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue