Skip to content

Commit 4fe9742

Browse files
committed
feat: integrate with react router
1 parent 20e3707 commit 4fe9742

File tree

10 files changed

+107
-18
lines changed

10 files changed

+107
-18
lines changed

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,8 @@ export default tseslint.config([
1919
ecmaVersion: 2020,
2020
globals: globals.browser,
2121
},
22+
rules: {
23+
'react-refresh/only-export-components': 'off'
24+
}
2225
},
2326
])

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"@tailwindcss/vite": "^4.1.13",
2525
"react": "^19.1.1",
2626
"react-dom": "^19.1.1",
27+
"react-router": "^7.9.1",
2728
"tailwindcss": "^4.1.13"
2829
},
2930
"devDependencies": {

pnpm-lock.yaml

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

src/App.tsx

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
1+
import { BrowserRouter, Routes, Route } from 'react-router';
12
import { Layout } from "./components/layout";
2-
import { DiffEditor } from "./components/DiffEditor";
3+
import { TextDiff } from "./pages";
34
import { useDynamicFavicon } from "./hooks/useDynamicFavicon";
45

56
function App() {
67
useDynamicFavicon();
78

89
return (
9-
<Layout>
10-
<DiffEditor />
11-
</Layout>
10+
<BrowserRouter>
11+
<Layout>
12+
<Routes>
13+
<Route path="/" element={<TextDiff />} />
14+
</Routes>
15+
</Layout>
16+
</BrowserRouter>
1217
);
1318
}
1419

src/components/DiffEditor.tsx renamed to src/components/diff/TextDiff.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
import { useState, useRef } from 'react';
2-
import { DiffEditor as MonacoDiffEditor, type MonacoDiffEditor as MonacoDiffEditorType } from '@monaco-editor/react';
3-
import { useTheme } from '../hooks/useTheme';
2+
import { DiffEditor, type MonacoDiffEditor } from '@monaco-editor/react';
3+
import { useTheme } from '../../hooks/useTheme';
44

5-
interface DiffEditorProps {
5+
interface TextDiffProps {
66
className?: string;
77
}
88

9-
export const DiffEditor = ({ className = '' }: DiffEditorProps) => {
9+
export const TextDiff = ({ className = '' }: TextDiffProps) => {
1010
const [originalText, setOriginalText] = useState('function hello() {\n console.log("Hello World");\n}');
1111
const [modifiedText, setModifiedText] = useState('function hello() {\n console.log("Hello, World!");\n return "Hello";\n}');
12-
const editorRef = useRef<MonacoDiffEditorType | null>(null);
12+
const editorRef = useRef<MonacoDiffEditor | null>(null);
1313
const { theme } = useTheme();
1414

15-
const handleEditorDidMount = (editor: MonacoDiffEditorType) => {
15+
const handleEditorDidMount = (editor: MonacoDiffEditor) => {
1616
editorRef.current = editor;
1717
};
1818

@@ -64,7 +64,7 @@ export const DiffEditor = ({ className = '' }: DiffEditorProps) => {
6464
</div>
6565

6666
{/* Diff Editor */}
67-
<MonacoDiffEditor
67+
<DiffEditor
6868
wrapperProps={{
6969
className: 'flex-1',
7070
}}

src/components/layout/Header.tsx

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1-
import { Logo } from '../ui/Logo';
1+
import { Link } from "react-router";
2+
import { Logo, NavigationLink } from "../ui";
23

34
interface HeaderProps {
45
className?: string;
56
}
67

7-
export const Header = ({ className = '' }: HeaderProps) => {
8+
export const Header = ({ className = "" }: HeaderProps) => {
89
return (
9-
<header className={`bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700 shadow-sm ${className}`}>
10+
<header
11+
className={`bg-white dark:bg-gray-900 border-b border-gray-200 dark:border-gray-700 shadow-sm ${className}`}
12+
>
1013
<div className="mx-auto px-4 sm:px-6 lg:px-8">
1114
<div className="flex justify-between items-center h-16">
12-
{/* Logo */}
13-
<div className="flex items-center">
14-
<div className="flex-shrink-0 flex items-center space-x-3">
15+
<div className="flex items-center space-x-6">
16+
{/* Logo */}
17+
<Link to="/" className="flex-shrink-0 flex items-center space-x-3">
1518
<Logo className="w-10 h-10" />
1619
<h1 className="text-xl font-bold text-gray-900 dark:text-white">
1720
Diff Viewer
1821
</h1>
19-
</div>
22+
</Link>
23+
24+
{/* Navigation */}
25+
<nav className="flex space-x-6">
26+
<NavigationLink to="/">Text Diff</NavigationLink>
27+
<NavigationLink to="/image">Image Diff</NavigationLink>
28+
</nav>
2029
</div>
2130

2231
{/* Actions */}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Link, useLocation } from 'react-router';
2+
3+
interface NavigationLinkProps {
4+
to: string;
5+
children: React.ReactNode;
6+
className?: string;
7+
}
8+
9+
export const NavigationLink = ({ to, children, className = '' }: NavigationLinkProps) => {
10+
const location = useLocation();
11+
const isActive = (path: string) => location.pathname === path;
12+
13+
14+
return (
15+
<Link
16+
to={to}
17+
className={`px-3 py-2 rounded-md text-sm font-medium transition-colors ${
18+
isActive(to)
19+
? 'text-blue-600 dark:text-blue-400 bg-blue-50 dark:bg-blue-900/20'
20+
: 'text-gray-500 dark:text-gray-300 hover:text-gray-900 dark:hover:text-white'
21+
} ${className}`}
22+
>
23+
{children}
24+
</Link>
25+
);
26+
};

src/components/ui/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export * from './Logo';
2+
export * from './NavigationLink';
3+
export * from './Divider';

src/pages/TextDiff.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { TextDiff as TextDiffEditor } from "../components/diff/TextDiff";
2+
3+
export const TextDiff = () => {
4+
return (
5+
<div className="flex-1 flex flex-col">
6+
<TextDiffEditor />
7+
</div>
8+
);
9+
};

src/pages/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export { TextDiff } from './TextDiff';

0 commit comments

Comments
 (0)