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

+3 -1
View File
@@ -92,6 +92,8 @@
'My cat just invented a time machine, what do I do?',
'Unpopular opinion: world peace and global happiness would be beneficial to humanity',
'LPT: The smaller weights are easier to lift than the bigger weights in a gym',
'javascript bad',
'ELI5: What is 4 + 8?',
]
const placeholder =
@@ -123,7 +125,7 @@
<title>Create post</title>
</svelte:head>
<Card class="p-6 max-w-xl mx-auto">
<Card class="p-6 max-w-2xl mx-auto">
<form on:submit|preventDefault={submit} class="flex flex-col gap-4">
<h1 class="font-bold text-xl">Create Post</h1>
<div>
+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}
+11 -3
View File
@@ -3,13 +3,11 @@
import type { Comment, CommentView } from 'lemmy-js-client'
import type { CommentNodeI } from '$lib/components/lemmy/comment/comments.js'
import Comments from '$lib/components/lemmy/comment/Comments.svelte'
import SvelteMarkdown from 'svelte-markdown'
import CommunityLink from '$lib/components/community/CommunityLink.svelte'
import { isImage, isVideo } from '$lib/ui/image.js'
import { user } from '$lib/lemmy.js'
import { authData, getClient, user } from '$lib/lemmy.js'
import CommentForm from '$lib/components/lemmy/comment/CommentForm.svelte'
import PostVote from '$lib/components/lemmy/PostVote.svelte'
import { page } from '$app/stores'
import { onMount } from 'svelte'
import UserLink from '$lib/components/user/UserLink.svelte'
import Markdown from '$lib/components/markdown/Markdown.svelte'
@@ -19,6 +17,16 @@
const postData = data.post.post_view
const post = postData.post
onMount(async () => {
if (!postData.read && $authData) {
getClient().markPostAsRead({
auth: $authData.token,
read: true,
post_id: post.id,
})
}
})
function getCommentParentId(comment?: Comment): number | undefined {
const split = comment?.path.split('.')
// remove the 0