2020-12-24 16:37:38 -09:00
|
|
|
<template>
|
|
|
|
<v-card :loading="isLoading">
|
|
|
|
<v-img v-if="image" height="400" :src="image">
|
|
|
|
<template v-slot:placeholder>
|
|
|
|
<v-row class="fill-height ma-0" align="center" justify="center">
|
|
|
|
<v-progress-circular
|
|
|
|
indeterminate
|
|
|
|
color="grey lighten-5"
|
|
|
|
></v-progress-circular>
|
|
|
|
</v-row>
|
|
|
|
</template>
|
|
|
|
</v-img>
|
|
|
|
<br v-else />
|
|
|
|
|
|
|
|
<ButtonRow
|
|
|
|
@json="jsonEditor = true"
|
|
|
|
@editor="jsonEditor = false"
|
|
|
|
@save="createRecipe"
|
|
|
|
/>
|
|
|
|
|
2021-01-03 10:02:02 -09:00
|
|
|
<div v-if="jsonEditor">
|
2021-01-03 12:09:22 -09:00
|
|
|
<!-- Probably not the best way, but it works! -->
|
2021-01-03 10:02:02 -09:00
|
|
|
<br />
|
|
|
|
<br />
|
|
|
|
<VJsoneditor
|
|
|
|
v-model="recipeDetails"
|
|
|
|
height="1500px"
|
|
|
|
:options="jsonEditorOptions"
|
|
|
|
/>
|
|
|
|
</div>
|
2020-12-24 16:37:38 -09:00
|
|
|
|
|
|
|
<EditRecipe v-else v-model="recipeDetails" @upload="getImage" />
|
|
|
|
</v-card>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import api from "../api";
|
|
|
|
|
|
|
|
import EditRecipe from "./RecipeEditor/EditRecipe";
|
|
|
|
import VJsoneditor from "v-jsoneditor";
|
|
|
|
import ButtonRow from "./UI/ButtonRow";
|
|
|
|
export default {
|
|
|
|
components: {
|
|
|
|
VJsoneditor,
|
|
|
|
EditRecipe,
|
|
|
|
ButtonRow,
|
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
isLoading: false,
|
|
|
|
fileObject: null,
|
|
|
|
selectedFile: null,
|
|
|
|
image: null,
|
|
|
|
jsonEditor: false,
|
|
|
|
jsonEditorOptions: {
|
|
|
|
mode: "code",
|
|
|
|
search: false,
|
|
|
|
mainMenuBar: false,
|
|
|
|
},
|
|
|
|
recipeDetails: {
|
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
image: "",
|
|
|
|
recipeYield: "",
|
|
|
|
recipeIngredient: [],
|
|
|
|
recipeInstructions: [],
|
|
|
|
slug: "",
|
|
|
|
filePath: "",
|
|
|
|
tags: [],
|
|
|
|
categories: [],
|
|
|
|
// dateAdded: "",
|
|
|
|
notes: [],
|
|
|
|
extras: [],
|
|
|
|
},
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
getImage(fileObject) {
|
|
|
|
this.fileObject = fileObject;
|
|
|
|
this.onFileChange();
|
|
|
|
},
|
|
|
|
onFileChange() {
|
|
|
|
this.image = URL.createObjectURL(this.fileObject);
|
|
|
|
},
|
|
|
|
async createRecipe() {
|
|
|
|
this.isLoading = true;
|
|
|
|
this.recipeDetails.image = this.fileObject.name;
|
|
|
|
let slug = await api.recipes.create(this.recipeDetails);
|
|
|
|
|
2021-01-03 10:02:02 -09:00
|
|
|
await api.recipes.updateImage(slug, this.fileObject);
|
2020-12-24 16:37:38 -09:00
|
|
|
this.isLoading = false;
|
|
|
|
|
|
|
|
this.$router.push(`/recipe/${slug}`);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.img-input {
|
|
|
|
position: absolute;
|
|
|
|
bottom: 0;
|
|
|
|
}
|
|
|
|
</style>
|