2021-07-31 15:07:19 -08:00
|
|
|
<template>
|
|
|
|
<div class="text-center">
|
2021-11-04 18:15:23 -08:00
|
|
|
<v-menu v-model="menu" offset-y top nudge-top="6" :close-on-content-click="false">
|
2021-08-01 19:24:47 -08:00
|
|
|
<template #activator="{ on, attrs }">
|
2021-07-31 15:07:19 -08:00
|
|
|
<v-btn color="accent" dark v-bind="attrs" v-on="on">
|
|
|
|
<v-icon left>
|
|
|
|
{{ $globals.icons.fileImage }}
|
|
|
|
</v-icon>
|
|
|
|
{{ $t("general.image") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
<v-card width="400">
|
|
|
|
<v-card-title class="headline flex mb-0">
|
|
|
|
<div>
|
|
|
|
{{ $t("recipe.recipe-image") }}
|
|
|
|
</div>
|
2021-08-02 22:15:11 -08:00
|
|
|
<AppButtonUpload
|
2021-07-31 15:07:19 -08:00
|
|
|
class="ml-auto"
|
|
|
|
url="none"
|
|
|
|
file-name="image"
|
|
|
|
:text-btn="false"
|
|
|
|
:post="false"
|
2021-08-01 19:24:47 -08:00
|
|
|
@uploaded="uploadImage"
|
2021-07-31 15:07:19 -08:00
|
|
|
/>
|
|
|
|
</v-card-title>
|
|
|
|
<v-card-text class="mt-n5">
|
|
|
|
<div>
|
2022-01-09 07:15:23 +01:00
|
|
|
<v-text-field v-model="url" :label="$t('general.url')" class="pt-5" clearable :messages="messages">
|
2021-08-01 19:24:47 -08:00
|
|
|
<template #append-outer>
|
|
|
|
<v-btn class="ml-2" color="primary" :loading="loading" :disabled="!slug" @click="getImageFromURL">
|
2021-07-31 15:07:19 -08:00
|
|
|
{{ $t("general.get") }}
|
|
|
|
</v-btn>
|
|
|
|
</template>
|
|
|
|
</v-text-field>
|
|
|
|
</div>
|
|
|
|
</v-card-text>
|
|
|
|
</v-card>
|
|
|
|
</v-menu>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
<script lang="ts">
|
|
|
|
import { defineComponent, reactive, toRefs, useContext } from "@nuxtjs/composition-api";
|
2021-11-06 11:28:47 -08:00
|
|
|
import { useUserApi } from "~/composables/api";
|
2022-01-09 07:15:23 +01:00
|
|
|
|
2021-08-01 19:24:47 -08:00
|
|
|
const REFRESH_EVENT = "refresh";
|
|
|
|
const UPLOAD_EVENT = "upload";
|
2022-01-09 07:15:23 +01:00
|
|
|
|
2021-08-03 21:38:45 -08:00
|
|
|
export default defineComponent({
|
2021-07-31 15:07:19 -08:00
|
|
|
props: {
|
2021-08-03 21:38:45 -08:00
|
|
|
slug: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2022-01-09 07:15:23 +01:00
|
|
|
setup(props, context) {
|
|
|
|
const state = reactive({
|
|
|
|
url: "",
|
|
|
|
loading: false,
|
|
|
|
menu: false,
|
|
|
|
})
|
2021-08-03 21:38:45 -08:00
|
|
|
|
2022-01-09 07:15:23 +01:00
|
|
|
function uploadImage(fileObject: File) {
|
|
|
|
context.emit(UPLOAD_EVENT, fileObject);
|
|
|
|
state.menu = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const api = useUserApi();
|
|
|
|
async function getImageFromURL() {
|
|
|
|
state.loading = true;
|
|
|
|
if (await api.recipes.updateImagebyURL(props.slug, state.url)) {
|
|
|
|
context.emit(REFRESH_EVENT);
|
2021-07-31 15:07:19 -08:00
|
|
|
}
|
2022-01-09 07:15:23 +01:00
|
|
|
state.loading = false;
|
|
|
|
state.menu = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const { i18n } = useContext();
|
|
|
|
const messages = props.slug ? [""] : [i18n.t("recipe.save-recipe-before-use")];
|
|
|
|
|
|
|
|
return {
|
|
|
|
...toRefs(state),
|
|
|
|
uploadImage,
|
|
|
|
getImageFromURL,
|
|
|
|
messages,
|
|
|
|
};
|
2021-07-31 15:07:19 -08:00
|
|
|
},
|
2021-08-03 21:38:45 -08:00
|
|
|
});
|
2021-07-31 15:07:19 -08:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped></style>
|