2023-02-13 19:20:50 +00:00
|
|
|
<script lang="ts">
|
|
|
|
import { onMount } from 'svelte';
|
|
|
|
import { getNotifStorage, setSettings } from '@/utils/storage'
|
|
|
|
import { mainStore } from '@/utils/store'
|
|
|
|
import PageLoader from '@/components/PageLoader.svelte';
|
|
|
|
import { getNotifications } from '@/utils/notifications';
|
|
|
|
import Notification from '@/components/Notification.svelte';
|
|
|
|
import { clearNotifications } from '@/utils/notifications';
|
|
|
|
import { clearBadge } from '@/utils/chrome-misc'
|
|
|
|
|
|
|
|
let loading = true;
|
|
|
|
let noNotifications = false;
|
|
|
|
let notifs = [];
|
|
|
|
let pastNotifsPromise
|
2023-04-13 00:32:37 +00:00
|
|
|
let type = null
|
2023-02-13 19:20:50 +00:00
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
notifs = await getNotifications({
|
2023-07-20 06:57:07 +00:00
|
|
|
address: $mainStore.user.auth.address.toLowerCase(),
|
2023-02-13 19:20:50 +00:00
|
|
|
type,
|
|
|
|
skip: '0',
|
|
|
|
limit: '15'
|
|
|
|
})
|
|
|
|
pastNotifsPromise = getNotifStorage()
|
|
|
|
|
|
|
|
console.log(notifs);
|
|
|
|
loading = false;
|
|
|
|
clearNotifications($mainStore).then(
|
|
|
|
() => {
|
|
|
|
clearBadge()
|
|
|
|
$mainStore.settings.hasNewNotifications = false
|
|
|
|
setSettings($mainStore.settings)
|
|
|
|
}
|
|
|
|
)
|
|
|
|
|
|
|
|
});
|
|
|
|
|
2023-04-13 00:32:37 +00:00
|
|
|
const changeNotifsType = async (t : string[] | null) => {
|
|
|
|
if(String(type) === String(t)) return;
|
|
|
|
type = t
|
2023-02-13 19:20:50 +00:00
|
|
|
loading = true;
|
|
|
|
notifs = await getNotifications({
|
2023-07-20 06:57:07 +00:00
|
|
|
address: $mainStore.user.auth.address.toLowerCase(),
|
2023-02-13 19:20:50 +00:00
|
|
|
type: t,
|
|
|
|
skip: '0',
|
|
|
|
limit: '15'
|
|
|
|
})
|
|
|
|
loading = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
{#if loading}
|
|
|
|
<PageLoader />
|
|
|
|
{:else if notifs.length === 0}
|
|
|
|
|
|
|
|
{#await pastNotifsPromise}
|
|
|
|
|
|
|
|
{:then pastNotifs}
|
2023-07-20 06:57:07 +00:00
|
|
|
{#if (pastNotifs.notifs ?? []).length > 0}
|
2023-02-13 19:20:50 +00:00
|
|
|
{noNotifications = true}
|
|
|
|
{:else}
|
2023-07-20 06:57:07 +00:00
|
|
|
{#each pastNotifs.notifs as notif}
|
2023-02-13 19:20:50 +00:00
|
|
|
<Notification {notif} />
|
|
|
|
{/each}
|
|
|
|
{/if}
|
|
|
|
{/await}
|
|
|
|
{:else}
|
|
|
|
<div class="text-[0.75rem] py-1">
|
2023-04-13 00:32:37 +00:00
|
|
|
<span on:click={() => changeNotifsType(null)} aria-hidden class="inline-block mr-2 interactive-svg text-blue-200 interactive-svg" >All</span>
|
|
|
|
<span on:click={() => changeNotifsType(['reward'])} aria-hidden class="text-blue-200 interactive-svg interactive-svg text-blue-200 interactive-svg">Rewards</span>
|
2023-02-13 19:20:50 +00:00
|
|
|
</div>
|
|
|
|
<div class="flex flex-col">
|
2023-07-20 06:57:07 +00:00
|
|
|
{#each notifs as notif}
|
2023-02-13 19:20:50 +00:00
|
|
|
<Notification {notif} />
|
|
|
|
{/each}
|
|
|
|
</div>
|
|
|
|
{/if}
|
|
|
|
|
|
|
|
{#if noNotifications }
|
|
|
|
<div class="flex flex-col items-center justify-center h-full">
|
|
|
|
<p class="text-2xl font-semibold">No Notifications</p>
|
|
|
|
<p class="text-lg">You have no notifications</p>
|
|
|
|
</div>
|
|
|
|
{/if}
|