mirror of
https://github.com/mealie-recipes/mealie.git
synced 2025-12-15 06:45:23 -05:00
feat: Optionally include URL when importing via HTML/JSON (#6709)
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
<template>
|
||||
<v-form
|
||||
ref="domUrlForm"
|
||||
@submit.prevent="createFromHtmlOrJson(newRecipeData, importKeywordsAsTags)"
|
||||
@submit.prevent="createFromHtmlOrJson(newRecipeData, importKeywordsAsTags, newRecipeUrl)"
|
||||
>
|
||||
<div>
|
||||
<v-card-title class="headline">
|
||||
@@ -21,14 +21,28 @@
|
||||
<v-switch
|
||||
v-model="isEditJSON"
|
||||
:label="$t('recipe.json-editor')"
|
||||
color="primary"
|
||||
class="mt-2"
|
||||
@change="handleIsEditJson"
|
||||
/>
|
||||
<v-text-field
|
||||
v-model="newRecipeUrl"
|
||||
:label="$t('new-recipe.recipe-url')"
|
||||
:prepend-inner-icon="$globals.icons.link"
|
||||
validate-on="blur"
|
||||
variant="solo-filled"
|
||||
clearable
|
||||
rounded
|
||||
:rules="[validators.urlOptional]"
|
||||
:hint="$t('new-recipe.copy-and-paste-the-source-url-of-your-data-optional')"
|
||||
persistent-hint
|
||||
class="mt-10 mb-4"
|
||||
style="max-width: 500px"
|
||||
/>
|
||||
<RecipeJsonEditor
|
||||
v-if="isEditJSON"
|
||||
v-model="newRecipeData"
|
||||
height="250px"
|
||||
class="mt-10"
|
||||
mode="code"
|
||||
:main-menu-bar="false"
|
||||
/>
|
||||
@@ -41,10 +55,7 @@
|
||||
autofocus
|
||||
variant="solo-filled"
|
||||
clearable
|
||||
class="rounded-lg mt-2"
|
||||
rounded
|
||||
:hint="$t('new-recipe.url-form-hint')"
|
||||
persistent-hint
|
||||
/>
|
||||
<v-checkbox
|
||||
v-model="importKeywordsAsTags"
|
||||
@@ -124,6 +135,7 @@ export default defineNuxtComponent({
|
||||
}
|
||||
|
||||
const newRecipeData = ref<string | object | null>(null);
|
||||
const newRecipeUrl = ref<string | null>(null);
|
||||
|
||||
function handleIsEditJson() {
|
||||
if (state.isEditJSON) {
|
||||
@@ -148,8 +160,13 @@ export default defineNuxtComponent({
|
||||
}
|
||||
handleIsEditJson();
|
||||
|
||||
async function createFromHtmlOrJson(htmlOrJsonData: string | object | null, importKeywordsAsTags: boolean) {
|
||||
if (!htmlOrJsonData || !domUrlForm.value?.validate()) {
|
||||
async function createFromHtmlOrJson(htmlOrJsonData: string | object | null, importKeywordsAsTags: boolean, url: string | null = null) {
|
||||
if (!htmlOrJsonData) {
|
||||
return;
|
||||
}
|
||||
|
||||
const isValid = await domUrlForm.value?.validate();
|
||||
if (!isValid?.valid) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -162,7 +179,7 @@ export default defineNuxtComponent({
|
||||
}
|
||||
|
||||
state.loading = true;
|
||||
const { response } = await api.recipes.createOneByHtmlOrJson(dataString, importKeywordsAsTags);
|
||||
const { response } = await api.recipes.createOneByHtmlOrJson(dataString, importKeywordsAsTags, url);
|
||||
handleResponse(response, importKeywordsAsTags);
|
||||
}
|
||||
|
||||
@@ -172,6 +189,7 @@ export default defineNuxtComponent({
|
||||
stayInEditMode,
|
||||
parseRecipe,
|
||||
newRecipeData,
|
||||
newRecipeUrl,
|
||||
handleIsEditJson,
|
||||
createFromHtmlOrJson,
|
||||
...toRefs(state),
|
||||
|
||||
Reference in New Issue
Block a user