Release 202506091000
This commit is contained in:
@@ -27,6 +27,8 @@ const count =
|
||||
user && (
|
||||
<a
|
||||
href="/notifications"
|
||||
data-notification-count-link
|
||||
data-current-count={count}
|
||||
class={cn(
|
||||
'group relative flex cursor-pointer items-center justify-center text-gray-400 transition-colors duration-100 hover:text-white',
|
||||
className
|
||||
@@ -35,11 +37,32 @@ const count =
|
||||
{...htmlProps}
|
||||
>
|
||||
<Icon name="material-symbols:notifications-outline" class="size-5" />
|
||||
{count > 0 && (
|
||||
<span class="absolute top-[calc(50%-var(--spacing)*3.5)] right-[calc(50%-var(--spacing)*3.5)] flex size-3.5 items-center justify-center rounded-full bg-blue-600 text-[10px] font-bold tracking-tighter text-white group-hover:bg-blue-500">
|
||||
{count > 99 ? '★' : count.toLocaleString()}
|
||||
</span>
|
||||
)}
|
||||
<span
|
||||
data-notification-count-badge
|
||||
class="absolute top-[calc(50%-var(--spacing)*3.5)] right-[calc(50%-var(--spacing)*3.5)] flex size-3.5 items-center justify-center rounded-full bg-blue-600 text-[10px] font-bold tracking-tighter text-white group-hover:bg-blue-500 empty:hidden"
|
||||
>
|
||||
{count > 0 ? (count > 99 ? '★' : count.toLocaleString()) : ''}
|
||||
</span>
|
||||
</a>
|
||||
)
|
||||
}
|
||||
|
||||
<script>
|
||||
document.addEventListener('sse-new-notification', () => {
|
||||
document.querySelectorAll<HTMLElement>('[data-notification-count-link]').forEach((link) => {
|
||||
const currentCount = Number(link.getAttribute('data-current-count') || 0)
|
||||
const newCount = currentCount + 1
|
||||
|
||||
link.querySelectorAll<HTMLElement>('[data-notification-count-badge]').forEach((badge) => {
|
||||
badge.textContent = newCount > 0 ? (newCount > 99 ? '★' : newCount.toLocaleString()) : ''
|
||||
})
|
||||
|
||||
link.setAttribute(
|
||||
'aria-label',
|
||||
`Go to notifications${newCount > 0 ? ` (${newCount.toLocaleString()} unread)` : ''}`
|
||||
)
|
||||
|
||||
link.setAttribute('data-current-count', String(newCount))
|
||||
})
|
||||
})
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user