Skip to content

Commit ccec72e

Browse files
committed
chore(site): support multiple versions
1 parent 19e2c82 commit ccec72e

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

packages/site/src/app/routes/layout/Header.tsx

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ import { DCustomIcon, GithubOutlined } from '@react-devui/icons';
1010
import { DDropdown, DMenu, DSeparator } from '@react-devui/ui';
1111
import { getClassName } from '@react-devui/utils';
1212

13+
import { environment } from '../../../environments/environment';
14+
import { AppVersions } from './Versions';
15+
1316
export interface AppHeaderProps {
1417
menuOpen: boolean;
1518
onMenuOpenChange: (open: boolean) => void;
@@ -46,6 +49,7 @@ export function AppHeader(props: AppHeaderProps): JSX.Element | null {
4649
<div></div>
4750
</div>
4851
</button>
52+
{environment.production && <AppVersions />}
4953
<DMenu
5054
className="d-none d-md-inline-block app-layout-header__menu"
5155
dList={[
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
import axios from 'axios';
2+
import { useState } from 'react';
3+
import { useLocation } from 'react-router-dom';
4+
5+
import { useMount } from '@react-devui/hooks';
6+
import { DownOutlined } from '@react-devui/icons';
7+
import { DButton, DDropdown } from '@react-devui/ui';
8+
9+
export function AppVersions(): JSX.Element | null {
10+
const location = useLocation();
11+
12+
const version = (() => {
13+
const v = window.location.host.match(/^v[0-9]+/);
14+
return v ? v[0] : 'main';
15+
})();
16+
const [versions, setVersions] = useState<string[]>(() => {
17+
if (version === 'main') {
18+
return ['main'];
19+
} else {
20+
return ['main', version];
21+
}
22+
});
23+
useMount(() => {
24+
axios.get('/api/versions').then((response) => {
25+
setVersions(['main', ...(response.data as number[]).map((v) => `v${v}`)]);
26+
});
27+
});
28+
29+
return (
30+
<DDropdown
31+
dList={versions.map((v) => ({ id: v, label: v, type: 'item' }))}
32+
onItemClick={(id) => {
33+
window.location = ((id === 'main' ? 'https://react-devui.com' : `https://${id}.react-devui.com`) + location.pathname) as any;
34+
}}
35+
>
36+
<DButton dType="text">
37+
<div className="d-flex align-items-center">
38+
{version}
39+
<DownOutlined style={{ position: 'relative', top: 2, marginLeft: 2 }} dSize={12} />
40+
</div>
41+
</DButton>
42+
</DDropdown>
43+
);
44+
}

0 commit comments

Comments
 (0)