-
Notifications
You must be signed in to change notification settings - Fork 0
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
1 parent
a3a8225
commit d9d863c
Showing
12 changed files
with
185 additions
and
60 deletions.
There are no files selected for viewing
74 changes: 74 additions & 0 deletions
74
app/(dashboard)/room/[roomId]/_components/board-toolbar.tsx
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,74 @@ | ||
import { Avatar, AvatarFallback, AvatarImage } from "@/components/ui/avatar"; | ||
import { Button } from "@/components/ui/button"; | ||
import { useBoard } from "@/context/board"; | ||
import { cn } from "@/lib/utils"; | ||
|
||
const MAX_AVATAR_DISPLAY = 5; | ||
|
||
export const BoardToolbar = () => { | ||
const { others, self, handleRevealCards, reveal, handleReset } = useBoard(); | ||
|
||
if (!others.length) { | ||
return null; | ||
} | ||
|
||
const onRevealClick = () => { | ||
if (reveal) { | ||
handleReset(); | ||
} | ||
handleRevealCards(); | ||
}; | ||
|
||
const playersAvatar = () => { | ||
let avatarList = [self, ...others].map((player) => ({ | ||
name: player.name | ||
.split(" ") | ||
.map((name) => name[0]) | ||
.slice(0, 2) | ||
.join(""), | ||
imageUrl: player.imageUrl ?? undefined, | ||
})); | ||
|
||
if (avatarList.length > MAX_AVATAR_DISPLAY) { | ||
avatarList = avatarList.slice(0, MAX_AVATAR_DISPLAY); | ||
avatarList.push({ | ||
name: `+${others.length - MAX_AVATAR_DISPLAY}`, | ||
imageUrl: undefined, | ||
}); | ||
} | ||
|
||
return ( | ||
<div className="flex items-center gap-[-4px]"> | ||
{avatarList.map((player, index) => ( | ||
<Avatar | ||
key={player.name} | ||
className={cn("border-2 border-white", { | ||
"-ml-2": index > 0, | ||
})} | ||
> | ||
<AvatarImage src={player.imageUrl ?? undefined} /> | ||
<AvatarFallback className="text-xs bg-gradient-to-tr from-sky-300 to-gray-300 "> | ||
{player.name} | ||
</AvatarFallback> | ||
</Avatar> | ||
))} | ||
</div> | ||
); | ||
}; | ||
|
||
return ( | ||
<div className=" border border-gray-200 p-2 rounded-xl flex items-center justify-between gap-2"> | ||
<Button onClick={onRevealClick} size={"sm"}> | ||
{reveal ? "Iniciar outro jogo" : "Revelar cartas 👀"} | ||
</Button> | ||
|
||
<Button variant={"ghost"} onClick={handleReset} size={"sm"}> | ||
Limpar | ||
</Button> | ||
|
||
<hr className="w-[1px] border-l border-gray-200 h-full" /> | ||
|
||
{playersAvatar()} | ||
</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
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,25 @@ | ||
import { useBoard } from "@/context/board"; | ||
import { PlayerCard } from "./player-card"; | ||
|
||
export const Deck = () => { | ||
const { others, self } = useBoard(); | ||
|
||
const players = [self, ...others]; | ||
|
||
if (!others.length) { | ||
return ( | ||
<div className="flex items-center justify-center h-full"> | ||
<p className="text-gray-500">Sozinho por aqui... 😴</p> | ||
{/* adicionar botão de convidar */} | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="grid grid-cols-4 gap-4"> | ||
{players.map((player) => ( | ||
<PlayerCard key={player.id} player={player} /> | ||
))} | ||
</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
71 changes: 71 additions & 0 deletions
71
app/(dashboard)/room/[roomId]/_components/player-notification-popup.tsx
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,71 @@ | ||
import { useBoard } from "@/context/board"; | ||
import { Player } from "@/lib/schemas/player"; | ||
import { cn } from "@/lib/utils"; | ||
import { notificationIcons } from "@/messages/notification"; | ||
import { EnumNotification } from "@/types/notifications"; | ||
import { | ||
Popover, | ||
PopoverContent, | ||
PopoverPortal, | ||
PopoverTrigger, | ||
} from "@radix-ui/react-popover"; | ||
import { ReactNode, useState } from "react"; | ||
|
||
export function PlayerNotificationPopup({ | ||
children, | ||
player, | ||
}: { | ||
children: ReactNode; | ||
player: Player; | ||
}) { | ||
const { handleNotifyPlayer } = useBoard(); | ||
const [open, setOpen] = useState(false); | ||
|
||
const onNotifificationClick = (notification: EnumNotification) => { | ||
setOpen(false); | ||
if (player.choice) return; | ||
|
||
handleNotifyPlayer(player.id, notification); | ||
}; | ||
|
||
return ( | ||
<Popover open={open} onOpenChange={(open) => setOpen(open)}> | ||
<PopoverTrigger | ||
onClick={() => setOpen((prev) => !prev)} | ||
disabled={!!player.choice} | ||
> | ||
<div | ||
className={cn( | ||
"before:absolute before:top-1/2 before:-translate-x-1/2 before:-translate-y-full before:z-10 before:scale-0 before:hover:scale-100 before:transition-transform relative", | ||
{ | ||
"before:content-['🔉']": !player.choice, | ||
"before:scale-100": open, | ||
} | ||
)} | ||
> | ||
{children} | ||
</div> | ||
</PopoverTrigger> | ||
<PopoverPortal> | ||
<PopoverContent side="top" sideOffset={10}> | ||
<div className="flex items-center rounded-full p-1 bg-white shadow-md gap-4 border border-gray-200"> | ||
{Object.keys(notificationIcons).map((notification) => ( | ||
<div | ||
key={notification} | ||
role="presentation" | ||
onClick={() => | ||
onNotifificationClick(notification as EnumNotification) | ||
} | ||
className="p-1 w-10 cursor-pointer aspect-square rounded-full hover:bg-gray-100" | ||
> | ||
<span className="text-2xl flex items-center justify-center"> | ||
{notificationIcons[notification as EnumNotification]} | ||
</span> | ||
</div> | ||
))} | ||
</div> | ||
</PopoverContent> | ||
</PopoverPortal> | ||
</Popover> | ||
); | ||
} |
45 changes: 0 additions & 45 deletions
45
app/(dashboard)/room/[roomId]/_components/players-cards.tsx
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
Binary file not shown.
Binary file not shown.
Binary file not shown.