Skip to content

Commit e750aea

Browse files
authored
チュートリアルのルーティングを修正 (#98)
* temp * routing for tutorial
1 parent a89bf9f commit e750aea

File tree

7 files changed

+74
-53
lines changed

7 files changed

+74
-53
lines changed

apps/web/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"preview": "vite preview"
1111
},
1212
"dependencies": {
13-
"shared": "workspace:*",
1413
"@emotion/react": "^11.13.3",
1514
"@emotion/styled": "^11.13.0",
1615
"@mui/base": "^5.0.0-beta.58",
@@ -21,7 +20,9 @@
2120
"react-dom": "^19.1.1",
2221
"react-icons": "^5.3.0",
2322
"react-markdown": "^9.0.1",
24-
"react-router-dom": "^6.26.2"
23+
"react-router": "^7.8.2",
24+
"react-router-dom": "^7.8.2",
25+
"shared": "workspace:*"
2526
},
2627
"devDependencies": {
2728
"@eslint/js": "^9.33.0",

apps/web/src/App.tsx

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import { useState } from "react";
2+
import { Route, Routes } from "react-router";
23
import NotFound from "./pages/NotFound/NotFound";
34
import GameInterface from "./pages/Play/GameInterface";
45
import Result from "./pages/Result/Result";
56
import Start from "./pages/Start/Start";
7+
import BasicRules from "./pages/Tutorial/BasicRules";
8+
import LocalRules from "./pages/Tutorial/LocalRules";
69
import Tutorial from "./pages/Tutorial/Tutorial";
710
import "./App.css";
8-
import { Route, BrowserRouter as Router, Routes } from "react-router-dom";
911

1012
export type PlayerInfo = {
1113
rank: number | null;
@@ -31,23 +33,25 @@ function App() {
3133
fontFamily: "YuMincho, Hiragino Mincho ProN, serif",
3234
}}
3335
>
34-
<Router>
35-
<Routes>
36-
<Route path="/" element={<Start setPlayerInfo={setPlayerInfo} />} />
37-
<Route path="/tutorial" element={<Tutorial />} />
38-
<Route
39-
path="/play"
40-
element={
41-
<GameInterface
42-
playerInfo={playerInfo}
43-
setPlayerInfo={setPlayerInfo}
44-
/>
45-
}
46-
/>
47-
<Route path="/result" element={<Result playerInfo={playerInfo} />} />
48-
<Route path="*" element={<NotFound />} />
49-
</Routes>
50-
</Router>
36+
<Routes>
37+
<Route index element={<Start setPlayerInfo={setPlayerInfo} />} />
38+
<Route path="tutorial" element={<Tutorial />}>
39+
<Route index element={<BasicRules />} />
40+
<Route path="basic" element={<BasicRules />} />
41+
<Route path="local" element={<LocalRules />} />
42+
</Route>
43+
<Route
44+
path="play"
45+
element={
46+
<GameInterface
47+
playerInfo={playerInfo}
48+
setPlayerInfo={setPlayerInfo}
49+
/>
50+
}
51+
/>
52+
<Route path="result" element={<Result playerInfo={playerInfo} />} />
53+
<Route path="*" element={<NotFound />} />
54+
</Routes>
5155
</div>
5256
);
5357
}

apps/web/src/index.css

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ a {
2222
color: #646cff;
2323
text-decoration: inherit;
2424
}
25+
2526
a:hover {
2627
color: #535bf2;
2728
}
@@ -54,9 +55,11 @@ button {
5455
cursor: pointer;
5556
transition: border-color 0.25s;
5657
}
58+
5759
button:hover {
5860
border-color: #646cff;
5961
}
62+
6063
button:focus,
6164
button:focus-visible {
6265
outline: 4px auto -webkit-focus-ring-color;
@@ -68,10 +71,8 @@ button:focus-visible {
6871
color: #213547;
6972
background-color: #ffffff;
7073
}
74+
7175
a:hover {
7276
color: #747bff;
7377
}
74-
button {
75-
background-color: #f9f9f9;
76-
}
7778
}

apps/web/src/main.tsx

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
import { StrictMode } from "react";
22
import { createRoot } from "react-dom/client";
3+
import { BrowserRouter } from "react-router";
34
import App from "./App.tsx";
45
import "./index.css";
56

6-
createRoot(document.getElementById("root"))?.render(
7-
<StrictMode>
8-
<App />
9-
</StrictMode>,
10-
);
7+
const rootElement = document.getElementById("root");
8+
9+
if (rootElement) {
10+
const root = createRoot(rootElement);
11+
12+
root.render(
13+
<StrictMode>
14+
<BrowserRouter>
15+
<App />
16+
</BrowserRouter>
17+
</StrictMode>,
18+
);
19+
}

apps/web/src/pages/Start/Start.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,15 +68,15 @@ export default function Start(props: StartProps) {
6868

6969
<button
7070
onClick={handleUserNameSubmit}
71-
className="w-115 h-17.5 bg-[#fd903c] text-white text-xl rounded-md my-3.5"
71+
className="w-115 h-17.5 bg-black text-white text-xl rounded-md my-3.5"
7272
type="button"
7373
>
7474
プレイ
7575
</button>
7676
<div className="flex gap-5">
7777
<button
7878
onClick={() => navigate("/tutorial")}
79-
className="w-55 bg-[#85a4ba] text-white rounded-md"
79+
className="w-55 bg-black text-white rounded-md"
8080
type="button"
8181
>
8282
遊び方
@@ -90,7 +90,7 @@ export default function Start(props: StartProps) {
9090
});
9191
navigate("/result");
9292
}}
93-
className="w-55 bg-[#85a4ba] text-white rounded-md"
93+
className="w-55 bg-black text-white rounded-md"
9494
type="button"
9595
>
9696
ランキング

apps/web/src/pages/Tutorial/Tutorial.tsx

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
import HighlightOffIcon from "@mui/icons-material/HighlightOff";
2-
import { Button } from "@mui/material";
32
import IconButton from "@mui/material/IconButton";
4-
import { useState } from "react";
5-
import { useNavigate } from "react-router-dom";
6-
import BasicRules from "./BasicRules";
7-
import LocalRules from "./LocalRules";
3+
import { Link, Outlet, useNavigate, useParams } from "react-router";
84

9-
type ContentsType = "basic" | "local";
5+
type ContentIdType = "basic" | "local";
106

117
export default function Tutorial() {
12-
const [currentContent, setCurrentContent] = useState<ContentsType>("basic");
138
const navigate = useNavigate();
14-
const contents: ContentsType[] = ["basic", "local"];
9+
const { contentId } = useParams<{ contentId: ContentIdType }>();
10+
const contents: ContentIdType[] = ["basic", "local"];
1511

1612
return (
1713
<div className="flex flex-col items-center bg-white rounded-[1rem] absolute h-[80vh] w-[80vw] left-[10%] top-[10%] pt-4 pl-4">
@@ -31,22 +27,25 @@ export default function Tutorial() {
3127
<div className="grid size-full gap-[3%] h-[90%] overflow-auto pt-4">
3228
<div className="col-start-1 col-end-2 flex w-50 flex-col border-r border-gray-300 px-5 h-full">
3329
{contents.map((content) => (
34-
<Button
30+
<Link
3531
key={content}
36-
sx={{
37-
marginBottom: "10%",
38-
}}
39-
variant={currentContent === content ? "contained" : "outlined"}
40-
onClick={() => setCurrentContent(content)}
32+
to={`/tutorial/${content}`}
33+
className={`
34+
mb-[10%] px-4 py-2 rounded border transition-colors duration-200
35+
${
36+
contentId === content
37+
? "bg-blue-500 text-white border-blue-500"
38+
: "bg-transparent text-blue-500 border-blue-500 hover:bg-blue-50"
39+
}
40+
`}
4141
>
4242
{content === "basic" ? "基本ルール" : "ローカルルール"}
43-
</Button>
43+
</Link>
4444
))}
4545
</div>
4646

4747
<div className="col-start-2 col-end-3 text-left">
48-
{currentContent === "basic" && <BasicRules />}
49-
{currentContent === "local" && <LocalRules />}
48+
<Outlet />
5049
</div>
5150
</div>
5251
</div>

bun.lock

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

0 commit comments

Comments
 (0)