Skip to content

Commit

Permalink
Merge ; commit 'eb15d86a4bd9caf53ead16fa441c9d199da9174e'
Browse files Browse the repository at this point in the history
  • Loading branch information
rxx committed Apr 1, 2024
2 parents f3fc4d8 + eb15d86 commit 86be71e
Show file tree
Hide file tree
Showing 21 changed files with 1,230 additions and 141 deletions.
12 changes: 3 additions & 9 deletions bin/current.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,20 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" &>/dev/null && pwd)"
# Set the ROOT variable one level up from the script's location
ROOT="$(dirname "$SCRIPT_DIR")"

if [[ -L "$ROOT/current" ]]; then
rm -f "$ROOT/current"
fi

rm -f "$ROOT/current"
ln -s "$1" "$ROOT/current"

if [[ ! -e "$ROOT/current/.replit" ]]; then
echo "$1/.replit must exist"
exit 1
fi

if [[ -L "$ROOT/.replit" ]]; then
rm -f "$ROOT/.replit"
fi
rm -f "$ROOT/.replit"

ln -s "$ROOT/current/.replit" "$ROOT/.replit"

if [[ -L "$ROOT/replit.nix" ]]; then
rm -f "$ROOT/replit.nix"
fi
rm -f "$ROOT/replit.nix"

if [[ -e "$ROOT/current/replit.nix" ]]; then
ln -s "$ROOT/current/replit.nix" "$ROOT/replit.nix"
Expand Down
10 changes: 0 additions & 10 deletions src/node/react/.yarnrc.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,4 @@
# Yarn's manifest file. You can configure yarn here.
# See https://yarnpkg.com/configuration/yarnrc.

# For `node_modules` (see `nodeLinker` below), this is almost always the preferred option.
compressionLevel: 0

enableGlobalCache: true

# Lets yarn use hardlinks inside `node_modules` to dedupe packages.
# For a more pnpm-like experience, consider `hardlinks-global` where hardlinks point to a global store.
nmMode: hardlinks-local

# How to install Node packages.
nodeLinker: node-modules
25 changes: 14 additions & 11 deletions src/node/react/index.html
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>
17 changes: 12 additions & 5 deletions src/node/react/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,26 @@
"author": "",
"license": "ISC",
"devDependencies": {
"@tanstack/router-devtools": "^1.26.1",
"@tanstack/router-vite-plugin": "^1.25.0",
"@types/node": "^20.12.2",
"@types/react": "^18.2.37",
"@types/react-dom": "^18.2.15",
"@vitejs/plugin-react": "^4.2.0",
"autoprefixer": "^10.4.19",
"daisyui": "^4.9.0",
"postcss": "^8.4.38",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"tailwindcss": "^3.4.3",
"typescript": "^5.2.2",
"vite": "^5.2.6",
"autoprefixer": "^10.4.19",
"postcss": "^8.4.38",
"tailwindcss": "^3.4.3"
"vite": "^5.2.6"
},
"engines": {
"node": "=20.x"
},
"packageManager": "[email protected]"
"packageManager": "[email protected]",
"dependencies": {
"@tanstack/react-router": "^1.26.1"
}
}
10 changes: 0 additions & 10 deletions src/node/react/src/App.tsx

This file was deleted.

18 changes: 0 additions & 18 deletions src/node/react/src/components/Card/index.tsx

This file was deleted.

9 changes: 0 additions & 9 deletions src/node/react/src/components/Card/styles.css

This file was deleted.

17 changes: 17 additions & 0 deletions src/node/react/src/components/NavLink.tsx
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>
)
}
62 changes: 31 additions & 31 deletions src/node/react/src/components/TicTacToe/Game.tsx
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
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 (
<div className="flex">
<div>
Expand All @@ -46,4 +46,4 @@ export default function Game() {
</div>
</div>
);
}
}
File renamed without changes.
23 changes: 19 additions & 4 deletions src/node/react/src/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,24 @@
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from '@/App'
import "@/index.css";

ReactDOM.createRoot(document.getElementById('root')).render(
import { RouterProvider, createRouter } from '@tanstack/react-router';

import { routeTree } from '@/routeTree.gen';

const router = createRouter({
routeTree,
defaultPreload: 'intent',
})

declare module '@tanstack/react-router' {
interface Register {
router: typeof router
}
};

ReactDOM.createRoot(document.getElementById('root')!).render(
<React.StrictMode>
<App />
<RouterProvider router={router} />
</React.StrictMode>
)
)
2 changes: 0 additions & 2 deletions src/node/react/src/pages/HomePage.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Card from "@/components/Card";
import Game from "@/components/TicTacToe/Game";

const HomePage = () => {
return <>
<Card title="Home" desc="Sandbox page"/>
<Game />
</>
}
Expand Down
Empty file.
6 changes: 6 additions & 0 deletions src/node/react/src/pages/SudokuGamePage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default function SudokuGamePage() {
return (
<div className="container">
</div>
)
}
56 changes: 56 additions & 0 deletions src/node/react/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* prettier-ignore-start */

/* eslint-disable */

// @ts-nocheck

// noinspection JSUnusedGlobalSymbols

// This file is auto-generated by TanStack Router

import { createFileRoute } from '@tanstack/react-router'

// Import Routes

import { Route as rootRoute } from './routes/__root'

// Create Virtual Routes

const SudokuLazyImport = createFileRoute('/sudoku')()
const IndexLazyImport = createFileRoute('/')()

// Create/Update Routes

const SudokuLazyRoute = SudokuLazyImport.update({
path: '/sudoku',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/sudoku.lazy').then((d) => d.Route))

const IndexLazyRoute = IndexLazyImport.update({
path: '/',
getParentRoute: () => rootRoute,
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))

// Populate the FileRoutesByPath interface

declare module '@tanstack/react-router' {
interface FileRoutesByPath {
'/': {
preLoaderRoute: typeof IndexLazyImport
parentRoute: typeof rootRoute
}
'/sudoku': {
preLoaderRoute: typeof SudokuLazyImport
parentRoute: typeof rootRoute
}
}
}

// Create and export the route tree

export const routeTree = rootRoute.addChildren([
IndexLazyRoute,
SudokuLazyRoute,
])

/* prettier-ignore-end */
30 changes: 30 additions & 0 deletions src/node/react/src/routes/__root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { createRootRoute, Outlet } from "@tanstack/react-router";
import { TanStackRouterDevtools } from "@tanstack/router-devtools";

import NavLink from "@/components/NavLink";

export const Route = createRootRoute({
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 />
</>
)
}
6 changes: 6 additions & 0 deletions src/node/react/src/routes/index.lazy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createLazyFileRoute } from '@tanstack/react-router';
import HomePage from "@/pages/HomePage";

export const Route = createLazyFileRoute('/')({
component: HomePage,
})
6 changes: 6 additions & 0 deletions src/node/react/src/routes/sudoku.lazy.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { createLazyFileRoute } from '@tanstack/react-router';
import SudokuGamePage from "@/pages/SudokuGamePage";

export const Route = createLazyFileRoute('/sudoku')({
component: SudokuGamePage,
})
Loading

0 comments on commit 86be71e

Please sign in to comment.