feat: add ability to mark single item as read

This commit is contained in:
Xyphyn committed 2023-08-09 16:21:31 -07:00
1 parent 7e2561511d
commit 0f315bec01
6 files changed
+153 -93

No files matched your search

+3 -2
View File
@@ -18,8 +18,9 @@
hover:bg-transparent hover:dark:bg-transparent
active:bg-black/10 active:dark:bg-white/10`,
secondary:
'border border-slate-200 dark:border-zinc-700 bg-transparent hover:bg-slate-100 hover:dark:bg-zinc-800 dark:text-zinc-400',
secondary: `border border-slate-200 dark:border-zinc-700 bg-transparent
hover:bg-slate-100 hover:dark:bg-zinc-800 dark:text-zinc-400 hover:text-inherit
hover:dark:text-inherit`,
tertiary:
'border border-transparent bg-transparent hover:bg-slate-100 hover:dark:bg-zinc-800 dark:text-zinc-200',
@@ -76,7 +76,7 @@
<li
class="py-2 {node.depth == 0
? 'border-b border-slate-200 dark:border-zinc-800'
: ''}"
: ''} {$$props.class}"
id="#{node.comment_view.comment.id.toString()}"
>
<details bind:open class="flex flex-col gap-1">
+72 -61
View File
@@ -12,82 +12,93 @@
LockClosed,
Trash,
} from 'svelte-hero-icons'
import { getInstance } from '$lib/lemmy.js'
import { userSettings } from '$lib/settings.js'
export let community: Community | undefined = undefined
export let user: Person | undefined = undefined
export let published: Date
export let title: string | undefined = undefined
export let id: number | undefined = undefined
// Score
export let upvotes: number | undefined = undefined
export let downvotes: number | undefined = undefined
// Badges
export let nsfw: boolean
export let saved: boolean
export let featured: boolean
export let deleted: boolean
export let nsfw: boolean = false
export let saved: boolean = false
export let featured: boolean = false
export let deleted: boolean = false
export let removed: boolean = false
export let locked: boolean = false
</script>
<span class="flex flex-row gap-2 text-sm items-center">
{#if community}
<Avatar url={community.icon} width={24} alt={community.name} />
{/if}
<div class="flex flex-col text-xs">
<div class="flex flex-col gap-1">
<span class="flex flex-row gap-2 text-sm items-center">
{#if community}
<CommunityLink {community} />
<Avatar url={community.icon} width={24} alt={community.name} />
{/if}
<span
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1 flex-wrap items-center"
>
{#if user}
<div
class="mr-0.5 flex items-center"
class:text-slate-900={!community}
class:dark:text-zinc-100={!community}
>
<UserLink avatarSize={20} {user} avatar={!community} />
</div>
<div class="flex flex-col text-xs">
{#if community}
<CommunityLink {community} />
{/if}
<RelativeDate date={published} />
{#if upvotes != undefined && downvotes != undefined}
<span>•</span>
<span>
{Math.floor((upvotes / (upvotes + downvotes || 1)) * 100)}%
</span>
{/if}
</span>
</div>
<span
class="text-slate-600 dark:text-zinc-400 flex flex-row gap-1 flex-wrap items-center"
>
{#if user}
<div
class="mr-0.5 flex items-center"
class:text-slate-900={!community}
class:dark:text-zinc-100={!community}
>
<UserLink avatarSize={20} {user} avatar={!community} />
</div>
{/if}
<RelativeDate date={published} />
{#if upvotes != undefined && downvotes != undefined}
<span>•</span>
<span>
{Math.floor((upvotes / (upvotes + downvotes || 1)) * 100)}%
</span>
{/if}
</span>
</div>
<div class="flex flex-row ml-auto gap-2 flex-wrap">
{#if nsfw}
<Badge class="bg-red-600 text-white">NSFW</Badge>
{/if}
{#if saved}
<Badge class="bg-yellow-500 text-white py-1" label="Saved">
<Icon src={Bookmark} mini width={16} />
</Badge>
{/if}
{#if locked}
<Badge class="bg-yellow-400 text-black py-1" label="Locked">
<Icon src={LockClosed} mini width={16} />
</Badge>
{/if}
{#if removed}
<Badge class="bg-green-600 text-white py-1" label="Removed">
<Icon src={Trash} mini width={16} />
</Badge>
{/if}
{#if deleted}
<Badge class="bg-red-600 text-white py-1" label="Deleted">
<Icon src={Trash} mini width={16} />
</Badge>
{/if}
{#if featured}
<Badge class="bg-green-500 text-white py-1" label="Pinned">
<Icon src={InformationCircle} mini width={16} />
</Badge>
{/if}
</div>
</span>
<div class="flex flex-row ml-auto gap-2 flex-wrap">
{#if nsfw}
<Badge class="bg-red-600 text-white">NSFW</Badge>
{/if}
{#if saved}
<Badge class="bg-yellow-500 text-white py-1" label="Saved">
<Icon src={Bookmark} mini width={16} />
</Badge>
{/if}
{#if locked}
<Badge class="bg-yellow-400 text-black py-1" label="Locked">
<Icon src={LockClosed} mini width={16} />
</Badge>
{/if}
{#if removed}
<Badge class="bg-green-600 text-white py-1" label="Removed">
<Icon src={Trash} mini width={16} />
</Badge>
{/if}
{#if deleted}
<Badge class="bg-red-600 text-white py-1" label="Deleted">
<Icon src={Trash} mini width={16} />
</Badge>
{/if}
{#if featured}
<Badge class="bg-green-500 text-white py-1" label="Pinned">
<Icon src={InformationCircle} mini width={16} />
</Badge>
{/if}
</div>
</span>
{#if title && id}
<a href="/post/{getInstance()}/{id}" class="font-medium">
{title}
</a>
{/if}
</div>
+3 -1
View File
@@ -1,3 +1,5 @@
<span class="text-sm font-bold text-slate-600 dark:text-zinc-400">
<span
class="text-sm font-bold text-slate-600 dark:text-zinc-400 {$$props.class} "
>
<slot />
</span>
+73 -27
View File
@@ -13,9 +13,11 @@
PersonMentionView,
PrivateMessageView,
} from 'lemmy-js-client'
import { ChatBubbleOvalLeft, Icon } from 'svelte-hero-icons'
import { ChatBubbleOvalLeft, Check, Icon } from 'svelte-hero-icons'
import { page } from '$app/stores'
import { toast } from '$lib/components/ui/toasts/toasts.js'
import PostMeta from '$lib/components/lemmy/post/PostMeta.svelte'
import SectionTitle from '$lib/components/ui/SectionTitle.svelte'
export let item: CommentReplyView | PersonMentionView | PrivateMessageView
export let read: boolean
@@ -61,41 +63,85 @@
loading = false
}
async function markAsRead(isRead: boolean) {
if (!$profile?.jwt) return
loading = true
if ('person_mention' in item) {
await getClient().markPersonMentionAsRead({
auth: $profile?.jwt,
person_mention_id: item.person_mention.id,
read: isRead,
})
} else if ('comment_reply' in item) {
await getClient().markCommentReplyAsRead({
auth: $profile?.jwt,
comment_reply_id: item.comment_reply.id,
read: isRead,
})
}
read = isRead
loading = false
}
</script>
<Card class="flex flex-col bg-white rounded-md p-4 max-w-full">
<Card elevation={0} class="flex flex-col rounded-md p-4 max-w-full gap-2">
{#if !isPrivateMessage(item)}
<div class="flex flex-row items-center justify-between">
<div
class="text-sm max-w-[80ch] whitespace-nowrap text-ellipsis
overflow-hidden {read ? 'text-slate-600 dark:text-zinc-400' : ''}"
>
<span class="font-bold">
{item.creator.display_name ?? item.creator.name}
</span>
replied to you in
<a
href="/post/{item.post.id}"
class="font-bold max-w-[48ch] overflow-hidden text-ellipsis
whitespace-nowrap inline hover:underline"
>
{item.post.name}
</a>
</div>
<Button
href="/post/{item.post.id}?thread={item.comment.path}#{item.comment.id}"
>
Jump
</Button>
</div>
<div>
<PostMeta
published={new Date(item.post.published)}
title={item.post.name}
id={item.post.id}
/>
<div
class="flex flex-col"
class:mt-2={$profile?.user &&
item.post.creator_id != $profile.user.local_user_view.person.id}
>
<SectionTitle class="mb-2 text-xs">Reply</SectionTitle>
{#if $profile?.user && item.post.creator_id != $profile.user.local_user_view.person.id}
<div class="flex flex-row text-xs items-center gap-2">
<div
class="border-t w-8 rounded-tl h-2 border-l ml-2 border-zinc-700"
/>
<div>
<UserLink
avatar
avatarSize={16}
user={$profile.user.local_user_view.person}
/>
</div>
</div>
{/if}
<Comment
postId={item.post.id}
node={{ children: [], comment_view: item, depth: 1 }}
replying={false}
class="!p-0"
/>
</div>
<div class="flex flex-row ml-auto gap-2">
<Button
class={read ? '!text-green-500' : ''}
size="square-md"
{loading}
disabled={loading}
on:click={() => markAsRead(!read)}
>
<Icon slot="icon" src={Check} mini size="16" />
</Button>
<Button
href="/post/{item.post.id}?thread={item.comment.path}#{item.comment.id}"
size="md"
class="h-8"
>
Jump
</Button>
</div>
{:else}
<div class="flex flex-row items-center">
<div