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

@@ -43,8 +43,15 @@
<FormattedNumber number={community_view.counts.comments} />
</span>
</div>
<h1 class="font-bold text-lg">
{community_view.community.name}
</h1>
<div>
<h1 class="font-bold text-lg">
{community_view.community.title}
</h1>
<span class="opacity-80 text-sm">
!{community_view.community.name}@{new URL(
community_view.community.actor_id
).hostname}
</span>
</div>
<Markdown source={community_view.community.description} />
</StickyCard>
+16 -9
View File
@@ -25,6 +25,7 @@
import MenuButton from '$lib/components/ui/menu/MenuButton.svelte'
import { Color } from '$lib/ui/colors.js'
import { page } from '$app/stores'
import Avatar from '$lib/components/ui/Avatar.svelte'
let postRes: PostView
export { postRes as post }
@@ -49,16 +50,22 @@
<Card class="bg-white flex flex-col overflow-hidden w-full relative">
<div class="flex flex-col gap-2 bg-white dark:bg-zinc-900 p-4 rounded-md">
<span class="flex flex-row gap-2 text-xs items-center">
<CommunityLink avatarSize={20} avatar community={postRes.community} />
<span class="opacity-60">
<UserLink user={postRes.creator} />
</span>
<Avatar url={postRes.community.icon ?? ''} alt="" width={24} />
<div class="flex flex-col">
<CommunityLink community={postRes.community} />
<span class="opacity-60 flex flex-row gap-1">
<UserLink user={postRes.creator} />
<span>•</span>
<RelativeDate date={new Date(postRes.post.published)} />
</span>
</div>
<div class="ml-auto" />
<span class="opacity-50 capitalize">
<RelativeDate date={new Date(postRes.post.published)} />
</span>
<span class="opacity-50 capitalize" />
</span>
<a href="/post/{postRes.post.id}" class="font-bold">
<a
href="/post/{postRes.post.id}"
class="font-bold {postRes.read ? 'opacity-50' : ''}"
>
{postRes.post.name}
</a>
{#if postRes.post.url}
@@ -115,7 +122,7 @@
<FormattedNumber number={postRes.counts.comments} />
</span>
</a>
<Menu top absolute class="bottom-0 right-0 m-5 z-40">
<Menu top absolute class="bottom-0 right-0 m-5 z-10">
<Button slot="button">
<Icon src={EllipsisHorizontal} width={16} mini />
</Button>
@@ -120,14 +120,16 @@
class="flex flex-col gap-1 whitespace-pre-wrap
max-w-full"
>
<div class="max-w-full break-words">
<div class="max-w-full break-words text-sm leading-6">
<Markdown source={node.comment_view.comment.content} />
</div>
<div class="flex flex-row gap-2 items-center">
<div class="flex flex-row gap-2 items-center">
<div class="flex flex-row items-center">
<button
on:click={upvote}
class={node.comment_view.my_vote == 1 ? 'text-orange-500' : ''}
class="pr-1.5 {node.comment_view.my_vote == 1
? 'text-orange-500'
: ''}"
>
<Icon src={ArrowUp} width={16} mini />
</button>
@@ -136,7 +138,9 @@
</span>
<button
on:click={downvote}
class={node.comment_view.my_vote == -1 ? 'text-blue-500' : ''}
class="pl-1.5 {node.comment_view.my_vote == -1
? 'text-blue-500'
: ''}"
>
<Icon src={ArrowDown} width={16} mini />
</button>
@@ -1,5 +1,6 @@
<script lang="ts">
import MarkdownHeader from '$lib/components/markdown/MarkdownHeader.svelte'
import MarkdownHr from '$lib/components/markdown/MarkdownHr.svelte'
import MarkdownLink from '$lib/components/markdown/MarkdownLink.svelte'
import SvelteMarkdown from 'svelte-markdown'
@@ -11,5 +12,6 @@
renderers={{
link: MarkdownLink,
heading: MarkdownHeader,
hr: MarkdownHr,
}}
/>
@@ -0,0 +1 @@
<hr class="w-[90%] mx-auto my-4 opacity-80" />
+1 -1
View File
@@ -4,7 +4,7 @@
</script>
<div
class="bg-white shadow-lg border-slate-200
class="bg-white shadow-md border border-slate-100
dark:border-zinc-800 dark:bg-zinc-900 break-words
flex-col p-1 rounded-md {clazz}"
>
+91 -75
View File
@@ -26,84 +26,100 @@
</script>
<nav
class="flex top-0 z-20 flex-row gap-4 items-center mt-2 w-full h-16
max-w-5xl mx-auto px-6"
class="sticky bg-slate-50/70 dark:bg-zinc-950/70 backdrop-blur-3xl top-0
z-20 mt-2"
>
<div class="flex flex-row gap-2 items-center mr-auto">
<a href="/" class="flex flex-row items-center gap-2">
<Logo width={40} />
<div class="sm:flex flex-col hidden">
<span class="font-bold">Xylemmy</span>
<span
class="text-xs opacity-50
<div
class="flex z-20 flex-row gap-4 items-center w-full h-16 max-w-5xl mx-auto px-6"
>
<div class="flex flex-row gap-2 items-center mr-auto">
<a href="/" class="flex flex-row items-center gap-2">
<Logo width={40} />
<div class="sm:flex flex-col hidden">
<span class="font-bold">Xylemmy</span>
<span
class="text-xs opacity-50
transition-opacity"
>
{#if $authData?.instance}
{$authData.instance}
{:else}
{DEFAULT_INSTANCE_URL}
{/if}
</span>
</div>
</a>
</div>
<div class="flex flex-row gap-2">
<Link href="/communities">
<Icon src={GlobeAlt} width={16} />
<span class="hidden sm:inline ml-1">Communities</span>
</Link>
>
{#if $authData?.instance}
{$authData.instance}
{:else}
{DEFAULT_INSTANCE_URL}
{/if}
</span>
</div>
</a>
</div>
<div class="flex flex-row gap-2">
<Link href="/communities">
<Icon src={GlobeAlt} width={16} />
<span class="hidden sm:inline ml-1">Communities</span>
</Link>
<Menu>
<Button color={Color.accent} slot="button">
<Icon src={Plus} width={16} />
<span class="hidden sm:inline">Create</span>
</Button>
<span class="text-xs opacity-80 text-left mx-4 my-2">Create</span>
<MenuButton link href="/create/post">
<Icon src={PencilSquare} mini width={16} />
Post
</MenuButton>
</Menu>
</div>
<Menu>
<Button color={Color.accent} slot="button">
<Icon src={Plus} width={16} />
<span class="hidden sm:inline">Create</span>
</Button>
<span class="text-xs opacity-80 text-left mx-4 my-2">Create</span>
<MenuButton link href="/create/post">
<Icon src={PencilSquare} mini width={16} />
Post
</MenuButton>
<button
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
dark:bg-zinc-800 relative"
aria-label="Profile"
slot="button"
>
{#if $user}
<img
src={$user.person_view.person.avatar ??
'https://xylo.xylight.dev/img/logo-background.svg'}
alt=""
width={32}
height={32}
/>
{#if $user.unreads > 0}
<div
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0"
/>
{/if}
{/if}
</button>
<span class="text-xs opacity-80 text-left mx-4 my-2">Profile</span>
{#if !$user}
<MenuButton link href="/login">
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
</MenuButton>
{:else}
<MenuButton link href="/u/{$user.person_view.person.name}">
<Icon src={UserCircle} mini width={16} /> Profile
</MenuButton>
<MenuButton link href="/inbox">
<div class="relative">
{#if $user.unreads > 0}
<div
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
/>
{/if}<Icon src={Inbox} mini width={16} />
</div>
Inbox
</MenuButton>
<MenuButton
on:click={() => {
localStorage.removeItem('user')
goto('/', {
invalidateAll: true,
})
}}
color={Color.dangerSecondary}
>
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
</MenuButton>
{/if}
</Menu>
</div>
<Menu>
<button
class="w-8 h-8 rounded-full ring-1 ring-slate-300 bg-slate-100
dark:bg-zinc-800"
aria-label="Profile"
slot="button"
>
{#if $user}
<img
src={$user.person_view.person.avatar ??
'https://xylo.xylight.dev/img/logo-background.svg'}
alt=""
width={32}
height={32}
/>
{/if}
</button>
<span class="text-xs opacity-80 text-left mx-4 my-2">Profile</span>
{#if !$user}
<MenuButton link href="/login">
<Icon src={ArrowLeftOnRectangle} mini width={16} /> Log in
</MenuButton>
{:else}
<MenuButton link href="/u/{$user.person_view.person.name}">
<Icon src={UserCircle} mini width={16} /> Profile
</MenuButton>
<MenuButton link href="/inbox">
<Icon src={Inbox} mini width={16} /> Inbox
</MenuButton>
<MenuButton
on:click={() => {
localStorage.removeItem('user')
goto('/', {
invalidateAll: true,
})
}}
color={Color.dangerSecondary}
>
<Icon src={ArrowRightOnRectangle} mini width={16} />Log out
</MenuButton>
{/if}
</Menu>
</nav>
+2 -2
View File
@@ -1,7 +1,7 @@
<div
class="sticky top-4 bg-white shadow-lg border-slate-200
class="sticky top-20 bg-white shadow-md border-slate-200
dark:border-zinc-800 dark:bg-zinc-900 break-words hidden lg:flex
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-2rem)] overflow-auto"
flex-col gap-4 p-8 max-w-sm rounded-md h-max max-h-[calc(100vh-6rem)] overflow-auto"
>
<slot />
</div>
+20 -2
View File
@@ -31,8 +31,26 @@ export interface AuthData {
instance: string
}
export interface UserData {
unreads: number
}
export const authData = writable<AuthData | undefined>()
export const user = writable<GetPersonDetailsResponse>()
export const user = writable<GetPersonDetailsResponse & UserData>()
setInterval(async () => {
// check for unread messages
if (!get(authData)) return
const response = await getClient().getUnreadCount({
auth: get(authData)!.token,
})
const u = get(user)
u.unreads = response.mentions + response.private_messages + response.replies
user.set(u)
}, 60 * 1000)
if (typeof localStorage != 'undefined') {
if (localStorage.getItem('user')) {
@@ -52,7 +70,7 @@ authData.subscribe(async (data) => {
username: `${data?.username}@${data?.instance}`,
})
user.set(person)
user.set({ ...person, unreads: 0 })
if (typeof localStorage != 'undefined') {
localStorage.setItem('user', JSON.stringify(data))