|
@@ -4,11 +4,13 @@
|
|
|
|
|
|
|
|
let nameInput, quantityInput, stepsInput;
|
|
let nameInput, quantityInput, stepsInput;
|
|
|
let {
|
|
let {
|
|
|
|
|
+ id,
|
|
|
name,
|
|
name,
|
|
|
ingredients: ingredientsProp,
|
|
ingredients: ingredientsProp,
|
|
|
steps: stepsProp,
|
|
steps: stepsProp,
|
|
|
notes,
|
|
notes,
|
|
|
- visibility
|
|
|
|
|
|
|
+ visibility,
|
|
|
|
|
+ route
|
|
|
} = $props();
|
|
} = $props();
|
|
|
let ingredients = $state(ingredientsProp);
|
|
let ingredients = $state(ingredientsProp);
|
|
|
let steps = $state(stepsProp);
|
|
let steps = $state(stepsProp);
|
|
@@ -16,7 +18,6 @@
|
|
|
let unit = $state("");
|
|
let unit = $state("");
|
|
|
let ingredientName = $state("");
|
|
let ingredientName = $state("");
|
|
|
let stepString = $state("");
|
|
let stepString = $state("");
|
|
|
- $inspect(ingredients);
|
|
|
|
|
|
|
|
|
|
const submit = async (event)=>{
|
|
const submit = async (event)=>{
|
|
|
event.preventDefault();
|
|
event.preventDefault();
|
|
@@ -32,7 +33,7 @@
|
|
|
private: visibility === "private" ? true : false
|
|
private: visibility === "private" ? true : false
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
- const response = await fetch("/recipe/new", {
|
|
|
|
|
|
|
+ const response = await fetch(route, {
|
|
|
method: "POST",
|
|
method: "POST",
|
|
|
headers: {"Content-Type": "application/json"},
|
|
headers: {"Content-Type": "application/json"},
|
|
|
credentials: "include",
|
|
credentials: "include",
|
|
@@ -42,7 +43,8 @@
|
|
|
const recipe = await response.json();
|
|
const recipe = await response.json();
|
|
|
if(!response.ok) return notify("error", recipe.message);
|
|
if(!response.ok) return notify("error", recipe.message);
|
|
|
|
|
|
|
|
- goto("/dashboard");
|
|
|
|
|
|
|
+ let redirect = route === "/recipe/new" ? "/dashboard" : `/recipe/${id}`;
|
|
|
|
|
+ goto(redirect);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const addIngredient = ()=>{
|
|
const addIngredient = ()=>{
|
|
@@ -146,7 +148,13 @@
|
|
|
</div>
|
|
</div>
|
|
|
</fieldset>
|
|
</fieldset>
|
|
|
|
|
|
|
|
- <button>Create Recipe</button>
|
|
|
|
|
|
|
+ <button>
|
|
|
|
|
+ {#if route === "/recipe/new"}
|
|
|
|
|
+ Create Recipe
|
|
|
|
|
+ {:else}
|
|
|
|
|
+ Update Recipe
|
|
|
|
|
+ {/if}
|
|
|
|
|
+ </button>
|
|
|
</form>
|
|
</form>
|
|
|
|
|
|
|
|
<style>
|
|
<style>
|
|
@@ -431,10 +439,6 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@media (min-width: 640px){
|
|
@media (min-width: 640px){
|
|
|
- .container{
|
|
|
|
|
- padding: 2rem 1rem 3rem;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
.standardForm{
|
|
.standardForm{
|
|
|
padding: 2rem;
|
|
padding: 2rem;
|
|
|
}
|
|
}
|
|
@@ -445,11 +449,6 @@
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@media (max-height: 500px){
|
|
@media (max-height: 500px){
|
|
|
- .container{
|
|
|
|
|
- padding-top: 0.75rem;
|
|
|
|
|
- padding-bottom: 1rem;
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
.standardForm > textarea{
|
|
.standardForm > textarea{
|
|
|
min-height: 3.5rem;
|
|
min-height: 3.5rem;
|
|
|
}
|
|
}
|