2022-08-27 10:44:58 -08:00
|
|
|
<template>
|
2025-06-28 15:59:58 +02:00
|
|
|
<div class="d-flex justify-start align-top flex-wrap">
|
2025-06-20 00:09:12 +07:00
|
|
|
<RecipeImageUploadBtn
|
2025-06-28 15:59:58 +02:00
|
|
|
class="my-2"
|
2025-06-20 00:09:12 +07:00
|
|
|
:slug="recipe.slug"
|
|
|
|
@upload="uploadImage"
|
|
|
|
@refresh="imageKey++"
|
|
|
|
/>
|
2022-08-27 10:44:58 -08:00
|
|
|
<RecipeSettingsMenu
|
2025-06-20 00:09:12 +07:00
|
|
|
v-model="recipe.settings"
|
2025-06-28 15:59:58 +02:00
|
|
|
class="my-2 mx-1"
|
2022-08-27 10:44:58 -08:00
|
|
|
:is-owner="recipe.userId == user.id"
|
|
|
|
@upload="uploadImage"
|
|
|
|
/>
|
2024-10-19 04:33:32 -05:00
|
|
|
<v-spacer />
|
|
|
|
<v-select
|
|
|
|
v-model="recipe.userId"
|
2025-06-28 15:59:58 +02:00
|
|
|
class="my-2"
|
|
|
|
max-width="300"
|
2024-10-19 04:33:32 -05:00
|
|
|
:items="allUsers"
|
2025-06-28 15:59:58 +02:00
|
|
|
:item-props="itemsProps"
|
2025-06-20 00:09:12 +07:00
|
|
|
:label="$t('general.owner')"
|
2024-10-19 04:33:32 -05:00
|
|
|
:disabled="!canEditOwner"
|
2025-06-28 15:59:58 +02:00
|
|
|
variant="outlined"
|
|
|
|
density="compact"
|
2024-10-19 04:33:32 -05:00
|
|
|
>
|
|
|
|
<template #prepend>
|
2025-06-20 00:09:12 +07:00
|
|
|
<UserAvatar
|
|
|
|
:user-id="recipe.userId"
|
|
|
|
:tooltip="false"
|
|
|
|
/>
|
2024-10-19 04:33:32 -05:00
|
|
|
</template>
|
|
|
|
</v-select>
|
2025-06-28 15:59:58 +02:00
|
|
|
</div>
|
2022-08-27 10:44:58 -08:00
|
|
|
</template>
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
<script setup lang="ts">
|
|
|
|
import { computed } from "vue";
|
2024-11-07 11:43:07 -06:00
|
|
|
import { usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { NoUndefinedField } from "~/lib/api/types/non-generated";
|
|
|
|
import type { Recipe } from "~/lib/api/types/recipe";
|
2022-08-27 10:44:58 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
|
|
|
import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue";
|
|
|
|
import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue";
|
2024-10-19 04:33:32 -05:00
|
|
|
import { useUserStore } from "~/composables/store/use-user-store";
|
|
|
|
import UserAvatar from "~/components/Domain/User/UserAvatar.vue";
|
|
|
|
import { useHouseholdStore } from "~/composables/store";
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const recipe = defineModel<NoUndefinedField<Recipe>>({ required: true });
|
2024-10-19 04:33:32 -05:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const { user } = usePageUser();
|
|
|
|
const api = useUserApi();
|
|
|
|
const { imageKey } = usePageState(recipe.value.slug);
|
2024-10-19 04:33:32 -05:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const canEditOwner = computed(() => {
|
|
|
|
return user.id === recipe.value.userId || user.admin;
|
|
|
|
});
|
2022-08-27 10:44:58 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const { store: allUsers } = useUserStore();
|
|
|
|
const { store: households } = useHouseholdStore();
|
2025-06-28 15:59:58 +02:00
|
|
|
|
|
|
|
function itemsProps(item: any) {
|
|
|
|
const owner = allUsers.value.find(u => u.id === item.id);
|
|
|
|
return {
|
|
|
|
value: item.id,
|
|
|
|
title: item.fullName,
|
|
|
|
subtitle: owner ? households.value.find(h => h.id === owner.householdId)?.name || "" : "",
|
|
|
|
};
|
|
|
|
}
|
2025-06-20 00:09:12 +07:00
|
|
|
|
|
|
|
async function uploadImage(fileObject: File) {
|
|
|
|
if (!recipe.value || !recipe.value.slug) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
const newVersion = await api.recipes.updateImage(recipe.value.slug, fileObject);
|
|
|
|
if (newVersion?.data?.image) {
|
|
|
|
recipe.value.image = newVersion.data.image;
|
|
|
|
}
|
|
|
|
imageKey.value++;
|
|
|
|
}
|
2022-08-27 10:44:58 -08:00
|
|
|
</script>
|