import { useApolloClient, useQuery } from '@apollo/client' import Button from 'react-bootstrap/Button' import { useState } from 'react' import Comment, { CommentSkeleton } from './comment' import Item from './item' import { NOTIFICATIONS } from '../fragments/notifications' import styles from './notifications.module.css' import { useRouter } from 'next/router' function Notification ({ key, n }) { const router = useRouter() const client = useApolloClient() return (
{ if (n.__typename === 'Reply' || !n.item.title) { // evict item from cache so that it has current state // e.g. if they previously visited before a recent comment client.cache.evict({ id: `Item:${n.item.parentId}` }) router.push({ pathname: '/items/[id]', query: { id: n.item.parentId, commentId: n.item.id } }, `/items/${n.item.parentId}`) } else { client.cache.evict({ id: `Item:${n.item.id}` }) router.push(`items/${n.item.id}`) } }} > {n.__typename === 'Votification' && your {n.item.title ? 'post' : 'reply'} stacked {n.earnedSats} sats} {n.__typename === 'Mention' && you were mentioned in}
{n.item.title ? : }
) } export default function Notifications ({ variables }) { const { loading, error, data, fetchMore } = useQuery(NOTIFICATIONS, { variables }) if (error) return
Failed to load!
if (loading) { return } const { notifications: { notifications, cursor, lastChecked } } = data const [fresh, old] = notifications.reduce((result, n) => { result[new Date(n.sortTime).getTime() > lastChecked ? 0 : 1].push(n) return result }, [[], []]) return ( <> {/* XXX we shouldn't use the index but we don't have a unique id in this union yet */}
{fresh.map((n, i) => ( ))}
{old.map((n, i) => ( ))} ) } function CommentsFlatSkeleton () { const comments = new Array(21).fill(null) return (
{comments.map((_, i) => ( ))}
) } function MoreFooter ({ cursor, fetchMore }) { const [loading, setLoading] = useState(false) if (loading) { return
} let Footer if (cursor) { Footer = () => ( ) } else { Footer = () => (
GENISIS
) } return
}