Skip to content

Commit 6d824b6

Browse files
committed
add react router
1 parent 9ca3e16 commit 6d824b6

File tree

7 files changed

+189
-87
lines changed

7 files changed

+189
-87
lines changed

internal/dev_server/ui/dist/index.html

Lines changed: 44 additions & 33 deletions
Large diffs are not rendered by default.

internal/dev_server/ui/package-lock.json

Lines changed: 111 additions & 29 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/dev_server/ui/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
"lodash": "4.17.21",
2323
"react": "18.3.1",
2424
"react-dom": "18.3.1",
25+
"react-router": "7.7.1",
2526
"react-window": "1.8.10"
2627
},
2728
"devDependencies": {

internal/dev_server/ui/src/App.tsx

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import './App.css';
2-
import { useState } from 'react';
2+
import { Routes, Route, Navigate } from 'react-router';
33
import { Box } from '@launchpad-ui/core';
44
import FlagsButton from './FlagsButton.tsx';
55
import EventsButton from './EventsButton.tsx';
66
import FlagsPage from './FlagsPage.tsx';
77
import EventsPage from './EventsPage.tsx';
88

99
function App() {
10-
const [mode, setMode] = useState<'flags' | 'events'>('flags');
11-
1210
return (
1311
<div
1412
style={{
@@ -28,12 +26,15 @@ function App() {
2826
padding="2rem"
2927
>
3028
<Box display="flex" gap="10px" justifyContent="flex-start" width="100%">
31-
<FlagsButton onPress={() => { setMode('flags'); }} />
32-
<EventsButton onPress={() => { setMode('events'); }} />
29+
<FlagsButton />
30+
<EventsButton />
3331
</Box>
3432
<Box padding="1rem" width="100%">
35-
{mode === 'flags' && <FlagsPage />}
36-
{mode === 'events' && <EventsPage />}
33+
<Routes>
34+
<Route path="/" element={<Navigate to="/ui" replace />} />
35+
<Route path="/ui" element={<FlagsPage />} />
36+
<Route path="/events" element={<EventsPage />} />
37+
</Routes>
3738
</Box>
3839
</Box>
3940
</div>

internal/dev_server/ui/src/EventsButton.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import {
55
} from '@launchpad-ui/components';
66
import { Icon } from '@launchpad-ui/icons';
77
import { Inline } from '@launchpad-ui/core';
8+
import { useNavigate, useLocation } from 'react-router';
89

9-
type Props = {
10-
onPress: () => void;
11-
};
10+
const EventsButton = () => {
11+
const navigate = useNavigate();
12+
const location = useLocation();
13+
const isActive = location.pathname === '/events';
1214

13-
const EventsButton = ({
14-
onPress,
15-
}: Props) => {
1615
return (
1716
<TooltipTrigger>
18-
<Button onPress={onPress}>
17+
<Button
18+
onPress={() => navigate('/events')}
19+
variant={isActive ? 'primary' : 'default'}
20+
>
1921
<div>
2022
<Inline gap="1">
2123
<Icon name="play" size="small" />

internal/dev_server/ui/src/FlagsButton.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,19 @@ import {
55
} from '@launchpad-ui/components';
66
import { Icon } from '@launchpad-ui/icons';
77
import { Inline } from '@launchpad-ui/core';
8+
import { useNavigate, useLocation } from 'react-router';
89

9-
type Props = {
10-
onPress: () => void;
11-
};
10+
const FlagsButton = () => {
11+
const navigate = useNavigate();
12+
const location = useLocation();
13+
const isActive = location.pathname === '/ui';
1214

13-
const FlagsButton = ({
14-
onPress,
15-
}: Props) => {
1615
return (
1716
<TooltipTrigger>
18-
<Button onPress={onPress}>
17+
<Button
18+
onPress={() => navigate('/ui')}
19+
variant={isActive ? 'primary' : 'default'}
20+
>
1921
<div>
2022
<Inline gap="1">
2123
<Icon name="flag" size="small" />

internal/dev_server/ui/src/main.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React, { useEffect } from 'react';
22
import ReactDOM from 'react-dom/client';
3+
import { BrowserRouter } from 'react-router';
34
import App from './App.tsx';
45
import { IconProvider } from './IconProvider.tsx';
56
import { ToastContainer } from '@launchpad-ui/components';
@@ -27,10 +28,12 @@ const Root = () => {
2728

2829
return (
2930
<React.StrictMode>
30-
<IconProvider>
31-
<App />
32-
<ToastContainer />
33-
</IconProvider>
31+
<BrowserRouter>
32+
<IconProvider>
33+
<App />
34+
<ToastContainer />
35+
</IconProvider>
36+
</BrowserRouter>
3437
</React.StrictMode>
3538
);
3639
};

0 commit comments

Comments
 (0)