-
Notifications
You must be signed in to change notification settings - Fork 0
feat: 결과 페이지 맛집 더 보기 기능 추가 및 레이아웃 개선 #127
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 all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
7e29657
feat(api): add reroll recommend result API
youngminss 65b63d9
feat(hooks): add useRerollRecommendResult and useRerollRestaurants hooks
youngminss 5bd8ab3
feat(result-page): add restaurant reroll feature and improve layout
youngminss b2a036a
fix(result-page): inject rankType prop to OtherCandidateCard for accu…
youngminss 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
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 |
|---|---|---|
| @@ -1,2 +1,3 @@ | ||
| export { useGetRecommendResult } from "./useGetRecommendResult"; | ||
| export { usePostProceedRecommendResult } from "./usePostProceedRecommendResult"; | ||
| export { useRerollRecommendResult } from "./useRerollRecommendResult"; |
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,9 @@ | ||
| "use client"; | ||
|
|
||
| import { useMutation } from "@tanstack/react-query"; | ||
|
|
||
| import { recommendResultMutationOptions } from "#/apis/recommendResult"; | ||
|
|
||
| export const useRerollRecommendResult = (accessKey: string) => { | ||
| return useMutation(recommendResultMutationOptions.reroll(accessKey)); | ||
| }; |
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,59 @@ | ||
| "use client"; | ||
|
|
||
| import { useMutationState } from "@tanstack/react-query"; | ||
| import { useCallback, useMemo } from "react"; | ||
|
|
||
| import { recommendResultMutationKeys } from "#/apis/recommendResult"; | ||
| import type { RerollRecommendResultResponse } from "#/apis/recommendResult"; | ||
| import { useRerollRecommendResult } from "#/hooks/apis/recommendResult"; | ||
| import type { Restaurant } from "#/types/gathering"; | ||
| import type { ApiResponse } from "#/utils/api/types"; | ||
|
|
||
| interface UseRerollRestaurantsProps { | ||
| accessKey: string; | ||
| initialList: Restaurant[]; | ||
| maxRerollCount: number; | ||
| } | ||
|
|
||
| export const useRerollRestaurants = ({ | ||
| accessKey, | ||
| initialList, | ||
| maxRerollCount, | ||
| }: UseRerollRestaurantsProps) => { | ||
| const { mutate, isPending } = useRerollRecommendResult(accessKey); | ||
|
|
||
| // 성공한 reroll 결과 이력을 TanStack Query 캐시에서 직접 읽음 | ||
| // → isMaxReached 가 isPending 과 동일 렌더 사이클에서 업데이트되어 race condition 없음 | ||
| const successfulRerolls = useMutationState({ | ||
| filters: { | ||
| mutationKey: recommendResultMutationKeys.reroll(accessKey), | ||
| status: "success", | ||
| }, | ||
| select: (mutation) => | ||
| mutation.state.data as ApiResponse<RerollRecommendResultResponse>, | ||
| }); | ||
|
|
||
| const isMaxReached = successfulRerolls.length >= maxRerollCount; | ||
|
|
||
| const displayList = useMemo( | ||
| () => [ | ||
| ...initialList, | ||
| ...successfulRerolls.flatMap((result) => result.data.list), | ||
| ], | ||
| [initialList, successfulRerolls], | ||
| ); | ||
|
|
||
| const handleReroll = useCallback(() => { | ||
| if (isMaxReached || isPending) return; | ||
|
|
||
| const excludedIds = displayList.map((r) => r.restaurantId); | ||
| mutate({ accessKey, restaurantIds: excludedIds }); | ||
| }, [accessKey, displayList, isMaxReached, isPending, mutate]); | ||
|
|
||
| return { | ||
| displayList, | ||
| isMaxReached, | ||
| isPending, | ||
| handleReroll, | ||
| }; | ||
| }; |
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
41 changes: 41 additions & 0 deletions
41
...ts/gathering/opinion/result/recommendedRestaurantSection/RecommendedRestaurantSection.tsx
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,41 @@ | ||
| "use client"; | ||
|
|
||
| import { useRerollRestaurants } from "#/hooks/gathering"; | ||
| import type { Restaurant } from "#/types/gathering"; | ||
|
|
||
| import { RerollButton } from "./RerollButton"; | ||
| import { RestaurantList } from "./RestaurantList"; | ||
|
|
||
| interface RecommendedRestaurantSectionProps { | ||
| accessKey: string; | ||
| initialList: Restaurant[]; | ||
| } | ||
|
|
||
| export const RecommendedRestaurantSection = ({ | ||
| accessKey, | ||
| initialList, | ||
| }: RecommendedRestaurantSectionProps) => { | ||
| const { displayList, isPending, isMaxReached, handleReroll } = | ||
| useRerollRestaurants({ accessKey, initialList, maxRerollCount: 2 }); | ||
|
|
||
| return ( | ||
| <section className="ygi:flex ygi:flex-col ygi:gap-3"> | ||
| <h2 className="ygi:heading-22-bd ygi:text-text-primary"> | ||
| 약속 장소는 여기 어때요? | ||
| </h2> | ||
|
|
||
| <div className="ygi:space-y-4 ygi:rounded-md ygi:bg-surface-white ygi:p-4"> | ||
| <p className="ygi:body-16-bd ygi:text-text-primary"> | ||
| 요기잇 추천 맛집 | ||
| </p> | ||
| <RestaurantList restaurants={displayList} /> | ||
| </div> | ||
|
|
||
| <RerollButton | ||
| isMaxReached={isMaxReached} | ||
| isPending={isPending} | ||
| onReroll={handleReroll} | ||
| /> | ||
| </section> | ||
| ); | ||
| }; | ||
33 changes: 33 additions & 0 deletions
33
src/pageComponents/gathering/opinion/result/recommendedRestaurantSection/RerollButton.tsx
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,33 @@ | ||
| "use client"; | ||
|
|
||
| import { Button } from "#/components/button"; | ||
| import { Spinner } from "#/components/spinner"; | ||
|
|
||
| interface RerollButtonProps { | ||
| isMaxReached: boolean; | ||
| isPending: boolean; | ||
| onReroll: () => void; | ||
| } | ||
|
|
||
| export const RerollButton = ({ | ||
| isMaxReached, | ||
| isPending, | ||
| onReroll, | ||
| }: RerollButtonProps) => { | ||
| return ( | ||
| <Button | ||
| variant={isMaxReached ? "tertiary" : "secondary"} | ||
| width="full" | ||
| disabled={isMaxReached || isPending} | ||
| onClick={onReroll} | ||
| > | ||
| {isPending ? ( | ||
| <Spinner size="small" /> | ||
| ) : isMaxReached ? ( | ||
| "맛집 더 보기 횟수를 모두 사용했어요" | ||
| ) : ( | ||
| "다른 맛집 더 보기" | ||
| )} | ||
| </Button> | ||
| ); | ||
| }; |
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxRerollCount값으로 하드코딩된 숫자2를 사용하고 있습니다. 이 값을MAX_REROLL_COUNT와 같은 이름의 상수로 정의하여 사용하면 코드의 가독성과 유지보수성을 높일 수 있습니다. 관련 상수를 모아두는 파일(예:#/constants/gathering.ts)에 정의하는 것을 권장합니다.References