feat: Improve shopping list label sections (#6345)

Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com>
This commit is contained in:
miah
2025-10-24 09:43:55 -05:00
committed by GitHub
parent a242f567ad
commit 201c63d1e4
4 changed files with 134 additions and 134 deletions

View File

@@ -1,5 +1,5 @@
import { useToggle } from "@vueuse/core";
import type { ShoppingListOut, ShoppingListItemOut } from "~/lib/api/types/household";
import type { ShoppingListOut } from "~/lib/api/types/household";
/**
* Composable for managing shopping list label state and operations
@@ -36,14 +36,24 @@ export function useShoppingListLabels(shoppingList: Ref<ShoppingListOut | null>)
);
});
const labelColorByName = computed(() => {
const map: Record<string, string | undefined> = {};
shoppingList.value?.listItems?.forEach((item) => {
if (!item.label) return;
const labelName = item.label?.name || t("shopping-list.no-label");
map[labelName] = item.label.color;
});
return map;
});
watch(labelNames, initializeLabelOpenStates, { immediate: true });
function toggleShowLabel(key: string) {
labelOpenState.value[key] = !labelOpenState.value[key];
}
function getLabelColor(item: ShoppingListItemOut | null) {
return item?.label?.color;
function getLabelColor(label: string) {
return labelColorByName.value[label];
}
const presentLabels = computed(() => {