RecipeSettingsSwitches use v-model instead of prop and turn into script setup

This commit is contained in:
Kuchenpirat 2025-06-19 10:20:12 +00:00
commit 4ce1f5c926

View file

@ -1,9 +1,9 @@
<template> <template>
<div> <div>
<v-switch <v-switch
v-for="(_, key) in modelValue" v-for="(_, key) in model"
:key="key" :key="key"
v-model="modelValue[key]" v-model="model[key]"
color="primary" color="primary"
xs xs
density="compact" density="compact"
@ -15,23 +15,17 @@
</div> </div>
</template> </template>
<script lang="ts"> <script lang="ts" setup>
import { defineModel, defineProps } from "vue";
import type { RecipeSettings } from "~/lib/api/types/recipe"; import type { RecipeSettings } from "~/lib/api/types/recipe";
import { useI18n } from "#imports";
export default defineNuxtComponent({ defineProps<{ isOwner?: boolean }>();
props: {
modelValue: { const model = defineModel<RecipeSettings>({ required: true });
type: Object as () => RecipeSettings,
required: true, const i18n = useI18n();
}, const labels: Record<keyof RecipeSettings, string> = {
isOwner: {
type: Boolean,
required: false,
},
},
setup() {
const i18n = useI18n();
const labels: Record<keyof RecipeSettings, string> = {
public: i18n.t("recipe.public-recipe"), public: i18n.t("recipe.public-recipe"),
showNutrition: i18n.t("recipe.show-nutrition-values"), showNutrition: i18n.t("recipe.show-nutrition-values"),
showAssets: i18n.t("asset.show-assets"), showAssets: i18n.t("asset.show-assets"),
@ -39,13 +33,7 @@ export default defineNuxtComponent({
disableComments: i18n.t("recipe.disable-comments"), disableComments: i18n.t("recipe.disable-comments"),
disableAmount: i18n.t("recipe.disable-amount"), disableAmount: i18n.t("recipe.disable-amount"),
locked: i18n.t("recipe.locked"), locked: i18n.t("recipe.locked"),
}; };
return {
labels,
};
},
});
</script> </script>
<style lang="scss" scoped></style> <style lang="scss" scoped></style>