From 17ce3cf4c40b65f43d6913099ea785c876ffebfb Mon Sep 17 00:00:00 2001 From: Nathaniel Tampus Date: Tue, 3 Jan 2023 15:47:30 +0800 Subject: [PATCH] move to public repo --- .editorconfig | 11 + .eslintrc | 34 +++ .gitignore | 33 +++ .prettierrc | 7 + LICENSE | 21 ++ README.md | 37 +++ chessu.session.sql | 12 + client/index.html | 13 + client/package.json | 28 +++ client/public/chessu.svg | 104 ++++++++ client/src/App.tsx | 32 +++ client/src/assets/oauth_facebook.png | Bin 0 -> 3848 bytes client/src/assets/oauth_google.png | Bin 0 -> 3983 bytes client/src/components/Auth/Auth.module.css | 125 +++++++++ client/src/components/Auth/Auth.tsx | 90 +++++++ client/src/components/Board/Board.tsx | 210 ++++++++++++++++ .../src/components/Footer/Footer.module.css | 14 ++ client/src/components/Footer/Footer.tsx | 24 ++ .../src/components/Header/Header.module.css | 15 ++ client/src/components/Header/Header.tsx | 47 ++++ client/src/config/config.ts | 1 + client/src/context/ContextProvider.tsx | 29 +++ client/src/context/session.ts | 7 + client/src/context/socket.ts | 18 ++ client/src/global.css | 39 +++ client/src/main.tsx | 10 + client/src/routes.tsx | 5 + client/src/routes/Game/Game.module.css | 121 +++++++++ client/src/routes/Game/Game.tsx | 238 ++++++++++++++++++ client/src/routes/Home/Home.module.css | 117 +++++++++ client/src/routes/Home/Home.tsx | 139 ++++++++++ client/src/routes/NotFound/NotFound.tsx | 5 + client/src/routes/ProtectedRoutes.tsx | 12 + client/src/utils/auth.ts | 29 +++ client/src/utils/games.ts | 24 ++ client/src/vite-env.d.ts | 1 + client/tsconfig.json | 28 +++ client/tsconfig.node.json | 9 + client/vercel.json | 3 + client/vite.config.ts | 7 + package.json | 27 ++ server/package.json | 29 +++ server/src/controllers/auth.controller.ts | 51 ++++ server/src/controllers/games.controller.ts | 74 ++++++ server/src/db/index.ts | 3 + server/src/db/init.sql | 16 ++ server/src/db/models/game.model.ts | 89 +++++++ server/src/db/models/user.model.ts | 87 +++++++ server/src/middleware/error.ts | 0 server/src/middleware/session.ts | 42 ++++ server/src/routes/auth.route.ts | 16 ++ server/src/routes/games.route.ts | 12 + server/src/routes/index.ts | 10 + server/src/server.ts | 46 ++++ server/src/socket/game.socket.ts | 164 ++++++++++++ server/src/socket/index.ts | 34 +++ server/tsconfig.json | 14 ++ types/index.ts | 17 ++ 58 files changed, 2430 insertions(+) create mode 100644 .editorconfig create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 .prettierrc create mode 100644 LICENSE create mode 100644 README.md create mode 100644 chessu.session.sql create mode 100644 client/index.html create mode 100644 client/package.json create mode 100644 client/public/chessu.svg create mode 100644 client/src/App.tsx create mode 100644 client/src/assets/oauth_facebook.png create mode 100644 client/src/assets/oauth_google.png create mode 100644 client/src/components/Auth/Auth.module.css create mode 100644 client/src/components/Auth/Auth.tsx create mode 100644 client/src/components/Board/Board.tsx create mode 100644 client/src/components/Footer/Footer.module.css create mode 100644 client/src/components/Footer/Footer.tsx create mode 100644 client/src/components/Header/Header.module.css create mode 100644 client/src/components/Header/Header.tsx create mode 100644 client/src/config/config.ts create mode 100644 client/src/context/ContextProvider.tsx create mode 100644 client/src/context/session.ts create mode 100644 client/src/context/socket.ts create mode 100644 client/src/global.css create mode 100644 client/src/main.tsx create mode 100644 client/src/routes.tsx create mode 100644 client/src/routes/Game/Game.module.css create mode 100644 client/src/routes/Game/Game.tsx create mode 100644 client/src/routes/Home/Home.module.css create mode 100644 client/src/routes/Home/Home.tsx create mode 100644 client/src/routes/NotFound/NotFound.tsx create mode 100644 client/src/routes/ProtectedRoutes.tsx create mode 100644 client/src/utils/auth.ts create mode 100644 client/src/utils/games.ts create mode 100644 client/src/vite-env.d.ts create mode 100644 client/tsconfig.json create mode 100644 client/tsconfig.node.json create mode 100644 client/vercel.json create mode 100644 client/vite.config.ts create mode 100644 package.json create mode 100644 server/package.json create mode 100644 server/src/controllers/auth.controller.ts create mode 100644 server/src/controllers/games.controller.ts create mode 100644 server/src/db/index.ts create mode 100644 server/src/db/init.sql create mode 100644 server/src/db/models/game.model.ts create mode 100644 server/src/db/models/user.model.ts create mode 100644 server/src/middleware/error.ts create mode 100644 server/src/middleware/session.ts create mode 100644 server/src/routes/auth.route.ts create mode 100644 server/src/routes/games.route.ts create mode 100644 server/src/routes/index.ts create mode 100644 server/src/server.ts create mode 100644 server/src/socket/game.socket.ts create mode 100644 server/src/socket/index.ts create mode 100644 server/tsconfig.json create mode 100644 types/index.ts diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..5e23c87 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,11 @@ +root = true + +[*] +end_of_line = lf +insert_final_newline = true + +[*.{js,ts,json}] +indent_size = 4 + +[*.{jsx,tsx,html}] +indent_size = 2 \ No newline at end of file diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..249cad4 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,34 @@ +{ + "settings": { + "react": { + "version": "detect" + } + }, + "root": true, + "env": { + "es2021": true, + "node": true + }, + "extends": [ + "eslint:recommended", + "plugin:react/recommended", + "plugin:react/jsx-runtime", + "plugin:@typescript-eslint/recommended", + "prettier" + ], + "overrides": [], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module" + }, + "plugins": ["react", "@typescript-eslint", "prettier"], + "rules": { + "prettier/prettier": [ + "error", + { + "endOfLine": "auto" + } + ] + } +} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..68ba517 --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +pnpm-debug.log* +lerna-debug.log* + +node_modules +dist +build +dist-ssr +*.local +package-lock.json + +.env +.env.test +.env.local +.env.development.local +.env.test.local +.env.production.local + +# Editor directories and files +.vscode/* +!.vscode/extensions.json +.idea +.DS_Store +*.suo +*.ntvs* +*.njsproj +*.sln +*.sw? diff --git a/.prettierrc b/.prettierrc new file mode 100644 index 0000000..08081b4 --- /dev/null +++ b/.prettierrc @@ -0,0 +1,7 @@ +{ + "semi": true, + "printWidth": 100, + "singleQuote": false, + "trailingComma": "none", + "endOfLine": "auto" +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..b6bf1c1 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023-present, Nathaniel Tampus + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..e5afda3 --- /dev/null +++ b/README.md @@ -0,0 +1,37 @@ +# chessu + +Online 2-player chess. Live demo at [ches.su](https://ches.su) + +- React 18 +- CSS Modules +- [react-chessboard](https://github.com/Clariity/react-chessboard) +- [chess.js](https://github.com/jhlywa/chess.js) +- Express.js +- socket.io +- PostgreSQL + +## Development + +Root directory + +```sh +npm install # install all dependencies + +npm run dev # concurrently run frontend and backend test servers + +npm run build # build frontend and backend for production (see dist/ folders) + +npm run react-dev # run frontend server only +``` + +### Environment variables + +Client: `APIURL` + +Server: `SESSION_SECRET`, `PGUSER`, `PGPASSWORD`, `PGHOST`, `PGDATABASE`, `PGPORT` + +## To-do (move this to issues): + +- [] real-time games with chat & observer support +- [] user authentication with oauth2 support (optional) +- [] RESTful API for non-real-time games like daily chess diff --git a/chessu.session.sql b/chessu.session.sql new file mode 100644 index 0000000..270bb75 --- /dev/null +++ b/chessu.session.sql @@ -0,0 +1,12 @@ +SELECT * FROM "user"; + +INSERT INTO "user"(name, email, password) VALUES('astwangw', 'tests@gmail.com', 'passwordd') RETURNING id, name, email; + +UPDATE "user" SET name = 'nizepogii' WHERE id = 1 RETURNING id, name, email; + +DELETE FROM "user" WHERE id = 4 RETURNING id, name, email; + +DROP TABLE "game"; +DROP TABLE "user"; + +INSERT INTO "game"(white_id, black_id) VALUES(undefined, undefined) RETURNING *; \ No newline at end of file diff --git a/client/index.html b/client/index.html new file mode 100644 index 0000000..a546081 --- /dev/null +++ b/client/index.html @@ -0,0 +1,13 @@ + + + + + + + Chessu + + +
+ + + diff --git a/client/package.json b/client/package.json new file mode 100644 index 0000000..ded581d --- /dev/null +++ b/client/package.json @@ -0,0 +1,28 @@ +{ + "name": "chessu", + "private": true, + "version": "0.0.0", + "type": "module", + "scripts": { + "dev": "vite", + "build": "tsc && vite build", + "preview": "vite preview" + }, + "dependencies": { + "@radix-ui/colors": "^0.1.8", + "@radix-ui/react-icons": "^1.1.1", + "chess.js": "^1.0.0-alpha.0", + "react": "^18.2.0", + "react-chessboard": "^1.3.1", + "react-dom": "^18.2.0", + "react-router-dom": "^6.6.1", + "socket.io-client": "^4.5.4" + }, + "devDependencies": { + "@types/react": "^18.0.26", + "@types/react-dom": "^18.0.10", + "@vitejs/plugin-react-swc": "^3.0.1", + "typescript": "^4.9.4", + "vite": "^4.0.3" + } +} diff --git a/client/public/chessu.svg b/client/public/chessu.svg new file mode 100644 index 0000000..cabe48a --- /dev/null +++ b/client/public/chessu.svg @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/client/src/App.tsx b/client/src/App.tsx new file mode 100644 index 0000000..18bbb0c --- /dev/null +++ b/client/src/App.tsx @@ -0,0 +1,32 @@ +import { Route, Routes } from "react-router-dom"; +import ContextProvider from "./context/ContextProvider"; + +import Header from "./components/Header/Header"; +import Footer from "./components/Footer/Footer"; + +import ProtectedRoutes from "./routes/ProtectedRoutes"; +import Home from "./routes/Home/Home"; +import Game from "./routes/Game/Game"; +import NotFound from "./routes/NotFound/NotFound"; + +import "./global.css"; + +const App = (): JSX.Element => { + return ( + +
+
+ + } /> + }> + } /> + + } /> + +
+