-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.tsx
47 lines (43 loc) · 1.26 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import Translate from '@docusaurus/Translate';
import React, { useEffect, useState } from 'react';
import CloseIcon from '@site/static/icons/close.svg';
import './index.scss';
export default function NavBanner({
isBannerVisible = false,
setIsBannerVisible
}: {
isBannerVisible: boolean;
setIsBannerVisible: React.Dispatch<React.SetStateAction<boolean>>;
}) {
const closeBanner = () => {
localStorage.setItem('bannerCloseTimestamp', Date.now().toString());
setIsBannerVisible(false);
};
const goDetail = () => {
window.open(`https://seaos.run`);
};
useEffect(() => {
const lastCloseTimestamp = +localStorage.getItem('bannerCloseTimestamp');
if (
window.location.hostname === 'sealos.io' &&
(!lastCloseTimestamp || Date.now() - lastCloseTimestamp > 7 * 24 * 60 * 60 * 1000)
) {
setIsBannerVisible(true);
} else {
setIsBannerVisible(false);
}
}, []);
return (
<>
{isBannerVisible && (
<div className="sealos-banner-box">
<Translate>如果您是国内用户,请直接访问 👉 </Translate>
<div className="sealos-banner-btn" onClick={goDetail}>
国内官网
</div>
<CloseIcon onClick={closeBanner} />
</div>
)}
</>
);
}