Something went wrong. Try again.
Monorepo for Tangled forked from tangled.org/core
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169<script module lang="ts"> import { tv, type VariantProps } from "tailwind-variants";
export const notificationItem = tv({ slots: { // the row subscribes to NotificationList's columns, so every row shares one // lead column width and the descriptions line up down the whole list. it // only lays out correctly inside that grid. root: "group/notification relative isolate col-span-full grid grid-cols-subgrid items-center gap-y-xs rounded-(--notification-radius) px-xs py-sm hover:bg-background-canvas md:px-sm dark:hover:bg-background-inset", icon: "row-start-1 size-3.5 shrink-0", dot: "flex shrink-0 overflow-hidden transition-[width,opacity] duration-200 ease-out motion-reduce:transition-none", header: "row-start-1 flex min-w-0 items-center overflow-hidden typography-paragraph-small", phrase: "max-w-full shrink-0 truncate text-inherit no-underline before:whitespace-pre before:content-['_'] after:absolute after:inset-0 after:z-1 hover:no-underline", meta: "row-start-1 flex items-center justify-end", timing: "relative flex items-center", time: "typography-paragraph-small whitespace-nowrap text-foreground-subtle", toggle: "absolute inset-0 z-10 hidden items-center justify-end text-foreground-placeholder hover:cursor-pointer hover:text-foreground-muted md:group-hover/notification:flex", subject: "col-span-2 col-start-2 row-start-2 flex min-w-0 typography-paragraph-small text-foreground-subtle *:not-first:before:whitespace-pre *:not-first:before:content-['_']", repo: "max-w-full shrink-0 truncate text-foreground-muted", number: "shrink-0", title: "truncate" }, variants: { read: { true: { header: "text-foreground-subtle", dot: "w-0 opacity-0" }, false: { header: "text-foreground-default", dot: "w-3.5" } } }, defaultVariants: { read: true } });
export type NotificationItemVariants = VariantProps<typeof notificationItem>;</script>
<script lang="ts"> import { flushSync } from "svelte"; import type { Attachment } from "svelte/attachments"; import Mail from "$icon/mail"; import MailCheck from "$icon/mail-check"; import { buttonIcon } from "#lib/components/ui/Button.svelte"; import ColorBall from "#lib/components/ui/ColorBall.svelte"; import TimeAgo from "#lib/components/ui/TimeAgo.svelte"; import User from "#lib/components/ui/User.svelte"; import { notificationHref, notificationIcon, notificationPhrase, notificationTarget, notificationTone } from "#lib/components/notifications/notification.ts"; import type { NotificationSummary } from "#lib/components/notifications/types.ts";
interface Props { notification: NotificationSummary; compact?: boolean; onToggleRead?: (uri: string, read: boolean) => void; }
let { notification, compact = false, onToggleRead }: Props = $props();
const style = $derived(notificationItem({ read: notification.read })); const Icon = $derived(notificationIcon(notification.type)); // resolve() would mangle the raw at:// uri here (collapses "//"), so it's used as-is const href = $derived(notificationHref(notification)); let includingOwner = $state(true); const target = $derived(notificationTarget(notification, includingOwner));
const truncates = (element: Element) => [...element.querySelectorAll("*")].some( (child) => getComputedStyle(child).textOverflow === "ellipsis" && child.scrollWidth > child.clientWidth + 1 );
const fit: Attachment<HTMLElement> = (line) => { const observer = new ResizeObserver(() => { includingOwner = true; flushSync(); if (!truncates(line)) return; includingOwner = false; flushSync(); }); observer.observe(line); for (const child of line.children) observer.observe(child); return () => observer.disconnect(); };
const toggle = () => onToggleRead?.(notification.uri, !notification.read);
const open = (event: MouseEvent & { currentTarget: HTMLAnchorElement }) => { onToggleRead?.(notification.uri, true); const popover = event.currentTarget.closest("[popover]"); if (popover instanceof HTMLElement) popover.hidePopover(); };</script>
<div data-testid="notificationRow" data-uri={notification.uri} data-type={notification.type} data-notification class={style.root()}> <Icon class={style.icon({ class: notificationTone(notification.type) })} aria-hidden="true" />
<div class={style.header()} {@attach !compact && fit}> <span class={style.dot()} aria-hidden="true"> <ColorBall color="var(--color-background-info-emphasis)" /> </span> <User handle={notification.actor.handle} did={notification.actor.did} size="small" class="min-w-0" /> <!-- the href embeds an at:// subject uri whose // resolve() would collapse --> <!-- eslint-disable-next-line svelte/no-navigation-without-resolve --> <a data-testid="notificationPhraseLink" {href} class={style.phrase()} onclick={open}> {notificationPhrase(notification, !compact)} {#if !compact && target} <span>{target}</span> {/if} </a> </div>
<div class={style.meta()}> <div class={style.timing()}> <TimeAgo value={notification.createdAt} class={style.time({ class: onToggleRead ? "md:group-hover/notification:invisible" : undefined })} /> {#if onToggleRead} <button type="button" class={style.toggle()} title={notification.read ? "Mark as unread" : "Mark as read"} aria-label={notification.read ? "Mark as unread" : "Mark as read"} onclick={toggle} > {#if notification.read} <Mail class={buttonIcon({ size: "small" })} aria-hidden="true" /> {:else} <MailCheck class={buttonIcon({ size: "small" })} aria-hidden="true" /> {/if} </button> {/if} </div> </div>
{#if (compact && target) || notification.subject} <div class={style.subject()} {@attach compact && fit}> {#if compact && target} <span class={style.repo()}>{target}</span> {/if} {#if notification.subject} <span class={style.number()}>#{notification.subject.number}</span> {#if notification.subject.title} <span class={style.title()}>{notification.subject.title}</span> {/if} {/if} </div> {/if}</div>