diff --git a/src/app.html b/src/app.html index 4f8cd23..cda1768 100644 --- a/src/app.html +++ b/src/app.html @@ -2,7 +2,7 @@ - + .input-field { - @apply border border-gray-400 w-12 p-1 rounded; + @apply border border-gray-400 w-12 md:w-full p-1 rounded; } diff --git a/src/routes/(app)/+layout.svelte b/src/routes/(app)/+layout.svelte index 7c203ff..eb9cce9 100644 --- a/src/routes/(app)/+layout.svelte +++ b/src/routes/(app)/+layout.svelte @@ -6,6 +6,8 @@ import { navigating } from '$app/stores' import Loader from '$lib/elements/Loader.svelte' import mixpanel from 'mixpanel-browser' + import { slide } from 'svelte/transition' + import { supabase } from '$lib/db/supabaseClient' //Import Mixpanel SDK mixpanel.init(PUBLIC_MIX_TOKEN, { @@ -13,6 +15,12 @@ track_pageview: true, persistence: 'localStorage' }) + + let showSettings = false + + const handleLogout = async () => { + await supabase.auth.signOut() + }
@@ -23,13 +31,11 @@ {/if} -
diff --git a/src/routes/(app)/+page.svelte b/src/routes/(app)/+page.svelte index 26fc690..a3bc4bd 100644 --- a/src/routes/(app)/+page.svelte +++ b/src/routes/(app)/+page.svelte @@ -15,6 +15,7 @@ import Icon from '@iconify/svelte' import mixpanel from 'mixpanel-browser' import { onMount, tick } from 'svelte' + import { slide } from 'svelte/transition' const paperFields = { id: '', @@ -46,12 +47,16 @@ } const removePaper = async (idx: string) => { + // const element = document.getElementById(idx) + // if (element) inputGroupRef.removeChild(element) paperCount = paperCount.filter((field) => field.id != idx) + if (perPaperResult.has(idx)) perPaperResult.delete(idx) + perPaperResult = perPaperResult getAllInputs() } const calculatePaperCost = async () => { - if (!paperCount.length || hasNullValue) return + if (hasNullValue) return perPaperResult.clear() finalPrice = 0 paperCount.forEach((paper) => { @@ -62,15 +67,6 @@ }) perPaperResult = perPaperResult - // Saving to history - if ($totalHistoryStore < MAX_HISTORY) { - addHistory({ - name: customer_name, - final_price: finalPrice, - papers: paperCount - }) - $totalHistoryStore = await getTotalHistory() - } // mixpanel data prepare const perPageData: number[] = [] perPaperResult.forEach((data) => { @@ -83,10 +79,22 @@ }) } + const saveHistory = async () => { + if ($totalHistoryStore < MAX_HISTORY) { + addHistory({ + name: customer_name, + final_price: finalPrice, + papers: paperCount + }) + $totalHistoryStore = await getTotalHistory() + } + } + const clearAll = () => { paperCount = [{ ...paperFields, id: makeid(5) }] finalPrice = 0 focusedIndex = 0 + customer_name = '' perPaperResult.clear() getAllInputs() setFocus() @@ -109,7 +117,7 @@ paperCount.find((paper) => { return !paper.length || !paper.width || !paper.thickness || !paper.rate }) - + $: showSaveHistory = perPaperResult.size == paperCount.length // Handling and maintaining focused input index $: inputsArray = inputs && Array.from(inputs) $: focusedInputID = $focusedInputStore && $focusedInputStore.getAttribute('id') @@ -156,20 +164,31 @@ Maximum history reached, delete some history!

{/if} -
+
+ {#if showSaveHistory} +
{#each paperCount as paper, i} -
+