feat: add reviews, notifications, notes and account hardening
This commit is contained in:
@@ -6,7 +6,7 @@ import {
|
||||
MoonMockIcon, PathMockIcon, SearchMockIcon, SignOutMockIcon, SunMockIcon, TeacherMockIcon,
|
||||
TrayMockIcon, UserMockIcon, VideoMockIcon,
|
||||
} from '../ui/MockupIcons';
|
||||
import { SidebarSimpleIcon } from '@phosphor-icons/react';
|
||||
import { BellIcon, SidebarSimpleIcon } from '@phosphor-icons/react';
|
||||
import { Logo } from '../Logo';
|
||||
import { Avatar } from '../ui/Avatar';
|
||||
import { useAuth } from '../../context/AuthContext';
|
||||
@@ -15,6 +15,7 @@ import { useCatalog } from '../../context/CatalogContext';
|
||||
import { NavKey, navKeyFor } from '../../lib/navigation';
|
||||
import { paths } from '../../lib/routes';
|
||||
import { readPreference, writePreference } from '../../lib/storage';
|
||||
import { getNotifications } from '../../services/notifications';
|
||||
|
||||
const GROUPS_KEY = 'ca-groups';
|
||||
const COLLAPSED_KEY = 'ca-side';
|
||||
@@ -47,6 +48,7 @@ export const Sidebar: React.FC = () => {
|
||||
const [shut, setShut] = useState<Record<string, boolean>>(readGroups);
|
||||
const [collapsed, setCollapsed] = useState(() => readPreference(COLLAPSED_KEY) === '1');
|
||||
const [menuOpen, setMenuOpen] = useState(false);
|
||||
const [unreadNotifications, setUnreadNotifications] = useState(0);
|
||||
const whoRef = useRef<HTMLButtonElement>(null);
|
||||
const menuRef = useRef<HTMLDivElement>(null);
|
||||
const [menuStyle, setMenuStyle] = useState<React.CSSProperties>({});
|
||||
@@ -60,6 +62,20 @@ export const Sidebar: React.FC = () => {
|
||||
|
||||
useEffect(() => setMenuOpen(false), [location.pathname]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!user) { setUnreadNotifications(0); return; }
|
||||
let cancelled = false;
|
||||
const refresh = () => {
|
||||
getNotifications().then((feed) => { if (!cancelled) setUnreadNotifications(feed.unread); }).catch(() => undefined);
|
||||
};
|
||||
refresh();
|
||||
window.addEventListener('compor:notifications-updated', refresh);
|
||||
return () => {
|
||||
cancelled = true;
|
||||
window.removeEventListener('compor:notifications-updated', refresh);
|
||||
};
|
||||
}, [user?.id, location.pathname]);
|
||||
|
||||
// The account menu lives on <body> with position: fixed, so the sidebar never clips it.
|
||||
useLayoutEffect(() => {
|
||||
if (!menuOpen || !whoRef.current) return;
|
||||
@@ -131,6 +147,10 @@ export const Sidebar: React.FC = () => {
|
||||
<button type="button" className="iconbtn" onClick={toggleCollapsed} aria-label={collapsed ? 'Expandir barra lateral' : 'Recolher barra lateral'} title={collapsed ? 'Expandir barra lateral' : 'Recolher barra lateral'}>
|
||||
<SidebarSimpleIcon className="ph" />
|
||||
</button>
|
||||
{user && <Link className="iconbtn notif" to={paths.notifications} aria-label={`Notificações${unreadNotifications ? `, ${unreadNotifications} não lidas` : ''}`} title="Notificações">
|
||||
<BellIcon className="ph" />
|
||||
{unreadNotifications > 0 && <span className="notif-badge">{unreadNotifications > 9 ? '9+' : unreadNotifications}</span>}
|
||||
</Link>}
|
||||
</div>
|
||||
<Link to={paths.explore} className="logo" aria-label="Compor Academy, início">
|
||||
<Logo width={96} />
|
||||
|
||||
Reference in New Issue
Block a user