diff --git a/client/src/components/ThemeToggle.tsx b/client/src/components/ThemeToggle.tsx index 02efac6..e49a205 100644 --- a/client/src/components/ThemeToggle.tsx +++ b/client/src/components/ThemeToggle.tsx @@ -1,7 +1,7 @@ "use client"; -import { IconSun, IconMoon } from "@tabler/icons-react"; -import { useState, useEffect } from "react"; +import { IconMoon, IconSun } from "@tabler/icons-react"; +import { useEffect, useState } from "react"; export default function ThemeToggle() { const [darkTheme, setDarkTheme] = useState(true); diff --git a/client/src/components/archive/ArchivedGame.tsx b/client/src/components/archive/ArchivedGame.tsx index b912181..8c89f83 100644 --- a/client/src/components/archive/ArchivedGame.tsx +++ b/client/src/components/archive/ArchivedGame.tsx @@ -1,19 +1,19 @@ "use client"; +import type { CustomSquares } from "@/types"; import { Game } from "@chessu/types"; -import { Chessboard } from "react-chessboard"; -import { useEffect, useReducer, useState, useRef } from "react"; import { IconChevronLeft, IconChevronRight, IconCopy, IconPlayerSkipBack, - IconPlayerSkipForward + IconPlayerSkipForward, + IconRotateClockwise2 } from "@tabler/icons-react"; import type { Square } from "chess.js"; import { Chess } from "chess.js"; -import type { CustomSquares } from "@/types"; -import { IconRotateClockwise2 } from "@tabler/icons-react"; +import { useEffect, useReducer, useRef, useState } from "react"; +import { Chessboard } from "react-chessboard"; export default function ArchivedGame({ game }: { game: Game }) { const [boardWidth, setBoardWidth] = useState(480); diff --git a/client/src/components/auth/AuthModal.tsx b/client/src/components/auth/AuthModal.tsx index d500370..ce9e8e7 100644 --- a/client/src/components/auth/AuthModal.tsx +++ b/client/src/components/auth/AuthModal.tsx @@ -2,14 +2,14 @@ import { SessionContext } from "@/context/session"; import { login, logout, register, setGuestSession } from "@/lib/auth"; +import Link from "next/link"; import type { FormEvent } from "react"; import { useContext, useEffect, useRef, useState } from "react"; -import Link from "next/link"; +import { IconSettings2, IconUserCircle } from "@tabler/icons-react"; import Guest from "./Guest"; import Login from "./Login"; import Register from "./Register"; -import { IconSettings2, IconUserCircle } from "@tabler/icons-react"; export default function AuthModal() { const session = useContext(SessionContext); diff --git a/client/src/components/game/GameAuthWrapper.tsx b/client/src/components/game/GameAuthWrapper.tsx index c868ce6..f9a3a17 100644 --- a/client/src/components/game/GameAuthWrapper.tsx +++ b/client/src/components/game/GameAuthWrapper.tsx @@ -1,9 +1,10 @@ "use client"; -import { useContext } from "react"; import { SessionContext } from "@/context/session"; -import GamePage from "./GamePage"; import type { Game } from "@chessu/types"; +import { useContext } from "react"; + +import GamePage from "./GamePage"; export default function GameAuthWrapper({ initialLobby }: { initialLobby: Game }) { const session = useContext(SessionContext); diff --git a/client/src/components/game/GamePage.tsx b/client/src/components/game/GamePage.tsx index fe47761..da7e798 100644 --- a/client/src/components/game/GamePage.tsx +++ b/client/src/components/game/GamePage.tsx @@ -10,7 +10,6 @@ import { } from "@tabler/icons-react"; import type { FormEvent, KeyboardEvent } from "react"; -import Link from "next/link"; import { SessionContext } from "@/context/session"; import { useContext, useEffect, useReducer, useRef, useState } from "react"; diff --git a/client/src/components/game/socketEvents.ts b/client/src/components/game/socketEvents.ts index 6f8544d..d0bc426 100644 --- a/client/src/components/game/socketEvents.ts +++ b/client/src/components/game/socketEvents.ts @@ -2,6 +2,7 @@ import type { Action, CustomSquares, Lobby, Message } from "@/types"; import type { Game, User } from "@chessu/types"; import type { Dispatch, SetStateAction } from "react"; import type { Socket } from "socket.io-client"; + import { syncPgn, syncSide } from "./utils"; export function initSocket( diff --git a/client/src/components/home/CreateGame.tsx b/client/src/components/home/CreateGame.tsx index 918e663..839c08a 100644 --- a/client/src/components/home/CreateGame.tsx +++ b/client/src/components/home/CreateGame.tsx @@ -1,10 +1,11 @@ "use client"; +import { useRouter } from "next/navigation"; import type { FormEvent } from "react"; -import { useState, useContext } from "react"; +import { useContext, useState } from "react"; + import { SessionContext } from "@/context/session"; import { createGame } from "@/lib/game"; -import { useRouter } from "next/navigation"; export default function CreateGame() { const session = useContext(SessionContext); diff --git a/client/src/components/home/JoinGame.tsx b/client/src/components/home/JoinGame.tsx index ce9b6eb..1604f38 100644 --- a/client/src/components/home/JoinGame.tsx +++ b/client/src/components/home/JoinGame.tsx @@ -1,10 +1,11 @@ "use client"; +import { useRouter } from "next/navigation"; import type { FormEvent } from "react"; -import { useState, useContext } from "react"; +import { useContext, useState } from "react"; + import { SessionContext } from "@/context/session"; import { fetchActiveGame } from "@/lib/game"; -import { useRouter } from "next/navigation"; export default function JoinGame() { const session = useContext(SessionContext); diff --git a/client/src/components/user/CopyLink.tsx b/client/src/components/user/CopyLink.tsx index e47521d..60a8456 100644 --- a/client/src/components/user/CopyLink.tsx +++ b/client/src/components/user/CopyLink.tsx @@ -1,7 +1,7 @@ "use client"; -import { useState } from "react"; import { IconCopy } from "@tabler/icons-react"; +import { useState } from "react"; export default function CopyLink({ name }: { name: string }) { const [copiedLink, setCopiedLink] = useState(false); diff --git a/client/src/context/ContextProvider.tsx b/client/src/context/ContextProvider.tsx index 91eb386..95a15bd 100644 --- a/client/src/context/ContextProvider.tsx +++ b/client/src/context/ContextProvider.tsx @@ -1,10 +1,10 @@ "use client"; import type { User } from "@chessu/types"; +import { useEffect, useState } from "react"; -import { useState, useEffect } from "react"; -import { SessionContext } from "./session"; import { fetchSession } from "@/lib/auth"; +import { SessionContext } from "./session"; export default function ContextProvider({ children }: { children: React.ReactNode }) { const [user, setUser] = useState({}); diff --git a/client/src/context/session.ts b/client/src/context/session.ts index de6f15d..5382aac 100644 --- a/client/src/context/session.ts +++ b/client/src/context/session.ts @@ -1,5 +1,4 @@ import type { User } from "@chessu/types"; - import { createContext, Dispatch, SetStateAction } from "react"; export const SessionContext = createContext<{ diff --git a/client/src/lib/auth.ts b/client/src/lib/auth.ts index 1df17b0..86d528f 100644 --- a/client/src/lib/auth.ts +++ b/client/src/lib/auth.ts @@ -1,5 +1,5 @@ -import type { User } from "@chessu/types"; import { API_URL } from "@/config"; +import type { User } from "@chessu/types"; export const fetchSession = async () => { try { diff --git a/client/src/lib/game.ts b/client/src/lib/game.ts index 3c56126..ab9351f 100644 --- a/client/src/lib/game.ts +++ b/client/src/lib/game.ts @@ -1,5 +1,5 @@ -import type { Game } from "@chessu/types"; import { API_URL } from "@/config"; +import type { Game } from "@chessu/types"; export const createGame = async (side: string, unlisted: boolean) => { try { diff --git a/client/src/lib/user.ts b/client/src/lib/user.ts index 02f0c4e..e7c803b 100644 --- a/client/src/lib/user.ts +++ b/client/src/lib/user.ts @@ -1,5 +1,5 @@ import { API_URL } from "@/config"; -import type { User, Game } from "@chessu/types"; +import type { Game, User } from "@chessu/types"; export const fetchProfileData = async (name: string) => { try { diff --git a/server/src/controllers/auth.controller.ts b/server/src/controllers/auth.controller.ts index a6bdbaf..c9d8ac5 100644 --- a/server/src/controllers/auth.controller.ts +++ b/server/src/controllers/auth.controller.ts @@ -1,11 +1,11 @@ -import type { Request, Response } from "express"; import type { User } from "@chessu/types"; -import xss from "xss"; import { hash, verify } from "argon2"; +import type { Request, Response } from "express"; +import xss from "xss"; import { activeGames } from "../db/models/game.model.js"; -import { io } from "../server.js"; import UserModel from "../db/models/user.model.js"; +import { io } from "../server.js"; export const getCurrentSession = async (req: Request, res: Response) => { try { diff --git a/server/src/controllers/games.controller.ts b/server/src/controllers/games.controller.ts index c3249a5..673f597 100644 --- a/server/src/controllers/games.controller.ts +++ b/server/src/controllers/games.controller.ts @@ -1,8 +1,9 @@ -import type { Request, Response } from "express"; -import GameModel, { activeGames } from "../db/models/game.model.js"; import type { Game, User } from "@chessu/types"; +import type { Request, Response } from "express"; import { nanoid } from "nanoid"; +import GameModel, { activeGames } from "../db/models/game.model.js"; + export const getGames = async (req: Request, res: Response) => { try { if (!req.query.id && !req.query.userid) { diff --git a/server/src/db/models/game.model.ts b/server/src/db/models/game.model.ts index 5f99305..5beae0f 100644 --- a/server/src/db/models/game.model.ts +++ b/server/src/db/models/game.model.ts @@ -1,5 +1,5 @@ -import { db } from "../index.js"; import type { Game, User } from "@chessu/types"; +import { db } from "../index.js"; export const activeGames: Array = []; diff --git a/server/src/db/models/user.model.ts b/server/src/db/models/user.model.ts index 5d29f1b..cb23373 100644 --- a/server/src/db/models/user.model.ts +++ b/server/src/db/models/user.model.ts @@ -1,5 +1,5 @@ -import { db } from "../index.js"; import type { User } from "@chessu/types"; +import { db } from "../index.js"; export const create = async (user: User, password: string) => { if (user.name === "Guest" || user.email === undefined) { diff --git a/server/src/middleware/session.ts b/server/src/middleware/session.ts index d24a394..05ef2a0 100644 --- a/server/src/middleware/session.ts +++ b/server/src/middleware/session.ts @@ -1,9 +1,10 @@ -import { nanoid } from "nanoid"; +import type { User } from "@chessu/types"; +import PGSimple from "connect-pg-simple"; import type { Session } from "express-session"; import session from "express-session"; -import PGSimple from "connect-pg-simple"; +import { nanoid } from "nanoid"; + import { db } from "../db/index.js"; -import type { User } from "@chessu/types"; const PGSession = PGSimple(session); diff --git a/server/src/routes/auth.route.ts b/server/src/routes/auth.route.ts index efe6641..886e028 100644 --- a/server/src/routes/auth.route.ts +++ b/server/src/routes/auth.route.ts @@ -1,4 +1,5 @@ import { Router } from "express"; + import * as controller from "../controllers/auth.controller.js"; const router = Router(); diff --git a/server/src/routes/games.route.ts b/server/src/routes/games.route.ts index a64a789..13b0be6 100644 --- a/server/src/routes/games.route.ts +++ b/server/src/routes/games.route.ts @@ -1,4 +1,5 @@ import { Router } from "express"; + import * as controller from "../controllers/games.controller.js"; const router = Router(); diff --git a/server/src/routes/index.ts b/server/src/routes/index.ts index 7710b1b..9bf1a76 100644 --- a/server/src/routes/index.ts +++ b/server/src/routes/index.ts @@ -1,6 +1,7 @@ import { Router } from "express"; -import games from "./games.route.js"; + import auth from "./auth.route.js"; +import games from "./games.route.js"; import users from "./users.route.js"; const router = Router(); diff --git a/server/src/server.ts b/server/src/server.ts index 2bc1380..e94cde7 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -1,13 +1,14 @@ -import "dotenv/config"; import cors from "cors"; -import type { Request, Response, NextFunction } from "express"; +import "dotenv/config"; +import type { NextFunction, Request, Response } from "express"; import express from "express"; import { createServer } from "http"; -import session from "./middleware/session.js"; import { Server } from "socket.io"; -import { init as initSocket } from "./socket/index.js"; -import { db, INIT_TABLES } from "./db/index.js"; + +import { INIT_TABLES, db } from "./db/index.js"; +import session from "./middleware/session.js"; import routes from "./routes/index.js"; +import { init as initSocket } from "./socket/index.js"; const corsConfig = { origin: process.env.CORS_ORIGIN || "http://localhost:3000", diff --git a/server/src/socket/game.socket.ts b/server/src/socket/game.socket.ts index 5f4c245..34bb5a2 100644 --- a/server/src/socket/game.socket.ts +++ b/server/src/socket/game.socket.ts @@ -1,7 +1,8 @@ -import GameModel, { activeGames } from "../db/models/game.model.js"; import type { Game } from "@chessu/types"; -import type { DisconnectReason, Socket } from "socket.io"; import { Chess } from "chess.js"; +import type { DisconnectReason, Socket } from "socket.io"; + +import GameModel, { activeGames } from "../db/models/game.model.js"; import { io } from "../server.js"; export async function joinLobby(this: Socket, gameCode: string) { diff --git a/server/src/socket/index.ts b/server/src/socket/index.ts index d14d032..7e5db12 100644 --- a/server/src/socket/index.ts +++ b/server/src/socket/index.ts @@ -1,13 +1,14 @@ import type { Socket } from "socket.io"; + import { io } from "../server.js"; import { + chat, + claimAbandoned, + getLatestGame, + joinAsPlayer, joinLobby, leaveLobby, - getLatestGame, - sendMove, - joinAsPlayer, - chat, - claimAbandoned + sendMove } from "./game.socket.js"; const socketConnect = (socket: Socket) => {