1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-24 15:49:42 +02:00

Merge branch 'mealie-next' into feat/filter-shopping-lists

This commit is contained in:
Michael Genson 2024-03-05 09:18:37 -06:00 committed by GitHub
commit c9fdf862a3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
57 changed files with 514 additions and 341 deletions

View file

@ -369,21 +369,50 @@ export default defineComponent({
const copy = useCopyList();
function copyListItems(copyType: CopyTypes) {
const items = shoppingList.value?.listItems?.filter((item) => !item.checked);
const text: string[] = [];
if (!items) {
return;
if (preferences.value.viewByLabel) {
// if we're sorting by label, we want the copied text in subsections
Object.entries(itemsByLabel.value).forEach(([label, items], idx) => {
// for every group except the first, add a blank line
if (idx) {
text.push("")
}
// add an appropriate heading for the label depending on the copy format
text.push(formatCopiedLabelHeading(copyType, label))
// now add the appropriately formatted list items with the given label
items.forEach((item) => text.push(formatCopiedListItem(copyType, item)))
})
} else {
// labels are toggled off, so just copy in the order they come in
const items = shoppingList.value?.listItems?.filter((item) => !item.checked)
items?.forEach((item) => {
text.push(formatCopiedListItem(copyType, item))
});
}
const text: string[] = items.map((itm) => itm.display || "");
copy.copyPlain(text);
}
function formatCopiedListItem(copyType: CopyTypes, item: ShoppingListItemOut): string {
const display = item.display || ""
switch (copyType) {
case "markdown":
copy.copyMarkdownCheckList(text);
break;
return `- [ ] ${display}`
default:
copy.copyPlain(text);
break;
return display
}
}
function formatCopiedLabelHeading(copyType: CopyTypes, label: string): string {
switch (copyType) {
case "markdown":
return `# ${label}`
default:
return `[${label}]`
}
}