|
1 | | -import { useState } from 'react' |
2 | | -import { Theme } from '@carbon/react' |
| 1 | +import { Content, Theme } from '@carbon/react' |
| 2 | +import { |
| 3 | + Navigate, |
| 4 | + Outlet, |
| 5 | + RouterProvider, |
| 6 | + createHashRouter, |
| 7 | +} from 'react-router-dom' |
3 | 8 | import AppHeader from './components/AppHeader' |
| 9 | +import AppContent from './components/AppContent' |
| 10 | +import Home from './content/Home' |
4 | 11 | import Projects from './content/Projects' |
5 | 12 | import Contact from './content/Contact' |
| 13 | +import { useState } from 'react' |
6 | 14 |
|
7 | | -function App() { |
8 | | - const [activeSection, setActiveSection] = useState('about') |
| 15 | +const AppLayout = () => { |
| 16 | + const defaultDarkMode = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches |
| 17 | + const [darkMode, setDarkMode] = useState(defaultDarkMode); |
9 | 18 |
|
10 | | - const renderContent = () => { |
11 | | - switch (activeSection) { |
12 | | - case 'about': |
13 | | - return <h1>About Me</h1> |
14 | | - case 'projects': |
15 | | - return <Projects /> |
16 | | - case 'contact': |
17 | | - return <Contact /> |
18 | | - default: |
19 | | - return <h1>About Me</h1> |
20 | | - } |
21 | | - } |
| 19 | + return ( |
| 20 | + <Theme theme={darkMode ? 'g100' : 'g10'}> |
| 21 | + <AppHeader darkMode={darkMode} setDarkMode={setDarkMode} /> |
| 22 | + <AppContent><Outlet /></AppContent> |
| 23 | + </Theme> |
| 24 | + ); |
| 25 | +}; |
22 | 26 |
|
23 | | - return ( |
24 | | - <> |
25 | | - <Theme theme="g100"> |
26 | | - <AppHeader |
27 | | - activeSection={activeSection} |
28 | | - onSectionChange={setActiveSection} |
29 | | - /> |
30 | | - <div className="app-content"> |
31 | | - {renderContent()} |
32 | | - </div> |
33 | | - </Theme> |
34 | | - </> |
35 | | - ) |
| 27 | +const router = createHashRouter([ |
| 28 | + { |
| 29 | + path: '/', |
| 30 | + element: <AppLayout />, |
| 31 | + children: [ |
| 32 | + { index: true, element: <Home /> }, |
| 33 | + { path: 'projects', element: <Projects /> }, |
| 34 | + { path: 'contact', element: <Contact /> }, |
| 35 | + { path: '*', element: <Navigate to="/" replace /> }, |
| 36 | + ], |
| 37 | + }, |
| 38 | +]) |
| 39 | + |
| 40 | +function App() { |
| 41 | + return <RouterProvider router={router} /> |
36 | 42 | } |
37 | 43 |
|
38 | 44 | export default App |
0 commit comments