Skip to content

Commit

Permalink
Merge pull request #5 from ma-ray/add-routing
Browse files Browse the repository at this point in the history
Add routing
  • Loading branch information
ma-ray authored Dec 9, 2023
2 parents fc7ed98 + 90b5dc4 commit 81f68f8
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 50 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
"moment": "^2.29.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.20.1",
"tailwind-merge": "^2.0.0",
"tailwindcss-animate": "^1.0.7"
},
Expand Down
21 changes: 0 additions & 21 deletions src/App.css

This file was deleted.

12 changes: 0 additions & 12 deletions src/App.tsx

This file was deleted.

12 changes: 0 additions & 12 deletions src/Home.tsx

This file was deleted.

9 changes: 6 additions & 3 deletions src/components/Calendar.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Calendar as CalendarBase, CalendarDate } from 'calendar-base'
import moment from 'moment'
import { Link } from 'react-router-dom'

type DayProps = {
date: CalendarDate
Expand Down Expand Up @@ -27,9 +28,11 @@ const Day: React.FC<DayProps> = ({ date }) => {
className={`flex items-center justify-center border border-black h-24 w-24 col ${bg}
}`}
>
<h4 className="scroll-m-20 text-2xl font-bold tracking-tight">
{date.day}
</h4>
<Link to={`/diary/${date.year}/${date.month}/${date.day}`}>
<h4 className="scroll-m-20 text-2xl font-bold tracking-tight">
{date.day}
</h4>
</Link>
</div>
)
}
Expand Down
17 changes: 15 additions & 2 deletions src/main.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { createBrowserRouter, RouterProvider } from 'react-router-dom'
import HomePage from './pages/HomePage.tsx'
import DiaryPage from './pages/DiaryPage.tsx'

const router = createBrowserRouter([
{
path: '/',
element: <HomePage />,
},
{
path: '/diary/:year/:month/:day',
element: <DiaryPage />,
},
])

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<RouterProvider router={router} />
</React.StrictMode>
)

Expand Down
14 changes: 14 additions & 0 deletions src/pages/DiaryPage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { useParams } from 'react-router-dom'

const DiaryPage = () => {
const { year, month, day } = useParams()

return (
<div>
<p>this is the diary page</p>
<p>{`the day is ${year} ${month} ${day}`}</p>
</div>
)
}

export default DiaryPage
12 changes: 12 additions & 0 deletions src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import Calendar from '../components/Calendar'

const HomePage = () => {
return (
<div className="flex flex-col justify-center items-center">
<p>home page</p>
<Calendar month={11} year={2023} />
</div>
)
}

export default HomePage
20 changes: 20 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,11 @@
"@nodelib/fs.scandir" "2.1.5"
fastq "^1.6.0"

"@remix-run/[email protected]":
version "1.13.1"
resolved "https://registry.yarnpkg.com/@remix-run/router/-/router-1.13.1.tgz#07e2a8006f23a3bc898b3f317e0a58cc8076b86e"
integrity sha512-so+DHzZKsoOcoXrILB4rqDkMDy7NLMErRdOxvzvOKb507YINKUP4Di+shbTZDhSE/pBZ+vr7XGIpcOO0VLSA+Q==

"@sindresorhus/is@^4.0.0":
version "4.6.0"
resolved "https://registry.yarnpkg.com/@sindresorhus/is/-/is-4.6.0.tgz#3c7c9c46e678feefe7a2e5bb609d3dbd665ffb3f"
Expand Down Expand Up @@ -2649,6 +2654,21 @@ react-refresh@^0.14.0:
resolved "https://registry.yarnpkg.com/react-refresh/-/react-refresh-0.14.0.tgz#4e02825378a5f227079554d4284889354e5f553e"
integrity sha512-wViHqhAd8OHeLS/IRMJjTSDHF3U9eWi62F/MledQGPdJGDhodXJ9PBLNGr6WWL7qlH12Mt3TyTpbS+hGXMjCzQ==

react-router-dom@^6.20.1:
version "6.20.1"
resolved "https://registry.yarnpkg.com/react-router-dom/-/react-router-dom-6.20.1.tgz#e34f8075b9304221420de3609e072bb349824984"
integrity sha512-npzfPWcxfQN35psS7rJgi/EW0Gx6EsNjfdJSAk73U/HqMEJZ2k/8puxfwHFgDQhBGmS3+sjnGbMdMSV45axPQw==
dependencies:
"@remix-run/router" "1.13.1"
react-router "6.20.1"

[email protected]:
version "6.20.1"
resolved "https://registry.yarnpkg.com/react-router/-/react-router-6.20.1.tgz#e8cc326031d235aaeec405bb234af77cf0fe75ef"
integrity sha512-ccvLrB4QeT5DlaxSFFYi/KR8UMQ4fcD8zBcR71Zp1kaYTC5oJKYAp1cbavzGrogwxca+ubjkd7XjFZKBW8CxPA==
dependencies:
"@remix-run/router" "1.13.1"

react@^18.2.0:
version "18.2.0"
resolved "https://registry.yarnpkg.com/react/-/react-18.2.0.tgz#555bd98592883255fa00de14f1151a917b5d77d5"
Expand Down

0 comments on commit 81f68f8

Please sign in to comment.