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

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