From 42234eae9b71772ea313d7a463524f6b718248db Mon Sep 17 00:00:00 2001 From: keyan Date: Thu, 3 Aug 2023 19:14:04 -0500 Subject: [PATCH] highlight notification on back button --- components/form.js | 2 +- components/notifications.js | 39 ++++++++++++++++++++++++------------- 2 files changed, 26 insertions(+), 15 deletions(-) diff --git a/components/form.js b/components/form.js index 769ca680..ee481a4f 100644 --- a/components/form.js +++ b/components/form.js @@ -431,7 +431,7 @@ export function Checkbox ({ children, label, groupClassName, hiddenLabel, extra, handleChange && handleChange(e.target.checked, helpers.setValue) }} /> - +
{label}
{extra &&
diff --git a/components/notifications.js b/components/notifications.js index 5f4cb174..c4a352d4 100644 --- a/components/notifications.js +++ b/components/notifications.js @@ -37,12 +37,22 @@ function Notification ({ n }) { return null } -function NotificationLayout ({ children, href, as }) { +function NotificationLayout ({ children, nid, href, as }) { const router = useRouter() return (
!ignoreClick(e) && router.push(href, as)} + className={`clickToContext ${router?.query?.nid === nid ? 'outline-it' : ''}`} + onClick={(e) => { + if (ignoreClick(e)) return + nid && router.replace({ + pathname: router.pathname, + query: { + ...router.query, + nid + } + }, router.asPath, { ...router.options, shallow: true }) + router.push(href, as) + }} > {children}
@@ -145,7 +155,7 @@ function EarnNotification ({ n }) { function Invitification ({ n }) { return ( - + your invite has been redeemed by {n.invite.invitees.length} stackers @@ -163,7 +173,7 @@ function Invitification ({ n }) { function InvoicePaid ({ n }) { return ( - +
{n.earnedSats} sats were deposited in your account {timeSince(new Date(n.sortTime))} @@ -174,7 +184,7 @@ function InvoicePaid ({ n }) { function Referral ({ n }) { return ( - + someone joined via one of your referral links {timeSince(new Date(n.sortTime))} @@ -185,7 +195,7 @@ function Referral ({ n }) { function Votification ({ n }) { return ( - + your {n.item.title ? 'post' : 'reply'} {n.item.fwdUser ? 'forwarded' : 'stacked'} {n.earnedSats} sats{n.item.fwdUser && ` to @${n.item.fwdUser.name}`} @@ -206,7 +216,7 @@ function Votification ({ n }) { function Mention ({ n }) { return ( - + you were mentioned in @@ -226,7 +236,7 @@ function Mention ({ n }) { function JobChanged ({ n }) { return ( - + {n.item.status === 'ACTIVE' ? 'your job is active again' @@ -241,7 +251,7 @@ function JobChanged ({ n }) { function Reply ({ n }) { return ( - +
{n.item.title ? @@ -316,12 +326,14 @@ export function NotificationAlert () { ) } +const nid = n => n.__typename + n.id + n.sortTime + export default function Notifications ({ ssrData }) { const { data, fetchMore } = useQuery(NOTIFICATIONS) const client = useApolloClient() const router = useRouter() - const { notifications: { notifications, earn, lastChecked, cursor } } = useMemo(() => { + const { notifications: { notifications, lastChecked, cursor } } = useMemo(() => { return data || ssrData || { notifications: {} } }, [data, ssrData]) @@ -361,13 +373,12 @@ export default function Notifications ({ ssrData }) { return ( <>
- {earn && } {fresh.map((n, i) => ( - + ))}
{old.map((n, i) => ( - + ))}