Repository navigation
fix: 찜 연속 클릭 시 상태 불일치 수정 및 찜 버튼 공통화 #66
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
06e5f22
fix: 찜 취소 후 재등록 시 재클릭 필요한 버그 수정
yooseohyeon d2cbaa9
fix: 찜 연속 클릭 시 요청 순서 보장
yooseohyeon 598a649
refactor: 공통 FavoriteButton 컴포넌트 생성 및 적용 (기사님 찾기 카드, 대기 견적 카드, 받은 견적 …
yooseohyeon 3b28f4d
feat: 공통 FavoriteButton 컴포넌트에서 onToggle prop를 필수로 변경
yooseohyeon 1343dcc
docs: 찜 버튼 FavoriteButton 스토리 추가
yooseohyeon 58ff8d6
feat: 공통 FavoriteButton의 aria-label 개선
yooseohyeon cceb770
fix: 계정 전환 시 찜 요청을 세션별로 격리하도록 수정
yooseohyeon c342f3b
fix: 찜 토글 onMutate 순서 보장 및 401 처리 제거
yooseohyeon bf9118a
test: 찜 버튼 FavoriteButton play 함수 내 접근성 이름 쿼리 수정
yooseohyeon 94b9e7b
fix: authScope 기준으로 찜 캐시 키 일관성 수정
yooseohyeon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,96 @@ | ||
| "use client"; | ||
|
|
||
| import type { MouseEvent } from "react"; | ||
|
|
||
| import { Text, type ResponsiveTextVariant, type TextVariant } from "@/components/common/Text"; | ||
| import { LikeIcon } from "@/icons"; | ||
| import { cn } from "@/lib/utils/cn"; | ||
|
|
||
| interface FavoriteButtonProps { | ||
| moverName: string; | ||
| isFavorite: boolean; | ||
| favoriteCount?: number; | ||
| showCount?: boolean; | ||
| interactive?: boolean; | ||
| countPosition?: "before" | "after"; | ||
| countVariant?: TextVariant | ResponsiveTextVariant; | ||
| className?: string; | ||
| iconClassName?: string; | ||
| countClassName?: string; | ||
| onToggle?: (nextIsFavorite: boolean) => void; | ||
| } | ||
|
|
||
| /** 기사님 찜 하트·개수 표시와 토글 접근성을 통일하는 공통 버튼 */ | ||
| export function FavoriteButton({ | ||
| moverName, | ||
| isFavorite, | ||
| favoriteCount, | ||
| showCount = false, | ||
| interactive = true, | ||
| countPosition = "after", | ||
| countVariant = "md-regular", | ||
| className, | ||
| iconClassName = "size-24", | ||
| countClassName, | ||
| onToggle, | ||
| }: FavoriteButtonProps) { | ||
| const icon = ( | ||
| <LikeIcon | ||
| isFavorite={isFavorite} | ||
| className={cn( | ||
| iconClassName, | ||
| isFavorite ? "text-like-active-fill" : "text-like-default-stroke", | ||
| )} | ||
| /> | ||
| ); | ||
| const count = | ||
| showCount && favoriteCount !== undefined ? ( | ||
| <Text | ||
| as="span" | ||
| variant={countVariant} | ||
| className={cn("text-text-muted", countClassName)} | ||
| aria-hidden="true" | ||
| > | ||
| {favoriteCount} | ||
| </Text> | ||
| ) : null; | ||
| const content = ( | ||
| <> | ||
| {countPosition === "before" ? count : icon} | ||
| {countPosition === "before" ? icon : count} | ||
| </> | ||
| ); | ||
|
|
||
| if (!interactive || !onToggle) { | ||
| return ( | ||
| <div | ||
| className={cn("flex shrink-0 items-center", className)} | ||
| role="group" | ||
| aria-label={`${moverName} 기사님 현재 찜 ${favoriteCount ?? 0}개`} | ||
| > | ||
| {content} | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const handleClick = (event: MouseEvent<HTMLButtonElement>) => { | ||
| event.preventDefault(); | ||
| event.stopPropagation(); | ||
| onToggle(!isFavorite); | ||
| }; | ||
|
|
||
| return ( | ||
| <button | ||
| type="button" | ||
| className={cn( | ||
| "focus-visible:ring-border-brand rounded-8 flex shrink-0 cursor-pointer items-center focus-visible:ring-2 focus-visible:outline-none", | ||
| className, | ||
| )} | ||
| aria-label={`${moverName} 기사님 찜`} | ||
| aria-pressed={isFavorite} | ||
| onClick={handleClick} | ||
| > | ||
| {content} | ||
| </button> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.