Skip to content

Commit

Permalink
Toaster added, sorted by date on history
Browse files Browse the repository at this point in the history
  • Loading branch information
prokawsar committed Jul 25, 2024
1 parent f40d5ef commit de9ef20
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 3 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
"dayjs": "^1.11.11",
"mixpanel-browser": "^2.53.0",
"svelte-persisted-store": "^0.11.0",
"svelte-sonner": "^0.3.27",
"tippy.js": "^6.3.7"
}
}
7 changes: 7 additions & 0 deletions src/routes/(app)/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mixpanel from 'mixpanel-browser'
import { slide } from 'svelte/transition'
import { supabase } from '$lib/db/supabaseClient'
import { Toaster } from 'svelte-sonner'
//Import Mixpanel SDK
mixpanel.init(PUBLIC_MIX_TOKEN, {
Expand All @@ -24,6 +25,12 @@
</script>

<main class="h-[100svh] flex flex-col">
<Toaster
richColors
toastOptions={{
class: 'py-2'
}}
/>
{#if $navigating}
<div
class="absolute bg-white bg-opacity-80 flex h-full w-full items-center justify-center z-10"
Expand Down
4 changes: 2 additions & 2 deletions src/routes/(app)/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import Icon from '@iconify/svelte'
import mixpanel from 'mixpanel-browser'
import { onMount, tick } from 'svelte'
import { toast } from 'svelte-sonner'
const paperFields = {
id: '',
Expand Down Expand Up @@ -46,8 +47,6 @@
}
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
Expand Down Expand Up @@ -86,6 +85,7 @@
papers: paperCount
})
$totalHistoryStore = await getTotalHistory()
toast.success('Cost details saved successfully')
}
}
Expand Down
16 changes: 15 additions & 1 deletion src/routes/(app)/history/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import Icon from '@iconify/svelte'
import days from 'dayjs'
import mixpanel from 'mixpanel-browser'
import { toast } from 'svelte-sonner'
export let data
let isLoading = false
Expand All @@ -19,6 +20,19 @@
await deleteHistory(id)
await invalidateAll()
isLoading = false
toast.message('History deleted successfully')
}
const sortedByCreatedAt = (data: any) => {
return data.sort((a: any, b: any) => {
// Convert 'created_at' strings to Date objects
let dateA = new Date(a.created_at)
let dateB = new Date(b.created_at)
if (dateA > dateB) return -1
if (dateA < dateB) return 1
return 0
})
}
</script>

Expand All @@ -38,7 +52,7 @@
<div class="relative flex flex-col h-full gap-2 overflow-y-auto w-full max-w-3xl py-2 z-0">
{#if !isLoading}
{#if data.histories.length}
{#each data.histories as { name, id, final_price, created_at }}
{#each sortedByCreatedAt(data.histories) as { name, id, final_price, created_at }}
<div
class="flex flex-col gap-1 items-center w-full p-1 border border-dashed rounded shadow-sm"
>
Expand Down

0 comments on commit de9ef20

Please sign in to comment.