diff --git a/src/lib/builderForm/BuilderForm.svelte b/src/lib/builderForm/BuilderForm.svelte index dd615c6..5932bb7 100644 --- a/src/lib/builderForm/BuilderForm.svelte +++ b/src/lib/builderForm/BuilderForm.svelte @@ -10,7 +10,9 @@ import DescriptionTerm from '$lib/List/DescriptionTerm.svelte'; import ListItem from '$lib/List/ListItem.svelte'; import UnorderedList from '$lib/List/UnorderedList.svelte'; + import Recipe from '$lib/recipes/Recipe.svelte'; import { currentBuilderStatus } from '$lib/stores.js'; + import { onMount } from 'svelte'; let name: string = $currentBuilderStatus.name; let author: AuthorInterface = $currentBuilderStatus.author; @@ -81,9 +83,36 @@ input.ingredients = ingredientList; input.instructions = instructionList; console.log(input); + localStorage.setItem('recipe', JSON.stringify(input)); + console.log(`hey did this write to local storage: ${localStorage.getItem('recipe')}`); updateCurrentBuilderRecipe(input); }; + const onReset = () => { + currentBuilderStatus.set({ + name: '', + author: { name: '', reference: '' }, + description: '', + totalTime: 0, + keywords: [], + yield: '', + category: '', + cuisine: '', + nutrition: { + calories: '' + }, + ingredients: [], + instructions: [] + }); + name = ''; + author = { name: '', reference: '' }; + description = ''; + keywordList = []; + ingredientList = []; + instructionList = []; + recipeYield = ''; + }; + // uses "as any" due to some weird ts issue, fix later i guess const updateCurrentBuilderRecipe = (input: any) => { currentBuilderStatus.set({ @@ -104,6 +133,14 @@ console.log(currentBuilderStatus); goto('/builder/your-recipe'); }; + + onMount(async () => { + if (localStorage.getItem('recipe')) { + console.log(localStorage.getItem('recipe')); + } else { + onReset(); + } + });
@@ -307,7 +344,7 @@
- +
diff --git a/src/routes/builder/your-recipe.svelte b/src/routes/builder/your-recipe.svelte index b95ed26..b2081a6 100644 --- a/src/routes/builder/your-recipe.svelte +++ b/src/routes/builder/your-recipe.svelte @@ -35,13 +35,18 @@ // const result = json; hasSubmittedRecipe = true; } + + const editRecipe = () => { + console.log('I go edit'); + console.log(localStorage.getItem('recipe')); + goto('/builder'); + }; your recipe | twotop - {#if !hasSubmittedRecipe}
{#if !$isAuthenticated} @@ -54,7 +59,7 @@ {#if $isAuthenticated} {/if} - + {:else} No recipe built, redirecting