Files
katelyatv/src/components/HubBell.tsx
T

52 lines
1.7 KiB
TypeScript

'use client';
import { useEffect } from 'react';
export default function HubBell({ forceShow = false }: { forceShow?: boolean }) {
useEffect(() => {
const t = setTimeout(() => {
fetch('/api/license-config', { cache: 'no-store' })
.then((r) => r.json())
.then((j) => {
try {
const a = j && j.data && j.data.announcement;
if (!a) return;
const seen = JSON.parse(
localStorage.getItem('hub_seen') || '{}'
);
if (!seen['a' + a.id]) {
const d = document.querySelector('.mv-bell-dot');
if (d) (d as HTMLElement).style.display = 'block';
}
} catch {}
})
.catch(() => {});
}, 1500);
return () => clearTimeout(t);
}, []);
return (
<button
onClick={() => {
try {
localStorage.removeItem('hasSeenAnnouncement');
} catch {}
if (location.pathname === '/') location.reload();
else location.href = '/';
}}
title='公告通知'
className={
forceShow
? 'relative flex items-center justify-center w-8 h-8 rounded-lg text-base text-gray-200 hover:text-white hover:bg-white/10 transition-colors duration-200'
: 'relative hidden md:flex items-center justify-center w-8 h-8 rounded-lg text-base text-gray-500 hover:text-purple-600 hover:bg-purple-500/10 dark:text-gray-400 dark:hover:text-purple-400 transition-colors duration-200'
}
>
<span className='leading-none'>🔔</span>
<span
className='mv-bell-dot absolute top-1.5 right-1.5 w-2 h-2 bg-red-500 rounded-full'
style={{ display: 'none' }}
/>
</button>
);
}