-
Notifications
You must be signed in to change notification settings - Fork 3
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
6 changed files
with
86 additions
and
37 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
import App from "@/components/App"; | ||
import Hero from "@/components/Hero"; | ||
import Party from "@/components/Party"; | ||
import { getServerSession } from "next-auth"; | ||
|
||
export default async function Home() { | ||
const session = await getServerSession(); | ||
|
||
return ( | ||
<div className="bg-base-200 flex flex-grow justify-center pt-20"> | ||
<div>{session ? <Party /> : <Hero />}</div> | ||
<div>{session ? <App /> : <Hero />}</div> | ||
</div> | ||
); | ||
} |
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,23 @@ | ||
"use client"; | ||
|
||
import { Dispatch, SetStateAction, createContext, useState } from "react"; | ||
import Party from "./Party"; | ||
import Alert from "./Alert"; | ||
|
||
type ErrorContextProps = { | ||
error?: string; | ||
setError: Dispatch<SetStateAction<string | undefined>>; | ||
}; | ||
|
||
export const ErrorContext = createContext<ErrorContextProps>(undefined!); | ||
|
||
export default function App() { | ||
const [error, setError] = useState<string>(); | ||
|
||
return ( | ||
<ErrorContext.Provider value={{ error, setError }}> | ||
{error && <Alert>{error}</Alert>} | ||
<Party /> | ||
</ErrorContext.Provider> | ||
); | ||
} |
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,19 +1,30 @@ | ||
"use client"; | ||
|
||
import { useState } from "react"; | ||
import { useSWRConfig } from "swr"; | ||
|
||
export default function LeaveParty() { | ||
const [isLoading, setLoading] = useState(false); | ||
const { mutate } = useSWRConfig(); | ||
|
||
async function leaveParty() { | ||
setLoading(true); | ||
|
||
const res = await fetch("/api/party/leave", { | ||
method: "POST", | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new Error(await res.json()); | ||
} | ||
|
||
mutate("/api/user"); | ||
} | ||
|
||
return ( | ||
<button className="btn btn-error" onClick={() => leaveParty()}> | ||
Leave Party | ||
{isLoading && <span className="loading loading-dots loading-sm"></span>} | ||
</button> | ||
); | ||
} |
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,16 @@ | ||
export default function PartyCard({ | ||
children, | ||
code, | ||
}: { | ||
children: React.ReactNode; | ||
code: string; | ||
}) { | ||
return ( | ||
<div className="card w-96 bg-base-100 shadow-xl"> | ||
<div className="card-body"> | ||
<h1 className="card-title text-3xl">Code: {code.toUpperCase()}</h1> | ||
{children} | ||
</div> | ||
</div> | ||
); | ||
} |
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