-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
181 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,16 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>React App</title> | ||
</head> | ||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
<html lang="en" data-theme="mine"> | ||
|
||
<head> | ||
<meta charset="UTF-8" /> | ||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
<title>React App</title> | ||
</head> | ||
|
||
<body> | ||
<div id="root"></div> | ||
<script type="module" src="/src/index.tsx"></script> | ||
</body> | ||
|
||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Link } from "@tanstack/react-router"; | ||
|
||
type NavLinkProps = { | ||
children: React.ReactNode, | ||
to: string | ||
} | ||
|
||
export default function NavLink({ children, to }: NavLinkProps) { | ||
return ( | ||
<Link | ||
activeProps={{ | ||
className: "bg-accent" | ||
}} | ||
className="btn btn-ghost text-xl" | ||
to={to}>{children}</Link> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,51 @@ | ||
import Board from "./Board"; | ||
import {useState} from "react"; | ||
import {type SquareValue} from "./types"; | ||
import { useState } from "react"; | ||
import { type SquareValue } from "./types"; | ||
|
||
export default function Game() { | ||
const size = 3; | ||
const initSquares: SquareValue[] = Array(size*size).fill(null); | ||
|
||
const [history, setHistory] = useState([initSquares]); | ||
const [currentMove, setCurrentMove] = useState(0); | ||
const size = 3; | ||
const initSquares: SquareValue[] = Array(size * size).fill(null); | ||
|
||
const currentSquares = history[currentMove]; | ||
const xnext = currentMove % 2 === 0; | ||
const [history, setHistory] = useState([initSquares]); | ||
const [currentMove, setCurrentMove] = useState(0); | ||
|
||
const handlePlay = (squares: SquareValue[]) => { | ||
const nextHistory = [...history.slice(0, currentMove + 1), squares]; | ||
setHistory(nextHistory); | ||
setCurrentMove(nextHistory.length - 1); | ||
}; | ||
const currentSquares = history[currentMove]; | ||
const xnext = currentMove % 2 === 0; | ||
|
||
const jumpTo = (move: number) => { | ||
setCurrentMove(move); | ||
const handlePlay = (squares: SquareValue[]) => { | ||
const nextHistory = [...history.slice(0, currentMove + 1), squares]; | ||
setHistory(nextHistory); | ||
setCurrentMove(nextHistory.length - 1); | ||
}; | ||
|
||
const jumpTo = (move: number) => { | ||
setCurrentMove(move); | ||
} | ||
|
||
const moves = history.map((_, move) => { | ||
let description; | ||
if (move > 0) { | ||
description = 'Go to move #' + move; | ||
} else { | ||
description = 'Go to game start'; | ||
} | ||
return ( | ||
<li> | ||
<button onClick={() => jumpTo(move)}>{description}</button> | ||
</li> | ||
); | ||
}); | ||
|
||
const moves = history.map((_, move) => { | ||
let description; | ||
if (move > 0) { | ||
description = 'Go to move #' + move; | ||
} else { | ||
description = 'Go to game start'; | ||
} | ||
return ( | ||
<li> | ||
<button onClick={() => jumpTo(move)}>{description}</button> | ||
</li> | ||
); | ||
}); | ||
|
||
return ( | ||
<> | ||
<h2>Tic Tac Toe game</h2> | ||
<div className="game"> | ||
<div className="game-board"> | ||
<Board size={size} squares={currentSquares} xnext={xnext} onPlay={handlePlay} /> | ||
</div> | ||
<div className="game-info"> | ||
<ol>{moves}</ol> | ||
<div className="game"> | ||
<div className="game-board"> | ||
<Board size={size} squares={currentSquares} xnext={xnext} onPlay={handlePlay} /> | ||
</div> | ||
<div className="game-info"> | ||
<ol>{moves}</ol> | ||
</div> | ||
</div> | ||
</div> | ||
</> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
export default function SudokuGamePage() { | ||
return ( | ||
<div className="container"> | ||
<h1>Sudoku game</h1> | ||
</div> | ||
) | ||
} | ||
return ( | ||
<div className="container"> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,30 @@ | ||
import { createRootRoute, Link, Outlet } from "@tanstack/react-router"; | ||
import { createRootRoute, Outlet } from "@tanstack/react-router"; | ||
import { TanStackRouterDevtools } from "@tanstack/router-devtools"; | ||
|
||
import NavLink from "@/components/NavLink"; | ||
|
||
export const Route = createRootRoute({ | ||
component: () => ( | ||
<> | ||
<Link to="/">TicTacToe</Link> | ||
<Link to="/sudoku">Sudoku</Link> | ||
<hr /> | ||
<Outlet /> | ||
<TanStackRouterDevtools /> | ||
</> | ||
), | ||
component: Root, | ||
notFoundComponent: NotFound | ||
}); | ||
|
||
function NotFound() { | ||
return ( | ||
<p>Not Found (on root route)</p> | ||
) | ||
} | ||
|
||
function Root() { | ||
return ( | ||
<> | ||
<div className="navbar bg-neutral text-blue-200"> | ||
<NavLink to="/">TicTacToe</NavLink> | ||
<NavLink to="/sudoku">Sudoku</NavLink> | ||
</div > | ||
|
||
<hr /> | ||
<Outlet /> | ||
<TanStackRouterDevtools /> | ||
</> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,40 @@ | ||
/** @type {import('tailwindcss').Config} */ | ||
export default { | ||
content: [ | ||
"./index.html", | ||
"./src/**/*.{ts,tsx}", | ||
], | ||
theme: { | ||
extend: {}, | ||
content: [ | ||
"./index.html", | ||
"./src/**/*.{ts,tsx}", | ||
], | ||
plugins: [require("daisyui")], | ||
daisyui: { | ||
themes: [ | ||
{ | ||
mine: { | ||
"primary": "#155e75", | ||
"secondary": "#0891b2", | ||
"accent": "#0069a6", | ||
"neutral": "#164e63", | ||
"base-100": "#e7e5e4", | ||
"info": "#0d9488", | ||
"success": "#155e75", | ||
"warning": "#fde047", | ||
"error": "#b91c1c", | ||
}, | ||
mine_dark: { | ||
"primary": "#155e75", | ||
"secondary": "#0891b2", | ||
"accent": "#0069a6", | ||
"neutral": "#164e63", | ||
"base-100": "#20161f", | ||
"info": "#0d9488", | ||
"success": "#155e75", | ||
"warning": "#fde047", | ||
"error": "#b91c1c", | ||
}, | ||
|
||
}, | ||
"coffee", | ||
"dark" | ||
], | ||
}, | ||
plugins: [], | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters