story-research-zapwall/hooks/useNotificationCenter.ts
2025-12-22 09:48:57 +01:00

34 lines
635 B
TypeScript

import { useState } from 'react'
import type { Notification } from '@/types/notifications'
export function useNotificationCenter(
markAsRead: (id: string) => void,
onClose?: () => void
) {
const [isOpen, setIsOpen] = useState(false)
const handleToggle = () => {
setIsOpen((prev) => !prev)
}
const handleClose = () => {
setIsOpen(false)
onClose?.()
}
const handleNotificationClick = (notification: Notification) => {
if (!notification.read) {
markAsRead(notification.id)
}
handleClose()
}
return {
isOpen,
handleToggle,
handleClose,
handleNotificationClick,
}
}