This commit is contained in:
2023-06-27 19:01:06 +02:00
parent 32777ada0e
commit 6708bfc89c
10 changed files with 118 additions and 23 deletions

View File

@ -8,11 +8,23 @@
let addendum = ""
import { season } from '$lib/js/season_store';
import { portions } from '$lib/js/portions_store';
import { img } from '$lib/js/img_store';
season.update(() => [])
let season_local
season.subscribe((s) => {
season_local = s
});
let portions_local
portions.update(() => "")
portions.subscribe((p) => {
portions_local = p});
let img_local
img.update(() => "")
img.subscribe((i) => {
img_local = i});
export let card_data ={
icon: "",
@ -33,13 +45,12 @@
mode: "",
},
total_time: "",
cooking: "",
}
let password = ""
let images = []
export let portions = ""
let short_name = ""
let password
let datecreated = new Date()
let datemodified = datecreated
@ -70,7 +81,28 @@
}
}
async function upload_img(){
console.log("uploading...")
console.log(img_local)
const data = {
image: img_local,
filename: short_name + '.webp',
bearer: password,
}
await fetch(`/api/img/add`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
bearer: password,
},
body: JSON.stringify(data)
});
}
async function doPost () {
upload_img()
console.log(add_info.total_time)
const res = await fetch('/api/add', {
method: 'POST',
@ -81,6 +113,7 @@
images: {mediapath: short_name + '.webp', alt: "", caption: ""}, // TODO
season: season_local,
short_name,
portions: portions_local,
datecreated,
datemodified,
instructions,
@ -221,7 +254,7 @@ h3{
<div class=list_wrapper>
<div>
<CreateIngredientList {ingredients} {portions}></CreateIngredientList>
<CreateIngredientList {ingredients}></CreateIngredientList>
</div>
<div>
<CreateStepList {instructions} {add_info}></CreateStepList>

View File

@ -10,6 +10,14 @@
let addendum = data.recipe.addendum
import { season } from '$lib/js/season_store';
import { portions } from '$lib/js/portions_store';
portions.update(() => data.recipe.portions)
let portions_local
portions.subscribe((p) => {
portions_local = p
});
season.update(() => data.recipe.season)
let season_local
season.subscribe((s) => {
@ -37,10 +45,10 @@
mode: data.recipe.baking.mode,
},
total_time: data.recipe.total_time,
cooking: data.recipe.cooking,
}
let images = data.recipe.images
export let portions = data.recipe.portions
let short_name = data.recipe.short_name
let password
@ -102,6 +110,7 @@
season: season_local,
short_name,
datecreated,
portions: portions_local,
datemodified,
instructions,
ingredients,
@ -247,7 +256,7 @@ h3{
<div class=list_wrapper>
<div>
<CreateIngredientList {ingredients} {portions}></CreateIngredientList>
<CreateIngredientList {ingredients}></CreateIngredientList>
</div>
<div>
<CreateStepList {instructions} {add_info}></CreateStepList>

View File

@ -1,11 +1,41 @@
<script lang="ts">
import TitleImgParallax from "$lib/components/TitleImgParallax.svelte";
<script lang=ts>
let fileInput;
let files;
let temp
let image : String;
let base64
export function store_img_base64(image) {
const reader = new FileReader();
reader.readAsDataURL(image);
reader.onload = e => {
base64 = e.target.result.split(',')[1];
//base64 = temp.split(',')[1]
};
};
export async function upload(){
console.log("uploading...")
const data = {
image: base64,
filename: "test.webp"
}
await fetch(`/api/img/add`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify(data)
});
}
</script>
<input id="file-to-upload" type="file" accept=".png,.jpg,.webp" bind:files bind:this={fileInput} on:change={() => store_img_base64(files[0])}/>
<button class="upload-btn" on:click="{upload}">Upload</button>
<button on:click={console.log(base64)}></button>
<style>
div{
transform: translateY(-1rem);
}
</style>
<div>
<TitleImgParallax></TitleImgParallax>
</div>