From d489a67a228c77715efb2843316bff902b62405e Mon Sep 17 00:00:00 2001 From: Justin Edmund Date: Wed, 25 Jan 2023 22:46:27 -0800 Subject: [PATCH] Set cookie properly on toast dismissal --- components/HeaderMenu/index.tsx | 3 --- components/Layout/index.tsx | 29 ++++++++++++++++++++--------- components/Toast/index.tsx | 3 ++- components/UpdateToast/index.tsx | 16 ++++++---------- 4 files changed, 28 insertions(+), 23 deletions(-) diff --git a/components/HeaderMenu/index.tsx b/components/HeaderMenu/index.tsx index 8ad9244c..d42795b2 100644 --- a/components/HeaderMenu/index.tsx +++ b/components/HeaderMenu/index.tsx @@ -8,10 +8,7 @@ import { retrieveCookies, retrieveLocaleCookies } from '~utils/retrieveCookies' import Link from 'next/link' import * as Switch from '@radix-ui/react-switch' -import AboutModal from '~components/AboutModal' import AccountModal from '~components/AccountModal' -import ChangelogModal from '~components/ChangelogModal' -import RoadmapModal from '~components/RoadmapModal' import LoginModal from '~components/LoginModal' import SignupModal from '~components/SignupModal' diff --git a/components/Layout/index.tsx b/components/Layout/index.tsx index 224eb7b0..f37d4dac 100644 --- a/components/Layout/index.tsx +++ b/components/Layout/index.tsx @@ -1,4 +1,5 @@ import { PropsWithChildren, useEffect, useState } from 'react' +import { useRouter } from 'next/router' import { add, format } from 'date-fns' import { getCookie } from 'cookies-next' @@ -12,6 +13,7 @@ import './index.scss' interface Props {} const Layout = ({ children }: PropsWithChildren) => { + const router = useRouter() const [updateToastOpen, setUpdateToastOpen] = useState(false) useEffect(() => { @@ -35,21 +37,30 @@ const Layout = ({ children }: PropsWithChildren) => { setUpdateToastOpen(false) } - function handleToastOpenChanged(open: boolean) { + function handleToastClosed() { setUpdateToastOpen(false) } + const updateToast = () => { + const path = router.asPath.replaceAll('/', '') + + return !['about', 'updates', 'roadmap'].includes(path) ? ( + + ) : ( + '' + ) + } + return ( <> - {/* TODO: Don't show toast on about pages */} - + {updateToast()}
{children}
) diff --git a/components/Toast/index.tsx b/components/Toast/index.tsx index 95878f2f..8f85cb50 100644 --- a/components/Toast/index.tsx +++ b/components/Toast/index.tsx @@ -8,6 +8,7 @@ interface Props extends ToastPrimitive.ToastProps { className?: string title?: string content: string + onCloseClick: () => void } const Toast = ({ @@ -28,7 +29,7 @@ const Toast = ({

{title}

)} - + × diff --git a/components/UpdateToast/index.tsx b/components/UpdateToast/index.tsx index 79ea4caf..29403e04 100644 --- a/components/UpdateToast/index.tsx +++ b/components/UpdateToast/index.tsx @@ -15,7 +15,7 @@ interface Props { updateType: 'feature' | 'content' lastUpdated: string onActionClicked: () => void - onOpenChange: (open: boolean) => void + onCloseClicked: () => void } const UpdateToast = ({ @@ -23,7 +23,7 @@ const UpdateToast = ({ updateType, lastUpdated, onActionClicked, - onOpenChange, + onCloseClicked, }: Props) => { const { t } = useTranslation('roadmap') @@ -42,18 +42,14 @@ const UpdateToast = ({ } function handleButtonClicked() { - // TODO: Set a timestamped cookie to not show - console.log('Primary button clicked') window.open('/about', '_blank') setToastCookie() onActionClicked() } - function handleOpenChanged(open: boolean) { - if (!open) { - setToastCookie() - onOpenChange(false) - } + function handleCloseClicked() { + setToastCookie() + onCloseClicked() } return ( @@ -63,7 +59,7 @@ const UpdateToast = ({ content={t(`toasts.description.${updateType}`)} open={open} type="background" - onOpenChange={handleOpenChanged} + onCloseClick={handleCloseClicked} >