Skip to content

Commit

Permalink
Seperate save history button
Browse files Browse the repository at this point in the history
  • Loading branch information
prokawsar committed Jul 22, 2024
1 parent 87d8d33 commit cfb3258
Showing 1 changed file with 23 additions and 12 deletions.
35 changes: 23 additions & 12 deletions src/routes/(app)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,13 @@
const removePaper = async (idx: string) => {
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) => {
Expand All @@ -62,15 +64,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) => {
Expand All @@ -83,6 +76,17 @@
})
}
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
Expand All @@ -109,7 +113,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')
Expand Down Expand Up @@ -156,13 +160,20 @@
Maximum history reached, delete some history!
</p>
{/if}
<div class="flex w-full items-start">
<div class="flex w-full gap-1 items-start">
<input
bind:value={customer_name}
type="text"
placeholder="Customer name"
class="border-b border-dashed w-full px-2 focus:outline-none focus:border-teal-500"
/>
{#if showSaveHistory}
<Button
on:click={saveHistory}
text="Save cost"
classNames="text-sm animate-pulse w-1/4 !px-1"
/>
{/if}
</div>
<div
class="flex flex-col gap-[1px] overflow-y-auto max-w-3xl max-h-[85%] py-2 w-full"
Expand Down

0 comments on commit cfb3258

Please sign in to comment.