2023-06-19 20:38:45 +02:00
|
|
|
<script lang="ts">
|
2023-06-24 15:31:10 +02:00
|
|
|
import Check from '$lib/assets/icons/Check.svelte';
|
|
|
|
import SeasonSelect from '$lib/components/SeasonSelect.svelte';
|
|
|
|
import '$lib/css/action_button.css'
|
|
|
|
|
|
|
|
let preamble = ""
|
|
|
|
let addendum = ""
|
|
|
|
|
|
|
|
import { season } from '$lib/js/season_store';
|
2023-06-27 19:01:06 +02:00
|
|
|
import { portions } from '$lib/js/portions_store';
|
|
|
|
import { img } from '$lib/js/img_store';
|
2023-06-24 15:31:10 +02:00
|
|
|
season.update(() => [])
|
|
|
|
let season_local
|
|
|
|
season.subscribe((s) => {
|
|
|
|
season_local = s
|
|
|
|
});
|
2023-06-27 19:01:06 +02:00
|
|
|
let portions_local
|
|
|
|
portions.update(() => "")
|
|
|
|
portions.subscribe((p) => {
|
|
|
|
portions_local = p});
|
|
|
|
let img_local
|
|
|
|
img.update(() => "")
|
|
|
|
img.subscribe((i) => {
|
|
|
|
img_local = i});
|
|
|
|
|
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
|
2023-06-23 17:23:14 +02:00
|
|
|
export let card_data ={
|
2023-06-24 15:31:10 +02:00
|
|
|
icon: "",
|
|
|
|
category: "",
|
|
|
|
name: "",
|
|
|
|
description: "",
|
|
|
|
tags: [],
|
|
|
|
}
|
|
|
|
export let add_info ={
|
|
|
|
preparation: "",
|
|
|
|
fermentation: {
|
|
|
|
bulk: "",
|
|
|
|
final: "",
|
|
|
|
},
|
|
|
|
baking: {
|
|
|
|
length: "",
|
|
|
|
temperature: "",
|
|
|
|
mode: "",
|
|
|
|
},
|
|
|
|
total_time: "",
|
2023-06-27 19:01:06 +02:00
|
|
|
cooking: "",
|
2023-06-23 17:23:14 +02:00
|
|
|
}
|
2023-06-24 15:31:10 +02:00
|
|
|
|
2023-06-27 19:01:06 +02:00
|
|
|
let password = ""
|
2023-06-24 15:31:10 +02:00
|
|
|
let images = []
|
|
|
|
let short_name = ""
|
|
|
|
let datecreated = new Date()
|
2023-06-19 20:38:45 +02:00
|
|
|
let datemodified = datecreated
|
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
import type { PageData } from './$types';
|
2023-06-21 19:50:27 +02:00
|
|
|
import CardAdd from '$lib/components/CardAdd.svelte';
|
2023-06-23 17:23:14 +02:00
|
|
|
|
2023-06-22 20:26:48 +02:00
|
|
|
import CreateIngredientList from '$lib/components/CreateIngredientList.svelte';
|
2023-06-23 17:23:14 +02:00
|
|
|
export let ingredients = []
|
|
|
|
|
2023-06-22 20:26:48 +02:00
|
|
|
import CreateStepList from '$lib/components/CreateStepList.svelte';
|
2023-06-23 17:23:14 +02:00
|
|
|
export let instructions = []
|
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
|
|
|
|
function get_season(){
|
|
|
|
let season = []
|
|
|
|
const el = document.getElementById("labels");
|
|
|
|
for(var i = 0; i < el.children.length; i++){
|
|
|
|
if(el.children[i].children[0].children[0].checked){
|
|
|
|
season.push(i+1)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return season
|
|
|
|
}
|
|
|
|
function write_season(season){
|
|
|
|
const el = document.getElementById("labels");
|
|
|
|
for(var i = 0; i < season.length; i++){
|
|
|
|
el.children[i].children[0].children[0].checked = true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-06-27 19:01:06 +02:00
|
|
|
async function upload_img(){
|
|
|
|
console.log("uploading...")
|
|
|
|
console.log(img_local)
|
|
|
|
const data = {
|
|
|
|
image: img_local,
|
2023-07-11 22:54:13 +02:00
|
|
|
name: short_name,
|
2023-06-27 19:01:06 +02:00
|
|
|
bearer: password,
|
|
|
|
}
|
|
|
|
await fetch(`/api/img/add`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
Accept: 'application/json',
|
|
|
|
bearer: password,
|
|
|
|
},
|
|
|
|
body: JSON.stringify(data)
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-06-19 20:38:45 +02:00
|
|
|
async function doPost () {
|
2023-06-27 19:01:06 +02:00
|
|
|
|
|
|
|
upload_img()
|
2023-06-24 15:31:10 +02:00
|
|
|
console.log(add_info.total_time)
|
2023-06-19 20:38:45 +02:00
|
|
|
const res = await fetch('/api/add', {
|
|
|
|
method: 'POST',
|
|
|
|
body: JSON.stringify({
|
|
|
|
recipe: {
|
2023-06-23 17:23:14 +02:00
|
|
|
...card_data,
|
2023-06-24 15:31:10 +02:00
|
|
|
...add_info,
|
|
|
|
images: {mediapath: short_name + '.webp', alt: "", caption: ""}, // TODO
|
|
|
|
season: season_local,
|
2023-06-19 20:38:45 +02:00
|
|
|
short_name,
|
2023-06-27 19:01:06 +02:00
|
|
|
portions: portions_local,
|
2023-06-19 20:38:45 +02:00
|
|
|
datecreated,
|
|
|
|
datemodified,
|
2023-06-23 17:23:14 +02:00
|
|
|
instructions,
|
|
|
|
ingredients,
|
2023-06-24 15:31:10 +02:00
|
|
|
preamble,
|
|
|
|
addendum,
|
2023-06-19 20:38:45 +02:00
|
|
|
},
|
|
|
|
headers: {
|
|
|
|
'content-type': 'application/json',
|
2023-06-23 17:23:14 +02:00
|
|
|
bearer: password,
|
2023-06-19 20:38:45 +02:00
|
|
|
}
|
|
|
|
})
|
2023-07-02 23:39:31 +02:00
|
|
|
});
|
|
|
|
if(res.status === 200){
|
|
|
|
const url = location.href.split('/')
|
|
|
|
url.splice(url.length -1, 1);
|
|
|
|
url.push(short_name)
|
|
|
|
location.assign(url.join('/'))
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
const item = await res.json();
|
|
|
|
alert(item.message)
|
|
|
|
}
|
2023-06-19 20:38:45 +02:00
|
|
|
|
|
|
|
}
|
2023-06-24 15:31:10 +02:00
|
|
|
|
2023-06-19 20:38:45 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
2023-06-24 15:31:10 +02:00
|
|
|
input{
|
2023-06-19 20:38:45 +02:00
|
|
|
display: block;
|
2023-06-24 15:31:10 +02:00
|
|
|
border: unset;
|
2023-06-23 17:23:14 +02:00
|
|
|
margin: 1rem auto;
|
2023-06-24 15:31:10 +02:00
|
|
|
padding: 0.5em 1em;
|
2023-06-21 19:50:27 +02:00
|
|
|
border-radius: 1000px;
|
|
|
|
background-color: var(--nord4);
|
2023-06-24 15:31:10 +02:00
|
|
|
font-size: 1.1rem;
|
|
|
|
transition: 100ms;
|
2023-06-21 19:50:27 +02:00
|
|
|
|
2023-06-19 20:38:45 +02:00
|
|
|
}
|
2023-06-24 15:31:10 +02:00
|
|
|
input:hover,
|
|
|
|
input:focus-visible
|
|
|
|
{
|
|
|
|
scale: 1.05 1.05;
|
|
|
|
}
|
|
|
|
.list_wrapper{
|
|
|
|
margin-inline: auto;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: row;
|
|
|
|
max-width: 1000px;
|
|
|
|
gap: 2rem;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
@media screen and (max-width: 700px){
|
|
|
|
.list_wrapper{
|
|
|
|
flex-direction: column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
input[type=password]{
|
|
|
|
box-sizing: border-box;
|
|
|
|
font-size: 1.5rem;
|
|
|
|
padding-block: 0.5em;
|
|
|
|
display: inline;
|
|
|
|
width: 100%;
|
|
|
|
}
|
|
|
|
.submit_wrapper{
|
|
|
|
position: relative;
|
|
|
|
margin-inline: auto;
|
|
|
|
width: max(300px, 50vw)
|
|
|
|
}
|
|
|
|
.submit_wrapper button{
|
|
|
|
position: absolute;
|
|
|
|
right:-1em;
|
|
|
|
bottom: -0.5em;
|
|
|
|
}
|
|
|
|
.submit_wrapper h2{
|
|
|
|
margin-bottom: 0;
|
|
|
|
}
|
|
|
|
h1{
|
|
|
|
text-align: center;
|
|
|
|
margin-bottom: 2rem;
|
|
|
|
}
|
|
|
|
.title_container{
|
|
|
|
max-width: 1000px;
|
|
|
|
display: flex;
|
|
|
|
flex-direction: column;
|
|
|
|
margin-inline: auto;
|
|
|
|
}
|
|
|
|
.title{
|
|
|
|
position: relative;
|
|
|
|
width: min(800px, 80vw);
|
|
|
|
margin-block: 2rem;
|
|
|
|
margin-inline: auto;
|
|
|
|
background-color: var(--nord6);
|
|
|
|
padding: 1rem 2rem;
|
|
|
|
}
|
|
|
|
.title p{
|
|
|
|
border: 2px solid var(--nord1);
|
|
|
|
border-radius: 10000px;
|
|
|
|
padding: 0.5em 1em;
|
|
|
|
font-size: 1.1rem;
|
|
|
|
transition: 200ms;
|
|
|
|
}
|
|
|
|
.title p:hover,
|
|
|
|
.title p:focus-within{
|
|
|
|
scale: 1.02 1.02;
|
|
|
|
}
|
|
|
|
.addendum{
|
|
|
|
font-size: 1.1rem;
|
|
|
|
max-width: 90%;
|
|
|
|
margin-inline: auto;
|
|
|
|
border: 2px solid var(--nord1);
|
|
|
|
border-radius: 45px;
|
|
|
|
padding: 1em 1em;
|
|
|
|
transition: 100ms;
|
|
|
|
}
|
|
|
|
.addendum:hover,
|
|
|
|
.addendum:focus-within
|
|
|
|
{
|
|
|
|
scale: 1.02 1.02;
|
|
|
|
}
|
|
|
|
.addendum_wrapper{
|
|
|
|
max-width: 1000px;
|
|
|
|
margin-inline: auto;
|
|
|
|
}
|
|
|
|
h3{
|
|
|
|
text-align: center;
|
|
|
|
}
|
2023-06-19 20:38:45 +02:00
|
|
|
</style>
|
2023-06-24 15:31:10 +02:00
|
|
|
<h1>Rezept erstellen</h1>
|
2023-06-19 20:38:45 +02:00
|
|
|
|
2023-06-23 17:23:14 +02:00
|
|
|
<CardAdd {card_data}></CardAdd>
|
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
<h3>Kurzname (für URL):</h3>
|
|
|
|
<input bind:value={short_name} placeholder="Kurzname"/>
|
|
|
|
|
|
|
|
<div class=title_container>
|
|
|
|
<div class=title>
|
|
|
|
<h4>Eine etwas längere Beschreibung:</h4>
|
|
|
|
<p bind:innerText={preamble} contenteditable></p>
|
|
|
|
<div class=tags>
|
|
|
|
<h4>Saison:</h4>
|
|
|
|
<SeasonSelect></SeasonSelect>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-23 17:23:14 +02:00
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
<div class=list_wrapper>
|
|
|
|
<div>
|
2023-06-27 19:01:06 +02:00
|
|
|
<CreateIngredientList {ingredients}></CreateIngredientList>
|
2023-06-24 15:31:10 +02:00
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<CreateStepList {instructions} {add_info}></CreateStepList>
|
|
|
|
</div>
|
|
|
|
</div>
|
2023-06-23 17:23:14 +02:00
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
<div class=addendum_wrapper>
|
|
|
|
<h3>Nachtrag:</h3>
|
|
|
|
<div class=addendum bind:innerText={addendum} contenteditable></div>
|
|
|
|
</div>
|
2023-06-19 20:38:45 +02:00
|
|
|
|
2023-06-24 15:31:10 +02:00
|
|
|
<div class=submit_wrapper>
|
|
|
|
<h2>Neues Rezept hinzufügen:</h2>
|
|
|
|
<input type="password" placeholder=Passwort bind:value={password}>
|
|
|
|
<button class=action_button on:click={doPost}><Check fill=white width=2rem height=2rem></Check></button>
|
|
|
|
</div>
|