commit 17ce3cf4c40b65f43d6913099ea785c876ffebfb Author: Nathaniel Tampus Date: Tue Jan 3 15:47:30 2023 +0800 move to public repo 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 ( + +
+
+ + } /> + }> + } /> + + } /> + +
+