feat: Add notification for unreads

This commit is contained in:
Xyphyn committed 2023-07-06 11:11:25 -07:00
1 parent 28d9820b1e
commit 1a0881f9ce
13 files changed
+215 -105

No files matched your search

+42 -3
View File
@@ -1,14 +1,53 @@
<script lang="ts">
import type { CommentReplyView, PersonMentionView } from 'lemmy-js-client'
import InboxItem from './InboxItem.svelte'
import Button from '$lib/components/input/Button.svelte'
import { Check, Icon } from 'svelte-hero-icons'
import { authData, getClient } from '$lib/lemmy.js'
import { goto } from '$app/navigation'
import { page } from '$app/stores'
export let data
export let data: {
data: PersonMentionView[] | CommentReplyView[]
}
function isRead(item: PersonMentionView | CommentReplyView) {
console.log('running...')
if ('person_mention' in item) {
return (item as PersonMentionView).person_mention.read
}
if ('comment_reply' in item) {
return (item as CommentReplyView).comment_reply.read
}
return false
}
async function markAllAsRead() {
const response = await getClient().markAllAsRead({
auth: $authData!.token,
})
goto($page.url, {
invalidateAll: true,
})
return response.replies
}
</script>
<svelte:head>
<title>Inbox</title>
</svelte:head>
<h1 class="font-bold text-3xl">Inbox</h1>
<div class="flex flex-row justify-between">
<h1 class="font-bold text-3xl">Inbox</h1>
<Button on:click={markAllAsRead}>
<Icon src={Check} width={16} mini />
Mark all as read
</Button>
</div>
<div class="flex flex-col gap-4 list-none my-4">
{#if !data.data || (data.data?.length ?? 0) == 0}
<p class="text-center opacity-60 text-lg mx-4">
@@ -16,7 +55,7 @@
</p>
{:else}
{#each data.data as item}
<InboxItem {item} />
<InboxItem {item} read={isRead(item)} />
{/each}
{/if}
</div>
+8 -2
View File
@@ -2,15 +2,21 @@
import Link from '$lib/components/input/Link.svelte'
import Comment from '$lib/components/lemmy/comment/Comment.svelte'
import Card from '$lib/components/ui/Card.svelte'
import type { CommentReplyView, PersonMentionView } from 'lemmy-js-client'
import type {
CommentReplyView,
PersonMentionView,
PrivateMessageView,
} from 'lemmy-js-client'
export let item: CommentReplyView | PersonMentionView
export let read: boolean
</script>
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
<div class="flex flex-row items-center">
<div
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis overflow-hidden"
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
overflow-hidden {read ? 'opacity-50' : ''}"
>
<span class="font-bold">
{item.creator.display_name ?? item.creator.name}