-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
325 additions
and
268 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,16 @@ | ||
import { MatchCreationForm } from "@/components/match-creation-form"; | ||
import { getCurrentUser, getUserLeagues } from "@/lib/session"; | ||
import { LeagueHeader } from "@/app/[locale]/(home)/league-header"; | ||
import { Container } from "@/components/container"; | ||
import { LeagueFeed } from "@/app/[locale]/(home)/league-feed"; | ||
import { MatchCreationForm } from "@/app/[locale]/(home)/match-creation-form"; | ||
import { getCurrentUser } from "@/lib/session"; | ||
import { | ||
getLeaguesForCurrentUser, | ||
getLeagueTeamsForCurrentUser, | ||
} from "@/db/model/league"; | ||
|
||
export async function Home() { | ||
const leagues = await getUserLeagues(); | ||
const user = await getCurrentUser(); | ||
|
||
if (!leagues || !user) { | ||
return null; // TODO | ||
} | ||
const teams = await getLeagueTeamsForCurrentUser(); | ||
|
||
return ( | ||
<Container> | ||
<div className="grid grid-cols-4 mt-5"> | ||
<div className="col-span-3"> | ||
<LeagueHeader | ||
leagues={leagues} | ||
selectedLeagueId={user.selectedLeagueId} | ||
/> | ||
<MatchCreationForm /> | ||
<LeagueFeed /> | ||
</div> | ||
</div> | ||
</Container> | ||
<MatchCreationForm | ||
teams={teams} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import React, { ReactNode } from "react"; | ||
import "@/styles/globals.css"; | ||
import { getLeaguesForCurrentUser } from "@/db/model/league"; | ||
import { getCurrentUser } from "@/lib/session"; | ||
import { LeagueHeader } from "@/app/[locale]/(home)/league-header"; | ||
import { Container } from "@/components/container"; | ||
|
||
export const metadata = { | ||
title: "Hilde - Platform", | ||
description: "Hilde.", | ||
}; | ||
|
||
export default async function HomeLayout({ | ||
children, | ||
params: { locale, ...params }, | ||
}: { | ||
children: ReactNode; | ||
params: { locale: string }; | ||
}) { | ||
const leagues = await getLeaguesForCurrentUser(); | ||
const user = await getCurrentUser(); | ||
|
||
if (!user || !leagues) { | ||
return <>{children}</>; | ||
} | ||
|
||
return ( | ||
<Container> | ||
<div className="grid grid-cols-4 mt-5"> | ||
<div className="col-span-3"> | ||
<LeagueHeader | ||
leagues={leagues} | ||
selectedLeagueId={user.selectedLeagueId} | ||
/> | ||
</div> | ||
</div> | ||
{children} | ||
</Container> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Container } from "@/components/container"; | ||
|
||
export default async function Matches() { | ||
return ( | ||
<Container> | ||
leaderboards | ||
</Container> | ||
); | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
"use client"; | ||
|
||
import { Card, CardBody, CardFooter } from "@nextui-org/card"; | ||
import { MatchTeamSelector } from "@/app/[locale]/(home)/match-team-selector"; | ||
import { Button, Divider, Input } from "@nextui-org/react"; | ||
import { League } from "@/db/schema"; | ||
import { getLeagueTeamsForCurrentUser } from "@/db/model/league"; | ||
import { Controller, useForm } from "react-hook-form"; | ||
import { useFormState } from "react-dom"; | ||
import { createMatchAction } from "@/app/[locale]/(home)/actions"; | ||
import { useRef } from "react"; | ||
|
||
interface MatchCreationFormProps { | ||
teams: Awaited<ReturnType<typeof getLeagueTeamsForCurrentUser>>; | ||
} | ||
|
||
interface FormValues { | ||
team1: string[]; | ||
score1: string; | ||
team2: string[]; | ||
score2: string; | ||
comment: string; | ||
} | ||
|
||
export function MatchCreationForm({ teams }: MatchCreationFormProps) { | ||
const { register, control } = useForm<FormValues>({ | ||
defaultValues: { | ||
team1: [], | ||
score1: "", | ||
team2: [], | ||
score2: "", | ||
comment: "", | ||
}, | ||
}); | ||
const [state, formAction] = useFormState(createMatchAction, null); | ||
const team1Ref = useRef<HTMLInputElement>(null); | ||
|
||
return ( | ||
<Card className="overflow-visible"> | ||
<form action={formAction}> | ||
<CardBody className="overflow-y-visible"> | ||
<div className="p-6"> | ||
<div className="grid grid-cols-12"> | ||
<div className="col-span-5"> | ||
<div className="grid grid-cols-12 gap-3"> | ||
<div className="col-span-8"> | ||
<input type="hidden" name="team1" ref={team1Ref} /> | ||
<Controller | ||
control={control} | ||
name="team1" | ||
render={({ field: { onChange } }) => ( | ||
<MatchTeamSelector | ||
teams={teams} | ||
onChange={data => { | ||
onChange(data); | ||
if (!team1Ref.current) { | ||
return; | ||
} | ||
return (team1Ref.current.value = data.join(",")); | ||
}} | ||
/> | ||
)} | ||
/> | ||
{/*<p className="text-xs">Suggestions: [self] others</p>*/} | ||
</div> | ||
<div className="col-span-4"> | ||
<Input | ||
type="number" | ||
placeholder="2" | ||
label="Score" | ||
labelPlacement="outside" | ||
{...register("score1")} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
<div className="col-span-2 text-center self-center"> | ||
<h3 className="font-bold text-3xl">vs</h3> | ||
</div> | ||
<div className="col-span-5"> | ||
<div className="grid grid-cols-12 gap-3"> | ||
<div className="col-span-8">{/*<MatchTeamSelector />*/}</div> | ||
<div className="col-span-4"> | ||
<Input | ||
type="number" | ||
placeholder="3" | ||
label="Score" | ||
labelPlacement="outside" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</CardBody> | ||
<Divider /> | ||
<CardFooter> | ||
<Button type="submit" color="primary"> | ||
Save | ||
</Button> | ||
</CardFooter> | ||
</form> | ||
</Card> | ||
); | ||
} |
Oops, something went wrong.