design: add unified notifications button
This commit is contained in:
8 files changed
+112
-76
No files matched your search
@@ -1,9 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/state'
|
import { page } from '$app/state'
|
||||||
import { Button, buttonColor } from 'mono-svelte'
|
import { Button } from 'mono-svelte'
|
||||||
import { Icon, type IconSource } from 'svelte-hero-icons'
|
|
||||||
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
import type { ButtonProps } from 'mono-svelte/button/Button.svelte'
|
||||||
import type { Snippet } from 'svelte'
|
import type { Snippet } from 'svelte'
|
||||||
|
import { Icon, type IconSource } from 'svelte-hero-icons'
|
||||||
|
|
||||||
interface Props extends ButtonProps {
|
interface Props extends ButtonProps {
|
||||||
label: string
|
label: string
|
||||||
@@ -35,31 +35,30 @@
|
|||||||
color="none"
|
color="none"
|
||||||
{...rest}
|
{...rest}
|
||||||
class={[
|
class={[
|
||||||
'shrink-0 rounded-full w-10 h-10 lg:w-max lg:h-8 lg:px-3 lg:rounded-xl',
|
'shrink-0 rounded-full w-10 h-10 lg:w-max lg:h-8 lg:rounded-xl',
|
||||||
isSelected &&
|
|
||||||
'bg-slate-200 dark:bg-zinc-900 text-primary-900 dark:text-primary-100!',
|
|
||||||
!rest.color && buttonColor.tertiary,
|
|
||||||
!rest.color &&
|
!rest.color &&
|
||||||
'lg:bg-white lg:dark:bg-zinc-900 border lg:border-slate-200 lg:border-b-slate-300 lg:dark:border-zinc-800 lg:dark:border-t-zinc-700/50 lg:hover:bg-slate-100 lg:dark:hover:bg-zinc-800 lg:active:bg-slate-200 lg:dark:active:bg-zinc-950',
|
'hover:text-slate-900 dark:hover:text-zinc-50 transition-colors',
|
||||||
|
isSelected
|
||||||
|
? 'text-primary-900 dark:text-primary-100 max-lg:bg-slate-100 max-lg:dark:bg-zinc-800'
|
||||||
|
: 'text-slate-600 dark:text-zinc-400',
|
||||||
clazz,
|
clazz,
|
||||||
]}
|
]}
|
||||||
|
shadow="none"
|
||||||
size="custom"
|
size="custom"
|
||||||
rounding="none"
|
rounding="none"
|
||||||
{href}
|
{href}
|
||||||
title={label}
|
title={label}
|
||||||
style="transition-property: background-color, filter;"
|
style="transition-property: background-color, filter;"
|
||||||
|
aria-selected={isSelected}
|
||||||
>
|
>
|
||||||
{#snippet prefix()}
|
{#snippet prefix()}
|
||||||
{#if icon}
|
<div class={(icon || customIcon) && adaptive ? 'lg:hidden' : ''}>
|
||||||
<div class="lg:hidden">
|
{#if icon}
|
||||||
<Icon src={icon} size="18" />
|
<Icon src={icon} size="20" />
|
||||||
</div>
|
{:else}
|
||||||
<div class="max-lg:hidden">
|
{@render customIcon?.({ size: 16, isSelected })}
|
||||||
<Icon src={icon} micro solid={isSelected} size="16" />
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
{:else}
|
|
||||||
{@render customIcon?.({ size: 16, isSelected })}
|
|
||||||
{/if}
|
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<span class="hidden {adaptive ? 'lg:block' : ''}">{label}</span>
|
<span class="hidden {adaptive ? 'lg:block' : ''}">{label}</span>
|
||||||
{@render children?.()}
|
{@render children?.()}
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { notifications, profile } from '$lib/auth.svelte.js'
|
import { notifications, profile } from '$lib/auth.svelte.js'
|
||||||
import ShieldIcon from '$lib/components/lemmy/moderation/ShieldIcon.svelte'
|
|
||||||
import {
|
import {
|
||||||
amModOfAny,
|
amModOfAny,
|
||||||
isAdmin,
|
isAdmin,
|
||||||
@@ -9,15 +8,18 @@
|
|||||||
import { t } from '$lib/i18n/translations'
|
import { t } from '$lib/i18n/translations'
|
||||||
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
import { LINKED_INSTANCE_URL } from '$lib/instance.svelte'
|
||||||
import { site } from '$lib/lemmy.svelte.js'
|
import { site } from '$lib/lemmy.svelte.js'
|
||||||
import { Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
import { Badge, Menu, MenuButton, MenuDivider, Spinner } from 'mono-svelte'
|
||||||
import {
|
import {
|
||||||
|
Bell,
|
||||||
GlobeAlt,
|
GlobeAlt,
|
||||||
Icon,
|
Icon,
|
||||||
|
Inbox,
|
||||||
MagnifyingGlass,
|
MagnifyingGlass,
|
||||||
Newspaper,
|
Newspaper,
|
||||||
PencilSquare,
|
PencilSquare,
|
||||||
Plus,
|
Plus,
|
||||||
ServerStack,
|
ServerStack,
|
||||||
|
ShieldCheck,
|
||||||
} from 'svelte-hero-icons'
|
} from 'svelte-hero-icons'
|
||||||
import type { ClassValue } from 'svelte/elements'
|
import type { ClassValue } from 'svelte/elements'
|
||||||
import Logo from '../Logo.svelte'
|
import Logo from '../Logo.svelte'
|
||||||
@@ -34,6 +36,15 @@
|
|||||||
let { style = '', class: clazz = '' }: Props = $props()
|
let { style = '', class: clazz = '' }: Props = $props()
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{#snippet notifBadge(number: number)}
|
||||||
|
<Badge
|
||||||
|
color={number > 0 ? 'red-subtle' : 'gray-subtle'}
|
||||||
|
class="min-w-5 h-5 p-0! px-0.5 grid place-items-center ml-auto"
|
||||||
|
>
|
||||||
|
{number > 99 ? '∞' : number}
|
||||||
|
</Badge>
|
||||||
|
{/snippet}
|
||||||
|
|
||||||
<CommandsWrapper bind:open={promptOpen} />
|
<CommandsWrapper bind:open={promptOpen} />
|
||||||
<nav
|
<nav
|
||||||
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border p-0.5
|
class="flex flex-row gap-2 items-center w-full mx-auto z-50 box-border p-0.5
|
||||||
@@ -71,7 +82,7 @@
|
|||||||
{/snippet}
|
{/snippet}
|
||||||
</NavButton>
|
</NavButton>
|
||||||
<div
|
<div
|
||||||
class="flex flex-row gap-2 py-2 px-2 items-center w-full overflow-auto"
|
class="flex flex-row gap-2 lg:gap-5 py-2 px-2 items-center w-full overflow-auto"
|
||||||
style="border-radius: inherit;"
|
style="border-radius: inherit;"
|
||||||
>
|
>
|
||||||
<div class="ml-auto"></div>
|
<div class="ml-auto"></div>
|
||||||
@@ -82,29 +93,15 @@
|
|||||||
icon={ServerStack}
|
icon={ServerStack}
|
||||||
class="relative"
|
class="relative"
|
||||||
isSelectedFilter={path => path.startsWith('/admin')}
|
isSelectedFilter={path => path.startsWith('/admin')}
|
||||||
>
|
/>
|
||||||
{#if ($notifications.applications ?? 0) > 0}
|
|
||||||
<div
|
|
||||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
|
||||||
></div>
|
|
||||||
{/if}
|
|
||||||
</NavButton>
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if amModOfAny(profile.data?.user)}
|
{#if amModOfAny(profile.data?.user)}
|
||||||
<NavButton
|
<NavButton
|
||||||
href="/moderation"
|
href="/moderation"
|
||||||
label={$t('nav.moderation')}
|
label={$t('nav.moderation')}
|
||||||
class="relative"
|
class="relative"
|
||||||
>
|
icon={ShieldCheck}
|
||||||
{#if ($notifications.reports ?? 0) > 0}
|
/>
|
||||||
<div
|
|
||||||
class="rounded-full w-2 h-2 bg-red-500 absolute -top-1 -left-1"
|
|
||||||
></div>
|
|
||||||
{/if}
|
|
||||||
{#snippet customIcon({ size, isSelected })}
|
|
||||||
<ShieldIcon filled={isSelected} width={size} />
|
|
||||||
{/snippet}
|
|
||||||
</NavButton>
|
|
||||||
{/if}
|
{/if}
|
||||||
<NavButton
|
<NavButton
|
||||||
href="/communities"
|
href="/communities"
|
||||||
@@ -112,13 +109,58 @@
|
|||||||
icon={GlobeAlt}
|
icon={GlobeAlt}
|
||||||
/>
|
/>
|
||||||
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
<NavButton href="/search" label={$t('nav.search')} icon={MagnifyingGlass} />
|
||||||
|
{#if profile.data.jwt}
|
||||||
|
{@const linkOnly =
|
||||||
|
!profile.data.user ||
|
||||||
|
!(isAdmin(profile.data.user) || amModOfAny(profile.data.user))}
|
||||||
|
<Menu manual={linkOnly} placement="top">
|
||||||
|
{#snippet target()}
|
||||||
|
<NavButton
|
||||||
|
label={$t('nav.notifications')}
|
||||||
|
icon={Bell}
|
||||||
|
class="relative"
|
||||||
|
adaptive={false}
|
||||||
|
href={linkOnly ? '/inbox' : undefined}
|
||||||
|
>
|
||||||
|
{#if Math.max(...Object.values($notifications)) > 0}
|
||||||
|
<div
|
||||||
|
class="rounded-full w-2 h-2 bg-red-500 absolute top-1 left-3 z-10"
|
||||||
|
></div>
|
||||||
|
{/if}
|
||||||
|
</NavButton>
|
||||||
|
{/snippet}
|
||||||
|
<MenuDivider>{$t('nav.notifications')}</MenuDivider>
|
||||||
|
<MenuButton href="/inbox" icon={Inbox}>
|
||||||
|
{$t('profile.inbox')}
|
||||||
|
{#snippet suffix()}
|
||||||
|
{@render notifBadge($notifications.inbox)}
|
||||||
|
{/snippet}
|
||||||
|
</MenuButton>
|
||||||
|
{#if amModOfAny(profile.data.user)}
|
||||||
|
<MenuButton href="/moderation" icon={ShieldCheck}>
|
||||||
|
{$t('routes.moderation.reports')}
|
||||||
|
{#snippet suffix()}
|
||||||
|
{@render notifBadge($notifications.reports)}
|
||||||
|
{/snippet}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
{#if profile.data.user && isAdmin(profile.data.user)}
|
||||||
|
<MenuButton href="/admin/applications" icon={ServerStack}>
|
||||||
|
{$t('routes.admin.applications.title')}
|
||||||
|
{#snippet suffix()}
|
||||||
|
{@render notifBadge($notifications.applications)}
|
||||||
|
{/snippet}
|
||||||
|
</MenuButton>
|
||||||
|
{/if}
|
||||||
|
</Menu>
|
||||||
|
{/if}
|
||||||
<Menu placement="top">
|
<Menu placement="top">
|
||||||
{#snippet target()}
|
{#snippet target()}
|
||||||
<NavButton
|
<NavButton
|
||||||
class="relative"
|
class="relative"
|
||||||
color="primary"
|
|
||||||
label={$t('nav.create.label')}
|
label={$t('nav.create.label')}
|
||||||
icon={Plus}
|
icon={Plus}
|
||||||
|
adaptive={false}
|
||||||
/>
|
/>
|
||||||
{/snippet}
|
{/snippet}
|
||||||
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
<MenuDivider>{$t('nav.create.label')}</MenuDivider>
|
||||||
|
|||||||
@@ -80,11 +80,6 @@
|
|||||||
alt={profile.data.user.local_user_view.person.name}
|
alt={profile.data.user.local_user_view.person.name}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{#if $notifications.inbox > 0}
|
|
||||||
<div
|
|
||||||
class="rounded-full w-2 h-2 bg-red-500 absolute top-0 left-0 z-10"
|
|
||||||
></div>
|
|
||||||
{/if}
|
|
||||||
{:else}
|
{:else}
|
||||||
<div class="w-full h-full grid place-items-center">
|
<div class="w-full h-full grid place-items-center">
|
||||||
<Icon src={Bars3} micro size="18" />
|
<Icon src={Bars3} micro size="18" />
|
||||||
|
|||||||
@@ -48,7 +48,8 @@
|
|||||||
"setTheme": "Set theme",
|
"setTheme": "Set theme",
|
||||||
"setThemeTo": "Set theme to {{default}}",
|
"setThemeTo": "Set theme to {{default}}",
|
||||||
"contextual": "On this page"
|
"contextual": "On this page"
|
||||||
}
|
},
|
||||||
|
"notifications": "Notifications"
|
||||||
},
|
},
|
||||||
"account": {
|
"account": {
|
||||||
"login": "Log In",
|
"login": "Log In",
|
||||||
@@ -331,7 +332,8 @@
|
|||||||
"unresolve": "Unresolve",
|
"unresolve": "Unresolve",
|
||||||
"resolvedBy": "Resolved by",
|
"resolvedBy": "Resolved by",
|
||||||
"markAll": "Mark page resolved",
|
"markAll": "Mark page resolved",
|
||||||
"markAllComplete": "Batch action completed."
|
"markAllComplete": "Batch action completed.",
|
||||||
|
"reports": "Reports"
|
||||||
},
|
},
|
||||||
"admin": {
|
"admin": {
|
||||||
"title": "Administration",
|
"title": "Administration",
|
||||||
|
|||||||
@@ -54,16 +54,16 @@ export async function postFeed(args: {
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
const defaultFeed = $state({
|
||||||
postFeeds.value[args.id]?.data ?? {
|
...args.request,
|
||||||
...args.request,
|
posts: posts,
|
||||||
posts: posts,
|
cursor: {
|
||||||
cursor: {
|
next: posts.next_page,
|
||||||
next: posts.next_page,
|
},
|
||||||
},
|
type_: args.request.type_,
|
||||||
type_: args.request.type_,
|
})
|
||||||
}
|
|
||||||
)
|
return postFeeds.value[args.id]?.data ?? defaultFeed
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getPostFeed(feeds: Map<PostFeedID, PostFeed>, id: PostFeedID) {
|
export function getPostFeed(feeds: Map<PostFeedID, PostFeed>, id: PostFeedID) {
|
||||||
|
|||||||
@@ -15,8 +15,8 @@
|
|||||||
|
|
||||||
let { data = $bindable() } = $props()
|
let { data = $bindable() } = $props()
|
||||||
|
|
||||||
let type = $state(data.feed.value.type_)
|
let type = $state(data.feed.type_)
|
||||||
let sort = $state(data.feed.value.sort)
|
let sort = $state(data.feed.sort)
|
||||||
|
|
||||||
$effect(() => {
|
$effect(() => {
|
||||||
if (type) settings.defaultSort.feed = type
|
if (type) settings.defaultSort.feed = type
|
||||||
@@ -62,8 +62,8 @@
|
|||||||
</header>
|
</header>
|
||||||
|
|
||||||
<FeedComponent
|
<FeedComponent
|
||||||
bind:posts={data.feed.value.posts.posts}
|
bind:posts={data.feed.posts.posts}
|
||||||
bind:feedData={data.feed.value}
|
bind:feedData={data.feed}
|
||||||
feedId="main"
|
feedId="main"
|
||||||
/>
|
/>
|
||||||
<svelte:element
|
<svelte:element
|
||||||
@@ -73,7 +73,7 @@
|
|||||||
class="mt-auto"
|
class="mt-auto"
|
||||||
>
|
>
|
||||||
<Pageination
|
<Pageination
|
||||||
cursor={{ next: data.feed.value.cursor.next }}
|
cursor={{ next: data.feed.cursor.next }}
|
||||||
href={page =>
|
href={page =>
|
||||||
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
typeof page == 'number' ? `?page=${page}` : `?cursor=${page}`}
|
||||||
back={false}
|
back={false}
|
||||||
|
|||||||
+12
-14
@@ -14,20 +14,18 @@ export async function load({ url, fetch }) {
|
|||||||
(url.searchParams.get('type') as ListingType) || settings.defaultSort.feed
|
(url.searchParams.get('type') as ListingType) || settings.defaultSort.feed
|
||||||
|
|
||||||
return {
|
return {
|
||||||
feed: new ReactiveState(
|
feed: await postFeed({
|
||||||
await postFeed({
|
id: 'main',
|
||||||
id: 'main',
|
request: {
|
||||||
request: {
|
page_cursor: cursor,
|
||||||
page_cursor: cursor,
|
sort: sort,
|
||||||
sort: sort,
|
type_: listingType,
|
||||||
type_: listingType,
|
limit: 20,
|
||||||
limit: 20,
|
show_hidden: settings.posts.showHidden,
|
||||||
show_hidden: settings.posts.showHidden,
|
},
|
||||||
},
|
url: url,
|
||||||
url: url,
|
fetch: fetch,
|
||||||
fetch: fetch,
|
}),
|
||||||
}),
|
|
||||||
),
|
|
||||||
contextual: {
|
contextual: {
|
||||||
actions: [
|
actions: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ import type { SortType } from 'lemmy-js-client'
|
|||||||
|
|
||||||
export async function load({ url, fetch, parent }) {
|
export async function load({ url, fetch, parent }) {
|
||||||
const page = Number(url.searchParams.get('page')) || 1
|
const page = Number(url.searchParams.get('page')) || 1
|
||||||
const type: 'comments' | 'posts' =
|
const type: 'comments' | 'posts' | 'all' =
|
||||||
(url.searchParams.get('type') as 'comments' | 'posts') || 'posts'
|
(url.searchParams.get('type') as 'comments' | 'posts' | 'all') || 'all'
|
||||||
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
const sort: SortType = (url.searchParams.get('sort') as SortType) || 'New'
|
||||||
|
|
||||||
const { my_user } = await parent()
|
const { my_user } = await parent()
|
||||||
|
|||||||
Reference in new issue
Block a user