Hey is a decentralized and permissionless social media app built with Lens Protocol 馃尶
at main 29 lines 856 B view raw
1import { 2 NotificationOrderBy, 3 useNotificationIndicatorQuery 4} from "@hey/indexer"; 5import { useAccountStore } from "@/store/persisted/useAccountStore"; 6import { useNotificationStore } from "@/store/persisted/useNotificationStore"; 7 8const useHasNewNotifications = () => { 9 const { currentAccount } = useAccountStore(); 10 const { lastSeenNotificationId } = useNotificationStore(); 11 12 const { data } = useNotificationIndicatorQuery({ 13 skip: !currentAccount, 14 variables: { request: { orderBy: NotificationOrderBy.Default } } 15 }); 16 17 const latestNotificationWithId = data?.notifications?.items?.find( 18 (notification) => "id" in notification 19 ); 20 const latestId = latestNotificationWithId?.id; 21 22 if (!latestId || !currentAccount) { 23 return false; 24 } 25 26 return latestId !== lastSeenNotificationId; 27}; 28 29export default useHasNewNotifications;