organize imports
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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<User | null>({});
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
import type { User } from "@chessu/types";
|
||||
|
||||
import { createContext, Dispatch, SetStateAction } from "react";
|
||||
|
||||
export const SessionContext = createContext<{
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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<Game> = [];
|
||||
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Router } from "express";
|
||||
|
||||
import * as controller from "../controllers/auth.controller.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Router } from "express";
|
||||
|
||||
import * as controller from "../controllers/games.controller.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user