From ff07858b3ee13817386191d0df6f6f6398ffc687 Mon Sep 17 00:00:00 2001 From: nehalist Date: Mon, 15 Apr 2024 09:15:30 +0200 Subject: [PATCH] cs: fix cs --- src/app/[locale]/(home)/login.tsx | 6 +- src/app/[locale]/(home)/page.tsx | 2 +- src/app/[locale]/(home)/teams/page.tsx | 8 +- src/app/[locale]/admin/layout.tsx | 4 +- src/app/[locale]/admin/page.tsx | 6 +- src/app/[locale]/invite/page.tsx | 6 +- src/app/[locale]/my/layout.tsx | 4 +- src/app/[locale]/my/leagues/[id]/content.tsx | 6 +- src/app/[locale]/my/leagues/create/page.tsx | 2 +- .../my/leagues/league-header-actions.tsx | 2 +- src/app/[locale]/my/settings/page.tsx | 4 +- src/app/[locale]/providers.tsx | 4 +- src/app/api/auth/[...nextauth]/route.ts | 2 +- src/components/achievement-list.tsx | 23 +- src/components/game-chip.tsx | 2 +- src/components/game-icon.tsx | 2 +- src/components/league-status-chip.tsx | 2 +- src/components/locale-switcher.tsx | 4 +- src/components/theme-switcher.tsx | 2 +- src/components/time-distance.tsx | 3 +- src/db/migrate.ts | 2 +- src/db/model/user.ts | 2 +- src/db/seed.ts | 249 ++++++++++-------- src/lib/navigation.ts | 2 +- 24 files changed, 197 insertions(+), 152 deletions(-) diff --git a/src/app/[locale]/(home)/login.tsx b/src/app/[locale]/(home)/login.tsx index 0e7fb8d..fa33a1d 100644 --- a/src/app/[locale]/(home)/login.tsx +++ b/src/app/[locale]/(home)/login.tsx @@ -1,11 +1,11 @@ "use client"; +import { LoginProviderIcon } from "@/components/login-provider-icon"; import { Card, CardBody } from "@nextui-org/card"; -import { getProviders, signIn } from "next-auth/react"; -import { useState } from "react"; import { Button, Input } from "@nextui-org/react"; -import { LoginProviderIcon } from "@/components/login-provider-icon"; +import { getProviders, signIn } from "next-auth/react"; import { useSearchParams } from "next/navigation"; +import { useState } from "react"; interface LoginProps { providers: Awaited>; diff --git a/src/app/[locale]/(home)/page.tsx b/src/app/[locale]/(home)/page.tsx index bdb07b7..15812c8 100644 --- a/src/app/[locale]/(home)/page.tsx +++ b/src/app/[locale]/(home)/page.tsx @@ -1,5 +1,5 @@ -import { LandingPage } from "@/app/[locale]/(home)/landing-page"; import { Home } from "@/app/[locale]/(home)/home"; +import { LandingPage } from "@/app/[locale]/(home)/landing-page"; import { getCurrentUser } from "@/lib/session"; import { getProviders } from "next-auth/react"; diff --git a/src/app/[locale]/(home)/teams/page.tsx b/src/app/[locale]/(home)/teams/page.tsx index ca6721e..b1629d8 100644 --- a/src/app/[locale]/(home)/teams/page.tsx +++ b/src/app/[locale]/(home)/teams/page.tsx @@ -1,16 +1,14 @@ -import { getLeagueTeams, getSelectedUserLeague } from "@/db/model/league"; import { TeamsTable } from "@/app/[locale]/(home)/teams-table"; +import { getLeagueTeams, getSelectedUserLeague } from "@/db/model/league"; export default async function Teams() { const currentLeague = await getSelectedUserLeague(); - if (! currentLeague) { + if (!currentLeague) { return null; } const teams = await getLeagueTeams(currentLeague.id); - return ( - - ); + return ; } diff --git a/src/app/[locale]/admin/layout.tsx b/src/app/[locale]/admin/layout.tsx index a579fdf..88af5d6 100644 --- a/src/app/[locale]/admin/layout.tsx +++ b/src/app/[locale]/admin/layout.tsx @@ -1,6 +1,6 @@ -import { ReactNode } from "react"; -import { Link } from "@/lib/navigation"; import { Container } from "@/components/container"; +import { Link } from "@/lib/navigation"; +import { ReactNode } from "react"; const nav = [ { diff --git a/src/app/[locale]/admin/page.tsx b/src/app/[locale]/admin/page.tsx index 4316243..3bb51f8 100644 --- a/src/app/[locale]/admin/page.tsx +++ b/src/app/[locale]/admin/page.tsx @@ -1,8 +1,8 @@ -import { getCurrentUser } from "@/lib/session"; -import { redirect } from "@/lib/navigation"; -import { Card, CardBody, CardHeader } from "@nextui-org/card"; import { db } from "@/db"; import { leagues, matches, memberships, teams, users } from "@/db/schema"; +import { redirect } from "@/lib/navigation"; +import { getCurrentUser } from "@/lib/session"; +import { Card, CardBody, CardHeader } from "@nextui-org/card"; import { eq, sql } from "drizzle-orm"; async function getStats() { diff --git a/src/app/[locale]/invite/page.tsx b/src/app/[locale]/invite/page.tsx index 42c0906..c3ddf67 100644 --- a/src/app/[locale]/invite/page.tsx +++ b/src/app/[locale]/invite/page.tsx @@ -1,9 +1,9 @@ +import { InviteForm } from "@/app/[locale]/invite/form"; import { Container } from "@/components/container"; import { getLeagueByInviteCode, userIsInLeague } from "@/db/model/league"; -import { notFound } from "next/navigation"; -import { InviteForm } from "@/app/[locale]/invite/form"; -import { getCurrentUser } from "@/lib/session"; import { redirect } from "@/lib/navigation"; +import { getCurrentUser } from "@/lib/session"; +import { notFound } from "next/navigation"; export default async function Invite({ searchParams, diff --git a/src/app/[locale]/my/layout.tsx b/src/app/[locale]/my/layout.tsx index 771dd4a..dc07788 100644 --- a/src/app/[locale]/my/layout.tsx +++ b/src/app/[locale]/my/layout.tsx @@ -1,6 +1,6 @@ -import { ReactNode } from "react"; -import { Link } from "@/lib/navigation"; import { Container } from "@/components/container"; +import { Link } from "@/lib/navigation"; +import { ReactNode } from "react"; export default function MyLayout({ children }: { children: ReactNode }) { const nav = [ diff --git a/src/app/[locale]/my/leagues/[id]/content.tsx b/src/app/[locale]/my/leagues/[id]/content.tsx index 78162fb..62734cc 100644 --- a/src/app/[locale]/my/leagues/[id]/content.tsx +++ b/src/app/[locale]/my/leagues/[id]/content.tsx @@ -1,11 +1,11 @@ "use client"; -import { MembershipsTable } from "@/app/[locale]/my/leagues/[id]/memberships-table"; import { InviteCode } from "@/app/[locale]/my/leagues/[id]/invite-code"; -import { LeagueSettings } from "@/app/[locale]/my/leagues/[id]/settings"; import { LeagueStatus } from "@/app/[locale]/my/leagues/[id]/league-status"; -import { User } from "@/db/schema"; +import { MembershipsTable } from "@/app/[locale]/my/leagues/[id]/memberships-table"; +import { LeagueSettings } from "@/app/[locale]/my/leagues/[id]/settings"; import { getLeagueWithMemberships } from "@/db/model/league"; +import { User } from "@/db/schema"; export function LeagueManagementContent({ league, diff --git a/src/app/[locale]/my/leagues/create/page.tsx b/src/app/[locale]/my/leagues/create/page.tsx index 68dd602..99aae70 100644 --- a/src/app/[locale]/my/leagues/create/page.tsx +++ b/src/app/[locale]/my/leagues/create/page.tsx @@ -1,6 +1,6 @@ import { CreateLeagueForm } from "@/app/[locale]/my/leagues/create/form"; -import { getTranslations } from "next-intl/server"; import { MyHeader } from "@/app/[locale]/my/my-header"; +import { getTranslations } from "next-intl/server"; export default async function CreateLeague() { const t = await getTranslations("my.leagues.create"); diff --git a/src/app/[locale]/my/leagues/league-header-actions.tsx b/src/app/[locale]/my/leagues/league-header-actions.tsx index f167ea6..01d268b 100644 --- a/src/app/[locale]/my/leagues/league-header-actions.tsx +++ b/src/app/[locale]/my/leagues/league-header-actions.tsx @@ -1,7 +1,7 @@ "use client"; -import { Button } from "@nextui-org/react"; import { Link } from "@/lib/navigation"; +import { Button } from "@nextui-org/react"; import { useTranslations } from "next-intl"; export function LeagueHeaderActions() { diff --git a/src/app/[locale]/my/settings/page.tsx b/src/app/[locale]/my/settings/page.tsx index 8935b9e..cfbe485 100644 --- a/src/app/[locale]/my/settings/page.tsx +++ b/src/app/[locale]/my/settings/page.tsx @@ -1,10 +1,10 @@ +import { MyHeader } from "@/app/[locale]/my/my-header"; import { SettingsForm } from "@/app/[locale]/my/settings/form"; -import { redirect } from "next/navigation"; import { getCurrentUser } from "@/lib/session"; import { Card, CardBody, CardHeader } from "@nextui-org/card"; import { Divider } from "@nextui-org/react"; -import { MyHeader } from "@/app/[locale]/my/my-header"; import { getTranslations } from "next-intl/server"; +import { redirect } from "next/navigation"; export default async function Settings() { const user = await getCurrentUser(); diff --git a/src/app/[locale]/providers.tsx b/src/app/[locale]/providers.tsx index 105ecf6..75c0c85 100644 --- a/src/app/[locale]/providers.tsx +++ b/src/app/[locale]/providers.tsx @@ -1,9 +1,9 @@ "use client"; -import { ReactNode } from "react"; import { NextUIProvider } from "@nextui-org/react"; -import { ThemeProvider as NextThemesProvider, useTheme } from "next-themes"; import { SessionProvider } from "next-auth/react"; +import { ThemeProvider as NextThemesProvider, useTheme } from "next-themes"; +import { ReactNode } from "react"; import { ToastContainer } from "react-toastify"; import "react-toastify/dist/ReactToastify.css"; diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts index 7b38c1b..ca0b5b4 100644 --- a/src/app/api/auth/[...nextauth]/route.ts +++ b/src/app/api/auth/[...nextauth]/route.ts @@ -1,5 +1,5 @@ -import NextAuth from "next-auth"; import { authOptions } from "@/lib/auth"; +import NextAuth from "next-auth"; const handler = NextAuth(authOptions); diff --git a/src/components/achievement-list.tsx b/src/components/achievement-list.tsx index 0776544..53bf133 100644 --- a/src/components/achievement-list.tsx +++ b/src/components/achievement-list.tsx @@ -1,15 +1,24 @@ -import { Achievement, League } from "@/db/schema"; import { AchievementCard } from "@/components/achievement-card"; +import { Achievement, League } from "@/db/schema"; interface AchievementListProps { achievements: Achievement[]; league: League; } -export function AchievementList({ achievements, league }: AchievementListProps) { - return
    - {achievements.map(achievement => ( - - ))} -
+export function AchievementList({ + achievements, + league, +}: AchievementListProps) { + return ( +
    + {achievements.map(achievement => ( + + ))} +
+ ); } diff --git a/src/components/game-chip.tsx b/src/components/game-chip.tsx index 3e25fe4..bca63f9 100644 --- a/src/components/game-chip.tsx +++ b/src/components/game-chip.tsx @@ -1,8 +1,8 @@ "use client"; +import { GameIcon } from "@/components/game-icon"; import { Game, games } from "@/lib/games"; import { Chip } from "@nextui-org/react"; -import { GameIcon } from "@/components/game-icon"; export function GameChip({ game }: { game: Game["id"] }) { const gameData = games.find(g => g.id === game); diff --git a/src/components/game-icon.tsx b/src/components/game-icon.tsx index 481fe21..457e468 100644 --- a/src/components/game-icon.tsx +++ b/src/components/game-icon.tsx @@ -2,8 +2,8 @@ import { Game, games } from "@/lib/games"; import { ReactNode } from "react"; -import { GiChessPawn, GiShuttlecock, GiSoccerField } from "react-icons/gi"; import { FaTrophy } from "react-icons/fa"; +import { GiChessPawn, GiShuttlecock, GiSoccerField } from "react-icons/gi"; export function GameIcon({ game: game }: { game: Game["id"] }) { const gameData = games.find(g => g.id === game); diff --git a/src/components/league-status-chip.tsx b/src/components/league-status-chip.tsx index e720635..b04a00e 100644 --- a/src/components/league-status-chip.tsx +++ b/src/components/league-status-chip.tsx @@ -1,7 +1,7 @@ "use client"; -import { Chip } from "@nextui-org/react"; import { leagueStatusEnum } from "@/db/schema"; +import { Chip } from "@nextui-org/react"; export function LeagueStatusChip({ status, diff --git a/src/components/locale-switcher.tsx b/src/components/locale-switcher.tsx index d25a4b4..6c81fea 100644 --- a/src/components/locale-switcher.tsx +++ b/src/components/locale-switcher.tsx @@ -1,6 +1,6 @@ "use client"; -import { useLocale, useTranslations } from "next-intl"; +import { locales } from "@/i18n"; import { usePathname, useRouter } from "@/lib/navigation"; import { Button, @@ -9,7 +9,7 @@ import { DropdownMenu, DropdownTrigger, } from "@nextui-org/react"; -import { locales } from "@/i18n"; +import { useLocale, useTranslations } from "next-intl"; export function LocaleSwitcher() { const locale = useLocale(); diff --git a/src/components/theme-switcher.tsx b/src/components/theme-switcher.tsx index 879bf04..cdcf2a9 100644 --- a/src/components/theme-switcher.tsx +++ b/src/components/theme-switcher.tsx @@ -1,7 +1,7 @@ "use client"; -import { useTheme } from "next-themes"; import { Button } from "@nextui-org/react"; +import { useTheme } from "next-themes"; import { MdDarkMode, MdLightMode } from "react-icons/md"; export function ThemeSwitcher() { diff --git a/src/components/time-distance.tsx b/src/components/time-distance.tsx index 4333d8f..cb44c0c 100644 --- a/src/components/time-distance.tsx +++ b/src/components/time-distance.tsx @@ -1,8 +1,7 @@ "use client"; -import { useEffect, useState } from "react"; import { differenceInHours, format, formatDistance } from "date-fns"; -import { useLocale } from "next-intl"; +import { useEffect, useState } from "react"; const threshold = 24; diff --git a/src/db/migrate.ts b/src/db/migrate.ts index 6dd3e15..6a1d5f4 100644 --- a/src/db/migrate.ts +++ b/src/db/migrate.ts @@ -1,6 +1,6 @@ +import { client, db } from "@/db"; import "dotenv/config"; import { migrate } from "drizzle-orm/postgres-js/migrator"; -import { client, db } from "@/db"; (async () => { await migrate(db, { migrationsFolder: "./drizzle" }); diff --git a/src/db/model/user.ts b/src/db/model/user.ts index 82eae2e..0133589 100644 --- a/src/db/model/user.ts +++ b/src/db/model/user.ts @@ -1,5 +1,5 @@ -import { User, users } from "@/db/schema"; import { db } from "@/db"; +import { User, users } from "@/db/schema"; import { eq } from "drizzle-orm"; export async function getUserById(id: string) { diff --git a/src/db/seed.ts b/src/db/seed.ts index a1b3ab0..4d03e78 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -1,105 +1,144 @@ -import { faker, simpleFaker } from "@faker-js/faker"; -import { db } from "@/db"; -import { League, leagues, memberships, NewTeam, teams, User, users } from "@/db/schema"; -import { eq } from "drizzle-orm"; - -type TeamsSeedProps = { - count: number | undefined, - owner: User, - league: League, -}; - -async function seedUser(): Promise { - const email = faker.internet.email().toLowerCase(); - const name = email.split("@")[0]; - - const [user] = await db.insert(users).values({ - id: simpleFaker.string.uuid(), - name, - email, - emailVerified: new Date(), - }).onConflictDoNothing().returning(); - - return user; -} - -async function seedLeague({ user, role, setSelectedLeague }: { user: User; role: "admin" | "member"; setSelectedLeague: boolean }): Promise { - const [league] = await db.insert(leagues).values({ - name: faker.company.name(), - ownerId: user.id, - }).onConflictDoNothing().returning(); - - await db - .insert(memberships) - .values({ - leagueId: league.id, - userId: user.id, - role, - }); - - if (setSelectedLeague) { - await db.update(users).set({ - selectedLeagueId: league.id, - }).where(eq(users.id, user.id)) - } - - return league; -} - -function generateTeam({ owner, league, teamSize }: { owner: User, league: League, teamSize: number }): NewTeam { - let names: string[] = []; - - for (let i = 0; i < teamSize; i++) { - names.push(faker.person.firstName().toLowerCase().substring(0, 2)); - } - - return { - name: names.join(","), - teamSize, - leagueId: league.id, - userId: owner.id, - }; -} - -function generateTeams({ owner, league, count }: TeamsSeedProps): NewTeam[] { - return [...Array(count).keys()].map((i) => { - console.log(`Generate team ${i + 1}...`); - - return generateTeam({ - owner, - league, - teamSize: faker.number.int({ - min: 1, - max: 3, - }), - }); - }); -} - -async function seedTeams({ owner, league, count }: TeamsSeedProps) { - const newTeams = generateTeams({ - owner, - league, - count, - }); - await db.insert(teams).values(newTeams).onConflictDoNothing(); -} - -async function clear() { - await db.delete(teams); - await db.delete(memberships); - await db.delete(leagues); - await db.delete(users); -} - -async function seed() { - const teamCount = 20; - const user = await seedUser(); - const league = await seedLeague({ user, role: "admin", setSelectedLeague: true }); - await seedTeams({ owner: user, league, count: teamCount }); -} - -clear().then(seed).finally(() => { - console.log("done seeding."); - process.exit(0); -}); +import { db } from "@/db"; +import { + League, + NewTeam, + User, + leagues, + memberships, + teams, + users, +} from "@/db/schema"; +import { faker, simpleFaker } from "@faker-js/faker"; +import { eq } from "drizzle-orm"; + +type TeamsSeedProps = { + count: number | undefined; + owner: User; + league: League; +}; + +async function seedUser(): Promise { + const email = faker.internet.email().toLowerCase(); + const name = email.split("@")[0]; + + const [user] = await db + .insert(users) + .values({ + id: simpleFaker.string.uuid(), + name, + email, + emailVerified: new Date(), + }) + .onConflictDoNothing() + .returning(); + + return user; +} + +async function seedLeague({ + user, + role, + setSelectedLeague, +}: { + user: User; + role: "admin" | "member"; + setSelectedLeague: boolean; +}): Promise { + const [league] = await db + .insert(leagues) + .values({ + name: faker.company.name(), + ownerId: user.id, + }) + .onConflictDoNothing() + .returning(); + + await db.insert(memberships).values({ + leagueId: league.id, + userId: user.id, + role, + }); + + if (setSelectedLeague) { + await db + .update(users) + .set({ + selectedLeagueId: league.id, + }) + .where(eq(users.id, user.id)); + } + + return league; +} + +function generateTeam({ + owner, + league, + teamSize, +}: { + owner: User; + league: League; + teamSize: number; +}): NewTeam { + let names: string[] = []; + + for (let i = 0; i < teamSize; i++) { + names.push(faker.person.firstName().toLowerCase().substring(0, 2)); + } + + return { + name: names.join(","), + teamSize, + leagueId: league.id, + userId: owner.id, + }; +} + +function generateTeams({ owner, league, count }: TeamsSeedProps): NewTeam[] { + return [...Array(count).keys()].map(i => { + console.log(`Generate team ${i + 1}...`); + + return generateTeam({ + owner, + league, + teamSize: faker.number.int({ + min: 1, + max: 3, + }), + }); + }); +} + +async function seedTeams({ owner, league, count }: TeamsSeedProps) { + const newTeams = generateTeams({ + owner, + league, + count, + }); + await db.insert(teams).values(newTeams).onConflictDoNothing(); +} + +async function clear() { + await db.delete(teams); + await db.delete(memberships); + await db.delete(leagues); + await db.delete(users); +} + +async function seed() { + const teamCount = 20; + const user = await seedUser(); + const league = await seedLeague({ + user, + role: "admin", + setSelectedLeague: true, + }); + await seedTeams({ owner: user, league, count: teamCount }); +} + +clear() + .then(seed) + .finally(() => { + console.log("done seeding."); + process.exit(0); + }); diff --git a/src/lib/navigation.ts b/src/lib/navigation.ts index d09843d..51b914f 100644 --- a/src/lib/navigation.ts +++ b/src/lib/navigation.ts @@ -1,5 +1,5 @@ -import { createSharedPathnamesNavigation } from "next-intl/navigation"; import { locales } from "@/i18n"; +import { createSharedPathnamesNavigation } from "next-intl/navigation"; export const localePrefix = "always"; // Default