-
Notifications
You must be signed in to change notification settings - Fork 2k
/
index.tsx
176 lines (165 loc) · 5.13 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
import Link from '@docusaurus/Link';
import Translate from '@docusaurus/Translate';
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
import useIsBrowser from '@docusaurus/useIsBrowser';
import useWindow from '@site/src/hooks/useWindow';
import NavBanner from '@site/src/components/NavBanner';
import GithubIcon from '@site/static/icons/github.svg';
import MeunIcon from '@site/static/icons/meun.svg';
import LogoIcon from '@site/static/icons/sealos.svg';
import React, { useEffect, useState } from 'react';
import './index.scss';
const navbar = [
{
key: 'docs',
label: <Translate>Documentation</Translate>,
to: '/docs/Intro'
},
{
key: 'community',
label: <Translate>Community</Translate>,
to: 'https://forum.laf.run/'
},
{
key: 'hosting',
label: <Translate>Hosting</Translate>,
to: '/self-hosting'
},
{
key: 'blog',
label: <Translate>Blog</Translate>,
to: '/blog'
},
{
key: 'contact',
label: <Translate>Contact</Translate>,
to: 'https://fael3z0zfze.feishu.cn/share/base/form/shrcnesSfEK65JZaAf2W6Fwz6Ad'
}
];
const i18nObj = {
startNow: <Translate>Start Now</Translate>,
cloudOS: <Translate>Cloud Operating System</Translate>
};
const HomeHeader = ({ isPc }: { isPc: boolean }) => {
const [stars, setStars] = useState(10000);
const isBrowser = useIsBrowser();
const { cloudUrl, bd_vid } = useWindow();
const [isBannerVisible, setIsBannerVisible] = useState(false);
const {
i18n: { currentLocale, defaultLocale }
} = useDocusaurusContext();
const i18nMap: { [key: string]: { label: string; link: string } } =
defaultLocale === 'en'
? {
en: { label: '中', link: '/zh-Hans/' },
['zh-Hans']: { label: 'En', link: '/' }
}
: {
en: { label: '中', link: '/' },
['zh-Hans']: { label: 'En', link: '/en/' }
};
useEffect(() => {
const getStars = async () => {
try {
const { stargazers_count } = await (
await fetch('https://api.github.com/repos/labring/sealos')
).json();
setStars(isNaN(stargazers_count) ? 11 * 1000 : stargazers_count);
} catch (error) {}
};
getStars();
}, []);
const openSideBar = () => {
const NavbarButton: HTMLBaseElement = document.querySelector('.navbar__toggle');
const event = new MouseEvent('click', {
view: window,
bubbles: true,
cancelable: true
});
NavbarButton.dispatchEvent(event);
};
if (!isPc) {
return (
<div className="sealo_price_header">
<NavBanner isBannerVisible={isBannerVisible} setIsBannerVisible={setIsBannerVisible} />
<nav
style={
isBannerVisible
? {
marginTop: '48px'
}
: {}
}
>
<div className="left">
<MeunIcon width={'24px'} height={'24px'} onClick={() => openSideBar()} />
<LogoIcon width={'42px'} height={'42px'} />
<span className="sealos-title">Sealos</span>
</div>
<div className="right">
<Link className="git-icon" to="https://github.com/labring/sealos">
<GithubIcon width={'20px'} height={'20px'} color="#fff" />
<span className="git-stars">{Math.floor(stars / 1000)}k</span>
</Link>
</div>
</nav>
</div>
);
}
return (
<div className="sealo_price_header">
<NavBanner isBannerVisible={isBannerVisible} setIsBannerVisible={setIsBannerVisible} />
<nav
style={
isBannerVisible
? {
marginTop: '48px'
}
: {}
}
>
<div className="left">
<div
className="sealos_home_header_title"
onClick={() =>
window.location.replace(
`${location.origin}${currentLocale === defaultLocale ? '/' : `/${currentLocale}/`}`
)
}
>
<LogoIcon width={'42px'} height={'42px'} />
<span className="sealos-title">Sealos</span>
</div>
<div className="links">
{navbar.map((item) => (
<Link key={item.key} to={item.to}>
{item.label}
</Link>
))}
</div>
</div>
<div className="right">
<Link className="git-icon" to="https://github.com/labring/sealos">
<GithubIcon width={'20px'} height={'20px'} color="#fff" />
<span className="git-stars">{Math.floor(stars / 1000)}k</span>
</Link>
{isBrowser && (
<div
className="i18nIcon"
onClick={() =>
window.location.replace(`${location.origin}${i18nMap[currentLocale].link}`)
}
>
{i18nMap[currentLocale].label}
</div>
)}
<a className="start-now-button" href={`${cloudUrl}?bd_vid=${bd_vid}`} target="_blank">
{i18nObj.startNow}
<div className="start-now-button-wrap"></div>
</a>
</div>
</nav>
</div>
);
};
export default React.memo(HomeHeader);