From a4f7f8eb3fbbb4404288506fa56d94dcde00c746 Mon Sep 17 00:00:00 2001 From: fsimonjetz Date: Wed, 10 Jul 2024 10:56:34 +0000 Subject: [PATCH] store banner state in cookie --- src/Banner.tsx | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/Banner.tsx b/src/Banner.tsx index c2338e2e5..5c41123c5 100644 --- a/src/Banner.tsx +++ b/src/Banner.tsx @@ -2,13 +2,25 @@ import React, { useState } from 'react' import Alert from 'react-bootstrap/Alert' import './Header.css' import { Container } from 'react-bootstrap' +import { set as setCookie, get as getCookie } from 'es-cookie' -function AlertDismissibleExample(): JSX.Element | null { - const [show, setShow] = useState(true) +function InfoBanner(): JSX.Element | null { + const initialState = getCookie('eblShowInfoBanner') !== 'false' + const [show, setShow] = useState(initialState) + + const midnight = new Date() + midnight.setHours(23, 59, 59) return show ? ( - setShow(false)} dismissible> + { + setShow(false) + setCookie('eblShowInfoBanner', 'false', { expires: midnight }) + }} + dismissible + > Scheduled Maintenance Notice: Our servers will be undergoing planned maintenance on{' '} @@ -21,4 +33,4 @@ function AlertDismissibleExample(): JSX.Element | null { ) : null } -export default AlertDismissibleExample +export default InfoBanner