-
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.
Merge pull request #111 from hufs-sports-live/fix/all
[FIX] 필요한 변경 사항을 모두 수정합니다.
- Loading branch information
Showing
18 changed files
with
249 additions
and
88 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
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
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,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> | ||
); | ||
} |
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
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
Oops, something went wrong.