ATlast — you'll never need to find your favorites on another platform again. Find your favs in the ATmosphere.
atproto
1import { useState, useCallback } from "react"; 2import type { NotificationType } from "../components/common/Notification"; 3 4export interface NotificationItem { 5 id: string; 6 type: NotificationType; 7 message: string; 8} 9 10export function useNotifications() { 11 const [notifications, setNotifications] = useState<NotificationItem[]>([]); 12 13 const addNotification = useCallback( 14 (type: NotificationType, message: string) => { 15 const id = `notification-${Date.now()}-${Math.random()}`; 16 setNotifications((prev) => [...prev, { id, type, message }]); 17 return id; 18 }, 19 [], 20 ); 21 22 const removeNotification = useCallback((id: string) => { 23 setNotifications((prev) => prev.filter((n) => n.id !== id)); 24 }, []); 25 26 const clearAll = useCallback(() => { 27 setNotifications([]); 28 }, []); 29 30 // Convenience methods 31 const success = useCallback( 32 (message: string) => addNotification("success", message), 33 [addNotification], 34 ); 35 36 const error = useCallback( 37 (message: string) => addNotification("error", message), 38 [addNotification], 39 ); 40 41 const info = useCallback( 42 (message: string) => addNotification("info", message), 43 [addNotification], 44 ); 45 46 const warning = useCallback( 47 (message: string) => addNotification("warning", message), 48 [addNotification], 49 ); 50 51 return { 52 notifications, 53 addNotification, 54 removeNotification, 55 clearAll, 56 success, 57 error, 58 info, 59 warning, 60 }; 61}