Skip to content

Commit

Permalink
Merge pull request #111 from hufs-sports-live/fix/all
Browse files Browse the repository at this point in the history
[FIX] 필요한 변경 사항을 모두 수정합니다.
  • Loading branch information
seongminn authored Nov 29, 2023
2 parents 91d560f + 08a1b7e commit 6da952a
Show file tree
Hide file tree
Showing 18 changed files with 249 additions and 88 deletions.
1 change: 1 addition & 0 deletions next.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const nextConfig = {
domains: [
'hufstreaming.s3.ap-northeast-2.amazonaws.com',
'hufscheer-server.s3.ap-northeast-2.amazonaws.com',
'github.com',
],
},
};
Expand Down
18 changes: 13 additions & 5 deletions src/api/match.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ export type MatchListParams = {
cursor?: number;
};

export const getMatchList = async (
{ cursor, ...params }: MatchListParams,
size = 3,
) => {
export const getMatchList = async ({ cursor, ...params }: MatchListParams) => {
const queryString = convertObjectToQueryString(params);

const { data } = await instance.get<MatchListType[]>(
`games?${queryString}&cursor=${cursor || ''}&size=${size}`,
`games?${queryString}&cursor=${cursor || ''}`,
);

return data;
Expand All @@ -47,6 +44,17 @@ export const getMatchCheerById = async (matchId: string) => {
return data;
};

export const postCheer = async ({
matchId,
...payload
}: {
matchId: string;
gameTeamId: number;
cheerCount: number;
}) => {
return await instance.post(`/games/${matchId}/cheer`, payload);
};

export const getGameComments = async (gameId: string, cursor = 1) => {
const response = await instance.get<MatchCommentType[]>(
`/games/${gameId}/comments?cursor=${cursor}`,
Expand Down
8 changes: 7 additions & 1 deletion src/app/match/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ export default function Match({ params }: { params: { id: string } }) {
loadingFallback={<Loader />}
>
<MatchCheerByIdFetcher matchId={params.id}>
{data => <Cheer cheers={data} />}
{({ cheers, matchTeams }) => (
<Cheer
matchId={params.id}
cheers={cheers}
matchTeams={matchTeams}
/>
)}
</MatchCheerByIdFetcher>
</AsyncBoundary>
<Panel options={options} defaultValue="라인업">
Expand Down
8 changes: 7 additions & 1 deletion src/app/rummikube/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,13 @@ export default function Rummikute({ params }: { params: { id: string } }) {
loadingFallback={<Loader />}
>
<MatchCheerByIdFetcher matchId={params.id}>
{data => <Cheer cheers={data} />}
{({ cheers, matchTeams }) => (
<Cheer
matchId={params.id}
cheers={cheers}
matchTeams={matchTeams}
/>
)}
</MatchCheerByIdFetcher>
</AsyncBoundary>
<Panel options={options} defaultValue="라인업">
Expand Down
29 changes: 20 additions & 9 deletions src/components/match/Cheer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
import { FallbackProps } from '@/components/common/ErrorBoundary';
import { MatchCheerType } from '@/types/match';
import { MatchCheerType, MatchTeamType } from '@/types/match';

import CheerTeam from '../CheerTeam';

type CheerProps = {
matchId: string;
cheers: MatchCheerType[];
matchTeams: MatchTeamType[];
};

export default function Cheer({ cheers }: CheerProps) {
const [firstTeam, secondTeam] = cheers;
export default function Cheer({ matchId, cheers, matchTeams }: CheerProps) {
const [firstTeamCheer, secondTeamCheer] = cheers;
const [firstTeam, secondTeam] = matchTeams;

return (
<div className="min-h-10 relative my-5 flex h-full w-full justify-center gap-5 p-2">
<CheerTeam className="bg-cheer-left">
🤜
<span className="ml-3">{firstTeam.cheerCount}</span>
<CheerTeam
className="flex-row-reverse bg-cheer-left"
matchId={matchId}
gameTeamId={firstTeam.gameTeamId}
cheerCount={firstTeamCheer.cheerCount}
>
<span>{firstTeam.gameTeamName} 🤜</span>
</CheerTeam>
<div className="absolute top-1/2 -translate-y-1/2 rounded-xl bg-white px-5 py-1 text-center font-bold text-gray-4">
VS
</div>
<CheerTeam className="bg-cheer-right">
<span className="mr-3">{secondTeam.cheerCount}</span>
🤛
<CheerTeam
matchId={matchId}
className="bg-cheer-right"
gameTeamId={secondTeam.gameTeamId}
cheerCount={secondTeamCheer.cheerCount}
>
<span>🤛 {secondTeam.gameTeamName}</span>
</CheerTeam>
</div>
);
Expand Down
56 changes: 48 additions & 8 deletions src/components/match/CheerTeam/index.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,63 @@
import { ComponentProps } from 'react';
'use client';

import { useQueryClient } from '@tanstack/react-query';
import { ComponentProps, useEffect, useState } from 'react';

import useQueryDebounce from '@/hooks/useQueryDebounce';
import useCheerMutation from '@/queries/useCheerMutation/query';
import { $ } from '@/utils/core';

interface CheerTeamType extends ComponentProps<'button'> {
matchId: string;
cheerCount: number;
gameTeamId: number;
}

export default function CheerTeam({
matchId,
gameTeamId,
cheerCount,
children,
className,
...props
}: ComponentProps<'div'>) {
}: CheerTeamType) {
const [count, setCount] = useState(0);
const { mutate } = useCheerMutation({ matchId, gameTeamId });
const debouncedCount = useQueryDebounce<number>(count, 1000 * 5);
const queryClient = useQueryClient();

useEffect(() => {
const handleCheerClick = (cheerCount: number) => {
mutate(cheerCount, {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['match-cheer', matchId] });
},
onError: (data, variables, context) => {
queryClient.setQueryData(
['match-cheer', matchId],
context?.previousCount,
);
},
onSettled: () => {
setCount(0);
},
});
};

handleCheerClick(debouncedCount);
}, [debouncedCount, matchId, mutate, queryClient]);

return (
<div
<button
onClick={() => setCount(prev => prev + 1)}
className={$(
'flex h-14 w-full cursor-pointer items-center justify-evenly rounded-xl shadow-lg',
'flex h-14 w-full cursor-pointer items-center justify-center gap-2 rounded-xl text-white shadow-lg',
className,
)}
{...props}
>
<button className="flex w-full items-center justify-center text-white">
{children}
</button>
</div>
<span>{cheerCount + count}</span>
<span>{children}</span>
</button>
);
}
17 changes: 14 additions & 3 deletions src/components/match/CommentForm/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { UseMutateFunction } from '@tanstack/react-query';
import { ChangeEvent, FormEvent, useState } from 'react';
import { ChangeEvent, FormEvent, Fragment, useState } from 'react';

import { MatchCommentPayload, MatchTeamType } from '@/types/match';
import { $ } from '@/utils/core';

type CommentFormProps = {
matchId: string;
Expand All @@ -10,6 +11,13 @@ type CommentFormProps = {
scrollToBottom: () => void;
};

const teamColor = [
'bg-cheer-left',
'bg-[#fb923c] ',
'bg-cheer-right',
'bg-[#22c55e]',
] as const;

export default function CommentForm({
matchId,
matchTeams,
Expand Down Expand Up @@ -44,7 +52,7 @@ export default function CommentForm({
})
}
>
<fieldset className="absolute top-0 flex w-full -translate-y-full items-center justify-start gap-4 rounded-lg bg-white px-5 py-3">
<fieldset className="absolute top-0 flex w-full -translate-y-full items-center justify-between gap-4 rounded-lg bg-white px-5 py-3">
{matchTeams.map(team => (
<label key={team.gameTeamId} className="flex items-center">
<input
Expand All @@ -54,7 +62,10 @@ export default function CommentForm({
onChange={handleRadioClick}
className="dark:border-gray-6 dark:bg-gray-6 mr-1 h-4 w-4 border-gray-3 bg-gray-1 text-primary focus:ring-2 focus:ring-primary dark:ring-offset-black dark:focus:ring-primary"
/>
{team.gameTeamName}
🙋
<div
className={$('h-2 w-2 rounded-full', teamColor[team.order - 1])}
></div>
</label>
))}
</fieldset>
Expand Down
2 changes: 1 addition & 1 deletion src/components/match/CommentItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ type CommentItemProps = {

const teamColor = [
'bg-[#ffb2b2]',
'bg-[#fdd3b1]',
'bg-[#b2c3ff]',
'bg-[#fdd3b1]',
'bg-[#a6e7be]',
] as const;

Expand Down
3 changes: 2 additions & 1 deletion src/components/match/Video/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ Video.ErrorFallback = function ErrorFallback({
message =
VIDEO_API_ERROR_MESSAGE[code as keyof typeof VIDEO_API_ERROR_MESSAGE];
} else if (error instanceof Error) {
message = '경기 영상이 등록되지 않았거나 불러올 수가 없어요!';
message = '경기 영상이 등록되지 않았어요!';
}

return (
<div className="flex h-full w-full flex-col items-center justify-center gap-5 rounded-xl py-10">
<span className="text-gary-5">⚠️ {message}</span>
Expand Down
46 changes: 31 additions & 15 deletions src/components/rummikub/Cheer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,37 +1,53 @@
import { FallbackProps } from '@/components/common/ErrorBoundary';
import CheerTeam from '@/components/match/CheerTeam';
import { MatchCheerType } from '@/types/match';
import { MatchCheerType, MatchTeamType } from '@/types/match';

type CheerProps = {
matchId: string;
cheers: MatchCheerType[];
matchTeams: MatchTeamType[];
};

export default function Cheer({ cheers }: CheerProps) {
const [firstTeam, secondTeam, thirdTeam, fourthTeam] = cheers;
export default function Cheer({ matchId, cheers, matchTeams }: CheerProps) {
const [firstTeamCheer, secondTeamCheer, thirdTeamCheer, fourthTeamCheer] =
cheers;
const [firstTeam, secondTeam, thirdTeam, fourthTeam] = matchTeams;

return (
<div className="min-h-10 relative my-5 flex h-full w-full justify-center gap-5 p-2">
<div className="flex w-full flex-col gap-3">
<CheerTeam className="bg-cheer-left">
🤜
<span className="ml-3">{firstTeam.cheerCount}</span>
<CheerTeam
{...firstTeamCheer}
matchId={matchId}
className="flex-row-reverse bg-cheer-left"
>
<span>{firstTeam.gameTeamName} 🤜</span>
</CheerTeam>
<CheerTeam className="bg-[#fb923c] ">
🤜
<span className="ml-3">{thirdTeam.cheerCount}</span>
<CheerTeam
{...secondTeamCheer}
matchId={matchId}
className="flex-row-reverse bg-[#fb923c] "
>
<span>{secondTeam.gameTeamName} 🤜</span>
</CheerTeam>
</div>
<div className="absolute top-1/2 -translate-y-1/2 rounded-xl bg-white px-5 py-1 text-center font-bold text-gray-4">
VS
</div>
<div className="flex w-full flex-col gap-3">
<CheerTeam className="bg-cheer-right">
<span className="mr-3">{secondTeam.cheerCount}</span>
🤛
<CheerTeam
{...thirdTeamCheer}
matchId={matchId}
className="bg-cheer-right"
>
<span>🤛 {thirdTeam.gameTeamName}</span>
</CheerTeam>
<CheerTeam className="bg-[#22c55e]">
<span className="mr-3">{fourthTeam.cheerCount}</span>
🤛
<CheerTeam
{...fourthTeamCheer}
matchId={matchId}
className="bg-[#22c55e]"
>
<span>🤛 {fourthTeam.gameTeamName}</span>
</CheerTeam>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/components/rummikub/MatchBanner/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default function RummiKubMatchBanner(match: MatchType) {
className="z-[0] h-[180px] fill-primary"
/>
<MatchCard.Status className="mt-5 text-black" />
<div className="z-10 flex items-center justify-center gap-4">
<div className="z-10 flex items-center justify-center gap-7">
<div className="flex flex-col items-center justify-center">
<MatchCard.Team
teamIndex={1}
Expand Down
42 changes: 13 additions & 29 deletions src/components/rummikub/MatchItem/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,37 +12,21 @@ export default function RummiKubMatchItem(match: MatchType) {
height={170}
className="z-[0] h-[180px] fill-primary"
/>
<MatchCard.Status className="mt-5 text-black" />
<MatchCard.Status className="my-2 text-black" />

<div className="z-10 flex items-center justify-center gap-4">
<div className="flex flex-col items-center justify-center">
<MatchCard.Team
teamIndex={1}
className="flex flex-col items-center justify-center [&>img]:my-0"
/>
<MatchCard.Score teamIndex={1} />
</div>
<div className="flex flex-col items-center justify-center">
<MatchCard.Team
teamIndex={2}
className="flex flex-col items-center justify-center [&>img]:my-0"
/>
<MatchCard.Score teamIndex={2} />
</div>
<div className="flex flex-col items-center justify-center">
<MatchCard.Team
teamIndex={3}
className="flex flex-col items-center justify-center [&>img]:my-0"
/>
<MatchCard.Score teamIndex={3} />
</div>
<div className="flex flex-col items-center justify-center">
<MatchCard.Team
teamIndex={4}
className="flex flex-col items-center justify-center [&>img]:my-0"
/>
<MatchCard.Score teamIndex={4} />
</div>
{match.gameTeams.map(team => (
<div
key={team.gameTeamId}
className="flex flex-col items-center justify-center"
>
<MatchCard.Team
teamIndex={team.order}
className="flex flex-col items-center justify-center [&>img]:my-0"
/>
<MatchCard.Score teamIndex={team.order} />
</div>
))}
</div>
<div className="flex items-center justify-center"></div>
</div>
Expand Down
Loading

0 comments on commit 6da952a

Please sign in to comment.