add list page and multiples optis
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s
All checks were successful
Deploy Sokko G / deploy (push) Successful in 7s
This commit is contained in:
parent
d9d22683dc
commit
959fa42454
30 changed files with 1015 additions and 45 deletions
|
|
@ -10,21 +10,46 @@ async function copyText(value) {
|
|||
}
|
||||
}
|
||||
|
||||
function notify(message) {
|
||||
window.dispatchEvent(new CustomEvent("sokkog:notify", { detail: { message } }));
|
||||
}
|
||||
|
||||
export function formatChecklistImportItems(labels) {
|
||||
return labels
|
||||
.map((label) => String(label || "").trim())
|
||||
.map((entry) => {
|
||||
if (typeof entry === "object" && entry !== null) {
|
||||
const label = String(entry.label || entry.name || "").trim();
|
||||
const quantity = Number.parseInt(entry.quantity ?? entry.quantite ?? 1, 10);
|
||||
return label ? { label, quantity: Number.isFinite(quantity) ? quantity : 1 } : null;
|
||||
}
|
||||
const label = String(entry || "").trim();
|
||||
return label ? { label, quantity: 1 } : null;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.map((label) => `${label}:1`)
|
||||
.map((entry) => `${entry.label}:${entry.quantity}`)
|
||||
.join("\n");
|
||||
}
|
||||
|
||||
export function CopyChecklistItemsButton({ labels, title = "Copier pour checklist" }) {
|
||||
export function formatChecklistImportSections(sections = []) {
|
||||
return sections
|
||||
.map((section) => {
|
||||
const title = String(section?.title || "").trim();
|
||||
const items = formatChecklistImportItems(section?.items || []);
|
||||
if (!items) return "";
|
||||
return title ? `# ${title}\n${items}` : items;
|
||||
})
|
||||
.filter(Boolean)
|
||||
.join("\n\n");
|
||||
}
|
||||
|
||||
export function CopyChecklistItemsButton({ labels, sections, title = "Copier pour checklist" }) {
|
||||
const [copied, setCopied] = useState(false);
|
||||
const text = formatChecklistImportItems(labels);
|
||||
const text = sections ? formatChecklistImportSections(sections) : formatChecklistImportItems(labels);
|
||||
|
||||
async function copyItems() {
|
||||
if (!text || !await copyText(text)) return;
|
||||
setCopied(true);
|
||||
notify("Copié dans le presse-papiers.");
|
||||
window.setTimeout(() => setCopied(false), 1400);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue