Skip to content

Commit 3f0d83f

Browse files
committed
Use cookie to stop banner from displaying for 7 days after closing
1 parent 9a68637 commit 3f0d83f

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

src/app/layouts/default/lower-sticky-note/lower-sticky-note.tsx

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,36 @@
11
import React from 'react';
22
import {usePutAway, useStickyData} from '../shared.js';
33
import JITLoad from '~/helpers/jit-load';
4+
import Cookies from 'js-cookie';
5+
6+
const cookieKey = 'lower-sticky-note-closed';
47

58
export default function LowerStickyNote() {
69
const stickyData = useStickyData();
710
const [closed, PutAway] = usePutAway();
8-
const shouldNotDisplay = !stickyData || closed ||
9-
stickyData.mode !== 'banner';
11+
const shouldNotDisplay =
12+
!stickyData ||
13+
closed ||
14+
stickyData?.mode !== 'banner' ||
15+
Boolean(Cookies.get(cookieKey));
16+
const hasDisplayed = React.useRef(false);
17+
18+
React.useEffect(() => {
19+
if (hasDisplayed.current && closed) {
20+
Cookies.set(cookieKey, 'true', {expires: 7});
21+
}
22+
}, [closed]);
1023

1124
if (shouldNotDisplay) {
1225
return null;
1326
}
1427

28+
hasDisplayed.current = true;
29+
1530
return (
1631
<JITLoad
17-
importFn={() => import('./lsn-content')} stickyData={stickyData}
32+
importFn={() => import('./lsn-content.js')}
33+
stickyData={stickyData}
1834
PutAway={PutAway}
1935
/>
2036
);

0 commit comments

Comments
 (0)