-
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
123 additions
and
13 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import _ from "lodash"; | ||
import LeaveParty from "./LeaveParty"; | ||
import { User } from "./Party"; | ||
import StartGame from "./StartGame"; | ||
import StopGame from "./StopGame"; | ||
|
||
export default function PartyStarted({ user }: { user: User }) { | ||
if (!user) { | ||
throw new Error("User does not exist"); | ||
} | ||
|
||
if (!user.party) { | ||
throw new Error("User is not party of a party"); | ||
} | ||
|
||
if (!user.party.started) { | ||
throw new Error("Party has not started"); | ||
} | ||
|
||
if (!user.target) { | ||
throw new Error("User does not have a target"); | ||
} | ||
|
||
const party = user.party; | ||
|
||
return ( | ||
<div className="block max-w-sm p-6 bg-white border border-gray-200 rounded-lg shadow dark:bg-gray-800 dark:border-gray-700"> | ||
<h1 className="mb-2 text-2xl font-bold tracking-tight text-gray-900 dark:text-white"> | ||
Code: {party.code.toUpperCase()} | ||
</h1> | ||
<h2>Mode: {_.startCase(_.toLower(party.mode))}</h2> | ||
<h2>Target:</h2> | ||
<ul>{user.target.name}</ul> | ||
{party.adminId === user.id && <StopGame />} | ||
<LeaveParty /> | ||
</div> | ||
); | ||
} |
Empty file.
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,33 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
|
||
export default function RemovePlayer({ playerId }: { playerId: string }) { | ||
const router = useRouter(); | ||
|
||
async function removePlayer(playerId: string) { | ||
const res = await fetch("/api/party/remove", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ playerId }), | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new Error(await res.json()); | ||
} | ||
|
||
router.refresh(); | ||
} | ||
|
||
return ( | ||
<button | ||
type="button" | ||
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800" | ||
onClick={() => removePlayer(playerId)} | ||
> | ||
Remove | ||
</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,31 @@ | ||
"use client"; | ||
|
||
import { useRouter } from "next/navigation"; | ||
|
||
export default function StopGame() { | ||
const router = useRouter(); | ||
|
||
async function stopGame() { | ||
const res = await fetch("/api/party/stop", { | ||
method: "POST", | ||
}); | ||
|
||
if (!res.ok) { | ||
throw new Error(await res.json()); | ||
} | ||
|
||
console.log(await res.json()); | ||
|
||
router.refresh(); | ||
} | ||
|
||
return ( | ||
<button | ||
type="button" | ||
className="text-white bg-blue-700 hover:bg-blue-800 focus:ring-4 focus:ring-blue-300 font-medium rounded-lg text-sm px-5 py-2.5 me-2 mb-2 dark:bg-blue-600 dark:hover:bg-blue-700 focus:outline-none dark:focus:ring-blue-800" | ||
onClick={() => stopGame()} | ||
> | ||
Stop Game | ||
</button> | ||
); | ||
} |