feat: add ability to mark individual posts as read, close #114

This commit is contained in:
Xyphyn committed 2023-08-19 14:13:30 -07:00
1 parent 0be27d8eee
commit 79221e2e53
3 files changed
+32 -3

No files matched your search

@@ -7,6 +7,8 @@
BookmarkSlash,
ChatBubbleOvalLeftEllipsis,
EllipsisHorizontal,
Eye,
EyeSlash,
Flag,
Icon,
Newspaper,
@@ -31,7 +33,7 @@
import ModerationMenu from '$lib/components/lemmy/moderation/ModerationMenu.svelte'
import { profile } from '$lib/auth.js'
import Spinner from '$lib/components/ui/loader/Spinner.svelte'
import { deleteItem, save } from '$lib/lemmy/contentview.js'
import { deleteItem, markAsRead, save } from '$lib/lemmy/contentview.js'
export let post: PostView
@@ -149,7 +151,15 @@
<Icon src={PencilSquare} width={16} mini />
Edit
</MenuButton>
{/if}
{/if}<MenuButton
on:click={async () => {
if ($profile?.jwt)
post.read = await markAsRead(post.post, !post.read, $profile.jwt)
}}
>
<Icon src={post.read ? EyeSlash : Eye} width={16} mini />
Mark as {post.read ? 'Unread' : 'Read'}
</MenuButton>
<MenuButton
on:click={() =>
navigator.clipboard.writeText(
+19
View File
@@ -140,3 +140,22 @@ export async function vote(
}
return 0
}
export async function markAsRead(
item: ContentView | Submission,
read: boolean,
jwt: string
): Promise<boolean> {
if (isSubmission(item)) item = contentItem(item)
if (item.type == 'post') {
return (
await getClient().markPostAsRead({
auth: jwt,
post_id: item.id,
read: read,
})
).post_view.read
}
return false
}