Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release/0.3.0 #19

Merged
merged 24 commits into from
Aug 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
78839e7
Merge pull request #8 from ItaloMedici/release/1.0.0
ItaloMedici Jul 20, 2024
7d528c6
fix: adjust reveal event key
ItaloMedici Jul 28, 2024
e3b08b7
chore: adjust db push script
ItaloMedici Jul 28, 2024
3e321c3
Merge pull request #11 from ItaloMedici/bugfix/10
ItaloMedici Jul 28, 2024
f1d8ade
feat: migrate all pages routes for api folder
ItaloMedici Aug 17, 2024
0fbc20b
break: remove socket
ItaloMedici Aug 17, 2024
5d1e31b
refactor: change socket calls to pooling
ItaloMedici Aug 17, 2024
87a738a
build: add swr
ItaloMedici Aug 17, 2024
1126015
feat: create messages
ItaloMedici Aug 17, 2024
e00ad3b
refactor: create fetcher
ItaloMedici Aug 17, 2024
b10fd6d
refactor: extract errors messages
ItaloMedici Aug 17, 2024
e8fe1cc
refactor: remove socket provider
ItaloMedici Aug 17, 2024
89f442b
feat: create notifications type
ItaloMedici Aug 17, 2024
9da40f6
refactor: adjust request type
ItaloMedici Aug 17, 2024
548047b
refactor: rename function
ItaloMedici Aug 17, 2024
a3a8225
refactor: adjust numeric card
ItaloMedici Aug 17, 2024
d9d863c
feat: create player notifications
ItaloMedici Aug 17, 2024
dfa0766
Merge pull request #14 from ItaloMedici/feature/13-change-socket-for-…
ItaloMedici Aug 17, 2024
8f0c90a
refactor: force dynamic
ItaloMedici Aug 17, 2024
88ca3df
fix: revalidate home when favorite room
ItaloMedici Aug 17, 2024
3a20e18
chore: add no-unused-vars rule
ItaloMedici Aug 17, 2024
00f10ef
refactor: remove unused variables
ItaloMedici Aug 17, 2024
eff20df
Merge pull request #17 from ItaloMedici/bugfix/16-favorite
ItaloMedici Aug 17, 2024
44a98c5
chore(release): v0.3.0
ItaloMedici Aug 21, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
{
"extends": "next/core-web-vitals"
"extends": "next/core-web-vitals",
"rules": {
"no-unused-vars":"error"
}
}
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@


# [0.3.0](https://github.com/ItaloMedici/pontim/compare/v0.2.0...v0.3.0) (2024-08-21)


### Bug Fixes

* adjust reveal event key ([7d528c6](https://github.com/ItaloMedici/pontim/commit/7d528c6eb1f5fc19ab0b06b7dc60d1ed4c78488a))
* revalidate home when favorite room ([88ca3df](https://github.com/ItaloMedici/pontim/commit/88ca3dff14ed065588082dfc0e6e031cf6bc3362))


### Features

* create messages ([1126015](https://github.com/ItaloMedici/pontim/commit/1126015cf41cb77d7cd342ace06a463f0aa7c6df))
* create notifications type ([89f442b](https://github.com/ItaloMedici/pontim/commit/89f442b7b7c97f2c217cf70225daca5998fb69c7))
* create player notifications ([d9d863c](https://github.com/ItaloMedici/pontim/commit/d9d863c5cd03774029247c54b08216a49718fdf1))
* migrate all pages routes for api folder ([f1d8ade](https://github.com/ItaloMedici/pontim/commit/f1d8ade39aa2db9e1714cda92cfbc52b956b6993))

# 0.2.0 (2024-07-20)


Expand Down
74 changes: 74 additions & 0 deletions app/(dashboard)/room/[roomId]/_components/board-toolbar.tsx
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>
);
};
15 changes: 6 additions & 9 deletions app/(dashboard)/room/[roomId]/_components/board.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,17 @@
"use client";

import { useBoard } from "@/context/board";
import { BoardNavbar } from "./board-navbar";
import { BoardToolbar } from "./board-toolbar";
import { CardsPicker } from "./cards-picker";
import { PlayersCards } from "./players-cards";
import { Deck } from "./deck";

export function Board() {
const { self, others } = useBoard();

return (
<div className="absolute inset-0 -z-10 h-full w-full bg-gray-50">
<div className="absolute inset-0 -z-10 h-full w-full bg-gray-50 overflow-hidden">
<BoardNavbar />
<div className="flex h-full items-center justify-center px-6">
<PlayersCards />
</div>
<div className="fixed w-full bottom-16 mx-auto px-6">
<div className="flex h-full flex-col items-center justify-between gap-6 p-4 pt-20 pb-12">
<BoardToolbar />
<Deck />
<CardsPicker />
</div>
</div>
Expand Down
4 changes: 2 additions & 2 deletions app/(dashboard)/room/[roomId]/_components/cards-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { useBoard } from "@/context/board";
import { cn } from "@/lib/utils";

export const CardsPicker = () => {
const { choiceOptions, handleChoice, self } = useBoard();
const { choiceOptions, handleChoice, selfChoice } = useBoard();

const isSelfOption = (option: string) => self.choice === option;
const isSelfOption = (option: string) => selfChoice == option;

return (
<div className="flex flex-col items-center justify-center flex-wrap gap-6">
Expand Down
25 changes: 25 additions & 0 deletions app/(dashboard)/room/[roomId]/_components/deck.tsx
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>
);
};
28 changes: 18 additions & 10 deletions app/(dashboard)/room/[roomId]/_components/player-card.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,41 @@
import { NumericCard } from "@/components/card/numeric-card";
import { useBoard } from "@/context/board";
import { Player } from "@/lib/schemas/player";
import { PlayerNotificationPopup } from "./player-notification-popup";

type PlayerCardProps = {
player: Player;
};

export const PlayerCard = ({ player }: PlayerCardProps) => {
const { revealCards, self } = useBoard();
const { reveal, self, selfChoice } = useBoard();

const isSelf = player.id === self.id;

const formatedChoice =
reveal && player.choice
? Buffer.from(player.choice, "base64").toString()
: "";

return (
<>
{isSelf ? (
<NumericCard
value={player.choice}
color={player.choice ? "primary" : "gray"}
value={selfChoice}
color={selfChoice ? "primary" : "gray"}
size={"large"}
label={"Você"}
/>
) : (
<NumericCard
value={revealCards ? player.choice : ""}
color={revealCards && player.choice ? "primary" : "gray"}
bgColor={revealCards ? "white" : player.choice ? "primary" : "gray"}
size={"large"}
label={player.name}
/>
<PlayerNotificationPopup player={player}>
<NumericCard
value={formatedChoice}
color={reveal && player.choice ? "primary" : "gray"}
bgColor={reveal ? "white" : player.choice ? "primary" : "gray"}
size={"large"}
label={player.name}
/>
</PlayerNotificationPopup>
)}
</>
);
Expand Down
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 app/(dashboard)/room/[roomId]/_components/players-cards.tsx

This file was deleted.

7 changes: 1 addition & 6 deletions app/(dashboard)/room/[roomId]/_components/room.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
"use client";

import { BoardProvider } from "@/context/board";
import { SocketClientProvider } from "@/context/socket-client";

type RoomProps = {
children: React.ReactNode;
roomId: string;
};

export const Room = ({ children, roomId }: RoomProps) => {
return (
<SocketClientProvider>
<BoardProvider roomId={roomId}>{children}</BoardProvider>
</SocketClientProvider>
);
return <BoardProvider roomId={roomId}>{children}</BoardProvider>;
};
22 changes: 22 additions & 0 deletions app/api/[roomId]/board/leave/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { leaveBoard } from "@/use-cases/board/leave-board";

export async function POST(
request: Request,
{ params }: { params: { roomId: string } }
) {
try {
const { roomId } = params;
const { playerId } = await request.json();

if (!playerId || !roomId) {
return Response.json({ message: "Invalid input" }, { status: 400 });
}

await leaveBoard({ roomId, playerId });

return Response.json({ message: "Succefully leave board" });
} catch (error: any) {
console.error(error);
return Response.json({ message: error?.message }, { status: 500 });
}
}
Loading
Loading