homepage/src/routes/rezepte/add/+page.svelte

77 lines
1.6 KiB
Svelte
Raw Normal View History

2023-06-19 20:38:45 +02:00
<script lang="ts">
export let card_data ={
}
let short_name
let password
2023-06-19 20:38:45 +02:00
let datecreated = new Date()
let datemodified = datecreated
import CardAdd from '$lib/components/CardAdd.svelte';
import SeasonSelect from '$lib/components/SeasonSelect.svelte';
export let season = []
import CreateIngredientList from '$lib/components/CreateIngredientList.svelte';
export let ingredients = []
import CreateStepList from '$lib/components/CreateStepList.svelte';
export let instructions = []
2023-06-19 20:38:45 +02:00
async function doPost () {
const res = await fetch('/api/add', {
method: 'POST',
body: JSON.stringify({
recipe: {
season: get_season(),
...card_data,
images: [{
mediapath: short_name + '.webp',
alt: "",
caption: ""
}],
2023-06-19 20:38:45 +02:00
short_name,
datecreated,
datemodified,
instructions,
ingredients,
2023-06-19 20:38:45 +02:00
},
headers: {
'content-type': 'application/json',
bearer: password,
2023-06-19 20:38:45 +02:00
}
})
})
const json = await res.json()
result = JSON.stringify(json)
console.log(result)
}
</script>
<style>
input.temp{
all: unset;
2023-06-19 20:38:45 +02:00
display: block;
margin: 1rem auto;
padding: 0.2em 1em;
border-radius: 1000px;
background-color: var(--nord4);
2023-06-19 20:38:45 +02:00
}
</style>
<h1>Rezept hinzufügen</h1>
<CardAdd {card_data}></CardAdd>
<input class=temp bind:value={short_name} placeholder="Kurzname"/>
<SeasonSelect {season}></SeasonSelect>
2023-06-19 20:38:45 +02:00
<h2>Zutaten</h2>
<CreateIngredientList {ingredients}></CreateIngredientList>
<h2>Zubereitung</h2>
<CreateStepList {instructions} ></CreateStepList>
<input class=temp type="password" placeholder=Passwort bind:value={password}>
<button on:click={doPost}>ADD RECIPE</button>