Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116<script lang="ts"> import BellOff from "$icon/bell-off"; import Inbox from "$icon/inbox"; import EmptyState from "$lib/components/ui/EmptyState.svelte"; import NotificationItem from "$lib/components/notifications/NotificationItem.svelte"; import notificationsNotificationlistSkeletonFixture from "$lib/bones/notifications-notificationlist--skeleton-fixture.bones.json"; import notificationsSociallistSkeletonFixture from "$lib/bones/notifications-notificationlist--social-skeleton-fixture.bones.json"; import Bones from "$lib/components/ui/Bones.svelte"; import { groupNotificationsByDate } from "$lib/components/notifications/notification"; import { formatCount } from "$lib/format"; import type { NotificationSummary, ReadFilter } from "$lib/components/notifications/types";
interface Props { notifications?: NotificationSummary[]; title?: string; unreadCount?: number; readFilter?: ReadFilter; border?: boolean; grouped?: boolean; loading?: boolean; onToggleRead?: (uri: string, read: boolean) => void; }
let { notifications = [], title, unreadCount = 0, readFilter = "inbox", border = true, grouped = true, loading = false, onToggleRead }: Props = $props();
const groups = $derived(groupNotificationsByDate(notifications)); const empty = $derived(notifications.length === 0);
const sections = $derived( grouped ? [ { label: "Today", items: groups.today }, { label: "This week", items: groups.thisWeek }, { label: "Older", items: groups.older } ] : [{ label: "", items: notifications }] );</script>
{#if loading} <Bones capture={title === "social" ? notificationsSociallistSkeletonFixture : notificationsNotificationlistSkeletonFixture} />{:else} <!-- the list owns the columns and every row subscribes to them with subgrid, so the lead column measures the widest issue number in the whole list rather than the one number in its own row.
divide-y hangs the separator off the bottom of each child, so the line above a row belongs to the row before it. a hovered row has to reach back one sibling to recolor that line, and data-notification is what tells a row from a date heading. --> <div class="grid h-fit grid-cols-[auto_1fr_auto] content-start gap-x-4 divide-y divide-border-default overflow-hidden pointer-fine:[&>*:has(+[data-notification]:hover)]:border-border-disabled {border ? 'rounded-sm border border-border-default' : ''}" > {#if title || unreadCount > 0} <div class="col-span-full flex items-center justify-between bg-background-default p-2 md:px-4" > <h2 class="typography-paragraph-small font-medium text-foreground-default capitalize" > {title} </h2> {#if unreadCount > 0} <span class="flex h-5 min-w-5 items-center justify-center rounded-full bg-background-info-emphasis px-1 typography-paragraph-small text-foreground-on-emphasis" > {formatCount(unreadCount)} </span> {/if} </div> {/if}
{#if empty} <div class="col-span-full"> <EmptyState border={false} background icon={readFilter === "unread" ? Inbox : BellOff} message={readFilter === "unread" ? "All caught up!" : "No notifications"} /> </div> {:else} {#each sections as section (section.label)} {#if section.items.length > 0} {#if section.label} <div class="col-span-full bg-background-subtle p-2 typography-paragraph-small text-foreground-muted md:px-4" > {section.label} </div> {/if} {#each section.items as notification (notification.uri)} <NotificationItem {notification} {onToggleRead} /> {/each} {/if} {/each} {/if} </div>{/if}