mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-08-05 21:45:25 +02:00
feat: Migrate to Nuxt 3 framework (#5184)
Co-authored-by: Michael Genson <71845777+michael-genson@users.noreply.github.com> Co-authored-by: Kuchenpirat <24235032+Kuchenpirat@users.noreply.github.com>
This commit is contained in:
parent
89ab7fac25
commit
c24d532608
403 changed files with 23959 additions and 19557 deletions
|
@ -1,28 +1,44 @@
|
|||
<template>
|
||||
<div class="d-flex justify-start align-top py-2">
|
||||
<RecipeImageUploadBtn class="my-1" :slug="recipe.slug" @upload="uploadImage" @refresh="imageKey++" />
|
||||
<RecipeImageUploadBtn
|
||||
class="my-1"
|
||||
:slug="recipe.slug"
|
||||
@upload="uploadImage"
|
||||
@refresh="imageKey++"
|
||||
/>
|
||||
<RecipeSettingsMenu
|
||||
v-model="recipe.settings"
|
||||
class="my-1 mx-1"
|
||||
:value="recipe.settings"
|
||||
:is-owner="recipe.userId == user.id"
|
||||
@upload="uploadImage"
|
||||
/>
|
||||
<v-spacer />
|
||||
<v-container class="py-0" style="width: 40%;">
|
||||
<v-container
|
||||
class="py-0"
|
||||
style="width: 40%;"
|
||||
>
|
||||
<v-select
|
||||
v-model="recipe.userId"
|
||||
:items="allUsers"
|
||||
item-text="fullName"
|
||||
item-title="fullName"
|
||||
item-value="id"
|
||||
:label="$tc('general.owner')"
|
||||
:label="$t('general.owner')"
|
||||
hide-details
|
||||
:disabled="!canEditOwner"
|
||||
variant="underlined"
|
||||
>
|
||||
<template #prepend>
|
||||
<UserAvatar :user-id="recipe.userId" :tooltip="false" />
|
||||
<UserAvatar
|
||||
:user-id="recipe.userId"
|
||||
:tooltip="false"
|
||||
/>
|
||||
</template>
|
||||
</v-select>
|
||||
<v-card-text v-if="ownerHousehold" class="pa-0 d-flex" style="align-items: flex-end;">
|
||||
<v-card-text
|
||||
v-if="ownerHousehold"
|
||||
class="pa-0 d-flex"
|
||||
style="align-items: flex-end;"
|
||||
>
|
||||
<v-spacer />
|
||||
<v-icon>{{ $globals.icons.household }}</v-icon>
|
||||
<span class="pl-1">{{ ownerHousehold.name }}</span>
|
||||
|
@ -31,11 +47,11 @@
|
|||
</div>
|
||||
</template>
|
||||
|
||||
<script lang="ts">
|
||||
import { computed, defineComponent } from "@nuxtjs/composition-api";
|
||||
<script setup lang="ts">
|
||||
import { computed } from "vue";
|
||||
import { usePageState, usePageUser } from "~/composables/recipe-page/shared-state";
|
||||
import { NoUndefinedField } from "~/lib/api/types/non-generated";
|
||||
import { Recipe } from "~/lib/api/types/recipe";
|
||||
import type { NoUndefinedField } from "~/lib/api/types/non-generated";
|
||||
import type { Recipe } from "~/lib/api/types/recipe";
|
||||
import { useUserApi } from "~/composables/api";
|
||||
import RecipeImageUploadBtn from "~/components/Domain/Recipe/RecipeImageUploadBtn.vue";
|
||||
import RecipeSettingsMenu from "~/components/Domain/Recipe/RecipeSettingsMenu.vue";
|
||||
|
@ -43,57 +59,34 @@ import { useUserStore } from "~/composables/store/use-user-store";
|
|||
import UserAvatar from "~/components/Domain/User/UserAvatar.vue";
|
||||
import { useHouseholdStore } from "~/composables/store";
|
||||
|
||||
export default defineComponent({
|
||||
components: {
|
||||
RecipeImageUploadBtn,
|
||||
RecipeSettingsMenu,
|
||||
UserAvatar,
|
||||
},
|
||||
props: {
|
||||
recipe: {
|
||||
type: Object as () => NoUndefinedField<Recipe>,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
setup(props) {
|
||||
const { user } = usePageUser();
|
||||
const api = useUserApi();
|
||||
const { imageKey } = usePageState(props.recipe.slug);
|
||||
const recipe = defineModel<NoUndefinedField<Recipe>>({ required: true });
|
||||
|
||||
const canEditOwner = computed(() => {
|
||||
return user.id === props.recipe.userId || user.admin;
|
||||
})
|
||||
const { user } = usePageUser();
|
||||
const api = useUserApi();
|
||||
const { imageKey } = usePageState(recipe.value.slug);
|
||||
|
||||
const { store: allUsers } = useUserStore();
|
||||
const { store: households } = useHouseholdStore();
|
||||
const ownerHousehold = computed(() => {
|
||||
const owner = allUsers.value.find((u) => u.id === props.recipe.userId);
|
||||
if (!owner) {
|
||||
return null;
|
||||
};
|
||||
|
||||
return households.value.find((h) => h.id === owner.householdId);
|
||||
});
|
||||
|
||||
async function uploadImage(fileObject: File) {
|
||||
if (!props.recipe || !props.recipe.slug) {
|
||||
return;
|
||||
}
|
||||
const newVersion = await api.recipes.updateImage(props.recipe.slug, fileObject);
|
||||
if (newVersion?.data?.image) {
|
||||
props.recipe.image = newVersion.data.image;
|
||||
}
|
||||
imageKey.value++;
|
||||
}
|
||||
|
||||
return {
|
||||
user,
|
||||
canEditOwner,
|
||||
uploadImage,
|
||||
imageKey,
|
||||
allUsers,
|
||||
ownerHousehold,
|
||||
};
|
||||
},
|
||||
const canEditOwner = computed(() => {
|
||||
return user.id === recipe.value.userId || user.admin;
|
||||
});
|
||||
|
||||
const { store: allUsers } = useUserStore();
|
||||
const { store: households } = useHouseholdStore();
|
||||
const ownerHousehold = computed(() => {
|
||||
const owner = allUsers.value.find(u => u.id === recipe.value.userId);
|
||||
if (!owner) {
|
||||
return null;
|
||||
}
|
||||
return households.value.find(h => h.id === owner.householdId);
|
||||
});
|
||||
|
||||
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++;
|
||||
}
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue