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

feat: Move "on hand" and "last made" to household (#4616)

Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
Michael Genson 2025-01-13 10:19:49 -06:00 committed by GitHub
parent e565b919df
commit e9892aba89
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 1618 additions and 400 deletions

View file

@ -5,8 +5,8 @@
:icon="$globals.icons.potSteam"
:items="tools"
item-type="tools"
@delete="actions.deleteOne"
@update="actions.updateOne"
@delete="deleteOne"
@update="updateOne"
>
<template #title> {{ $t("tool.tools") }} </template>
</RecipeOrganizerPage>
@ -14,9 +14,14 @@
</template>
<script lang="ts">
import { defineComponent, ref } from "@nuxtjs/composition-api";
import { computed, defineComponent, ref, useContext } from "@nuxtjs/composition-api";
import RecipeOrganizerPage from "~/components/Domain/Recipe/RecipeOrganizerPage.vue";
import { useToolStore } from "~/composables/store";
import { RecipeTool } from "~/lib/api/types/recipe";
interface RecipeToolWithOnHand extends RecipeTool {
onHand: boolean;
}
export default defineComponent({
components: {
@ -24,13 +29,42 @@ export default defineComponent({
},
middleware: ["auth", "group-only"],
setup() {
const { $auth } = useContext();
const toolStore = useToolStore();
const dialog = ref(false);
const userHousehold = computed(() => $auth.user?.householdSlug || "");
const tools = computed(() => toolStore.store.value.map((tool) => (
{
...tool,
onHand: tool.householdsWithTool?.includes(userHousehold.value) || false
} as RecipeToolWithOnHand
)));
async function deleteOne(id: string | number) {
await toolStore.actions.deleteOne(id);
}
async function updateOne(tool: RecipeToolWithOnHand) {
if (userHousehold.value) {
if (tool.onHand && !tool.householdsWithTool?.includes(userHousehold.value)) {
if (!tool.householdsWithTool) {
tool.householdsWithTool = [userHousehold.value];
} else {
tool.householdsWithTool.push(userHousehold.value);
}
} else if (!tool.onHand && tool.householdsWithTool?.includes(userHousehold.value)) {
tool.householdsWithTool = tool.householdsWithTool.filter((household) => household !== userHousehold.value);
}
}
await toolStore.actions.updateOne(tool);
}
return {
dialog,
tools: toolStore.store,
actions: toolStore.actions,
tools,
deleteOne,
updateOne,
};
},
head() {