Skip to content

Conversation

@BokyungCodes
Copy link
Contributor

@BokyungCodes BokyungCodes commented Aug 2, 2025

📌 변경 사항 개요

삭제한 체험이 메인 페이지의 모든 체험 및 인기 체험 목록에서 반영되도록 함

📝 상세 내용

  • 메인페이지에 삭제 로직 반영
  • Tanstack Query 도입

🔗 관련 이슈

🖼️ 스크린샷(선택사항)

💡 참고 사항

Summary by CodeRabbit

  • 리팩터링

    • 인기 체험 및 체험 목록 컴포넌트가 React Query를 활용한 데이터 관리로 전환되어, 더 안정적인 로딩 및 에러 처리 UI를 제공합니다.
  • 버그 수정

    • 활동 삭제 시 관련된 여러 데이터(체험, 인기 체험) 캐시가 함께 갱신되어 최신 정보가 반영됩니다.
  • 기타

    • API 응답 타입이 명확하게 정의되어 데이터 구조가 일관적으로 관리됩니다.
    • 인기 체험 조회 시 페이지 크기가 12개로 증가하고, 페이징 방식이 변경되었습니다.

@BokyungCodes BokyungCodes linked an issue Aug 2, 2025 that may be closed by this pull request
2 tasks
@BokyungCodes BokyungCodes self-assigned this Aug 2, 2025
@coderabbitai
Copy link

coderabbitai bot commented Aug 2, 2025

Walkthrough

이 변경사항은 경험(Experience) 관련 컴포넌트와 API 유틸리티를 TanStack Query(React Query) 기반의 선언적 데이터 패칭 방식으로 리팩터링하고, 관련 타입을 명확히 했습니다. 또한 활동 삭제 시 쿼리 무효화 범위를 확장하고, 일부 인터페이스 및 반환 타입을 개선했습니다.

Changes

Cohort / File(s) Change Summary
ExperienceList 컴포넌트 리팩터링
src/app/(with-header)/components/ExperienceList.tsx
useEffect와 useState를 제거하고 useQuery(TanStack Query)로 데이터 패칭 및 상태관리 전환, 로딩/에러 처리 추가, 타입 import 정리 및 JSX 소폭 수정
PopularExperiences 컴포넌트 리팩터링
src/app/(with-header)/components/PopularExperiences.tsx
useEffect와 useState 기반 데이터 패칭을 useQuery로 대체, API 호출 경로 수정, 로딩/에러 처리 추가, 불필요한 props 및 import 정리, UI 구조는 유지
getExperiences API 타입 명확화
src/app/api/experiences/getExperiences.ts
반환 타입을 명확히 하기 위해 ExperienceListResult 인터페이스 도입 및 함수 시그니처 수정, 서버 응답 타입 주석 보강, 반환 로직 간소화
getPopularExperiences API 인터페이스 및 파라미터 변경
src/app/api/experiences/getPopularExperiences.ts
응답 타입을 PopularExperiencesResponse로 명명 및 속성 단순화, 함수 반환 타입 및 요청 파라미터(페이지네이션 방식, pageSize) 변경
useDeleteActivity 훅 쿼리 무효화 범위 확장
src/app/(with-header)/activities/[id]/hooks/useDeleteActivity.ts
활동 삭제 성공 시 무효화되는 쿼리에 ['experiences'](exact: false), ['popularExperiences'] 추가하여 관련 데이터 캐시 갱신 보장
package.json 줄바꿈 제거
package.json
파일 끝의 불필요한 줄바꿈 문자 삭제(내용 및 구조 변동 없음)

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExperienceList
    participant TanStackQuery
    participant API

    User->>ExperienceList: 페이지 진입/필터 변경
    ExperienceList->>TanStackQuery: useQuery로 experiences 요청
    TanStackQuery->>API: getExperiences 호출
    API-->>TanStackQuery: { experiences, totalCount } 반환
    TanStackQuery-->>ExperienceList: 데이터/로딩/에러 상태 전달
    ExperienceList-->>User: UI 렌더링 (로딩/에러/목록)
Loading
sequenceDiagram
    participant User
    participant PopularExperiences
    participant TanStackQuery
    participant API

    User->>PopularExperiences: 컴포넌트 마운트
    PopularExperiences->>TanStackQuery: useQuery로 popularExperiences 요청
    TanStackQuery->>API: getPopularExperiences 호출
    API-->>TanStackQuery: { activities } 반환
    TanStackQuery-->>PopularExperiences: 데이터/로딩/에러 상태 전달
    PopularExperiences-->>User: UI 렌더링 (로딩/에러/목록)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~15–20 minutes

Possibly related PRs

Suggested labels

🔨 Refactor, 📬 API

Suggested reviewers

  • minimo-9

Poem

🐇
쿼리로 춤추는 경험의 밤,
useEffect는 안녕, useQuery는 반갑다!
캐시 무효화로 데이터 싱싱,
타입 명확해져 마음이 든든~
토끼는 오늘도 코드밭에서
깡총깡총 리팩터링을 노래한다!
🌙✨

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch refactor/92

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@BokyungCodes BokyungCodes added 📬 API 서버 api 통신관련 🔨 Refactor 코드 리팩토링 ✨ Feature 기능구현 labels Aug 2, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🔭 Outside diff range comments (1)
src/app/(with-header)/components/PopularExperiences.tsx (1)

53-65: JSX 구조를 단순화할 수 있습니다.

divLink 컴포넌트가 중복으로 래핑되어 있습니다. 구조를 단순화하여 가독성을 향상시킬 수 있습니다.

- {data.activities.map((exp) => (
-   <div key={exp.id} className='flex-shrink-0 card'>
-     <Link href={`/activities/${exp.id}`} className='flex-shrink-0 card'>
-       <PopularCard
-         imageUrl={exp.bannerImageUrl}
-         price={exp.price}
-         rating={exp.rating}
-         reviews={exp.reviewCount}
-         title={exp.title}
-       />
-     </Link>
-   </div>
- ))}
+ {data.activities.map((exp) => (
+   <Link key={exp.id} href={`/activities/${exp.id}`} className='flex-shrink-0 card'>
+     <PopularCard
+       imageUrl={exp.bannerImageUrl}
+       price={exp.price}
+       rating={exp.rating}
+       reviews={exp.reviewCount}
+       title={exp.title}
+     />
+   </Link>
+ ))}
📜 Review details

Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 86ccfd7 and 9c6c66d.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (6)
  • package.json (1 hunks)
  • src/app/(with-header)/activities/[id]/hooks/useDeleteActivity.ts (1 hunks)
  • src/app/(with-header)/components/ExperienceList.tsx (3 hunks)
  • src/app/(with-header)/components/PopularExperiences.tsx (3 hunks)
  • src/app/api/experiences/getExperiences.ts (2 hunks)
  • src/app/api/experiences/getPopularExperiences.ts (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
src/app/api/experiences/getPopularExperiences.ts (2)
src/types/experienceListTypes.ts (2)
  • Experience (1-14)
  • ExperienceResponse (16-20)
src/apis/instance.ts (1)
  • instance (100-100)
src/app/api/experiences/getExperiences.ts (1)
src/types/experienceListTypes.ts (2)
  • ExperienceResponse (16-20)
  • Experience (1-14)
🔇 Additional comments (13)
package.json (1)

49-49: 사소한 포맷팅 개선입니다.

파일 끝의 개행 문자 제거는 코드 스타일 일관성을 위한 정리 작업입니다.

src/app/api/experiences/getExperiences.ts (2)

11-22: 타입 정의가 명확해졌습니다.

서버 응답과 프론트엔드 사용 타입을 명확히 구분한 것이 좋습니다. 특히 ExperienceListResult 인터페이스로 useQuery의 제네릭 타입을 명시한 점이 훌륭합니다.


28-33: 함수 시그니처 개선이 좋습니다.

매개변수 구조분해와 명시적 반환 타입 선언으로 가독성과 타입 안전성이 향상되었습니다.

src/app/(with-header)/activities/[id]/hooks/useDeleteActivity.ts (1)

18-20: 캐시 무효화 전략이 잘 구현되었습니다.

삭제 후 관련된 모든 쿼리를 무효화하여 메인 페이지의 체험 리스트와 인기 체험 목록에서 삭제가 즉시 반영되도록 한 것이 PR 목표와 정확히 일치합니다. exact: false 옵션으로 다양한 파라미터를 가진 체험 리스트 쿼리들을 모두 무효화하는 것도 적절합니다.

src/app/api/experiences/getPopularExperiences.ts (2)

4-6: 인터페이스 단순화가 적절합니다.

인기 체험 조회에서 불필요한 cursorIdtotalCount 필드를 제거하여 인터페이스를 단순화한 것이 좋습니다.


14-16: cursor 기반 첫 페이지 호출 확인 완료
PopularExperiencesResponse 타입에 별도 cursorIdnextCursor 필드가 없고, 초기 페이지 조회용으로만 설계되어 있으므로 method: 'cursor'size: 12 변경은 서버 API 스펙에 부합하며, cursorId 없이도 정상 동작합니다.

src/app/(with-header)/components/PopularExperiences.tsx (2)

5-7: TanStack Query 도입이 성공적으로 완료되었습니다.

useStateuseEffect 대신 useQuery를 사용하여 선언적 데이터 패칭으로 개선했습니다. 불필요한 imports도 깔끔하게 정리되었습니다.


16-19: 쿼리 설정이 적절합니다.

쿼리 키와 함수 설정이 올바르며, 캐시 무효화 전략과도 일치합니다.

src/app/(with-header)/components/ExperienceList.tsx (5)

3-11: 임포트 구성이 잘 정리되었습니다.

TanStack Query 도입에 따른 임포트 변경사항이 적절하고, 관련 임포트들이 논리적으로 그룹화되어 가독성이 향상되었습니다. ExperienceListResult 타입 임포트로 API 응답의 타입 안정성도 확보되었습니다.


29-40: TanStack Query 구현이 우수합니다.

쿼리 키에 모든 관련 의존성이 포함되어 적절한 캐싱과 리페칭이 보장되며, placeholderData 옵션으로 리페칭 중 UI 깜빡임을 방지한 것이 좋습니다. 타입 명시도 타입 안정성을 확보했습니다.


42-44: 데이터 추출 로직이 안전합니다.

옵셔널 체이닝과 적절한 기본값 설정으로 안전한 데이터 접근이 보장되어, 데이터가 로딩 중이거나 에러 상태일 때도 UI가 안정적으로 동작할 수 있습니다.


90-108: 로딩과 에러 상태 처리가 적절합니다.

로딩, 에러, 성공 상태에 대한 조건부 렌더링이 명확하고, 사용자 친화적인 메시지로 UX가 개선되었습니다. 데이터가 있을 때만 그리드를 렌더링하는 구조도 안전합니다.


24-120: 전체적으로 성공적인 리팩터링입니다.

기존 기능을 모두 유지하면서 TanStack Query를 성공적으로 도입했습니다. 선언적 데이터 관리로 코드가 더 간결해졌고, 쿼리 캐시 무효화를 통한 삭제 로직 반영도 자동으로 처리될 것입니다. PR 목표에 완벽히 부합하는 구현입니다.

Comment on lines +36 to +37
if (isLoading) return <p className="text-center">인기 체험을 불러오는 중입니다...</p>;
if (error || !data) return <p className="text-center text-red-500">데이터를 불러오는 데 실패했어요 😢</p>;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

로딩 및 에러 상태 처리를 개선할 수 있습니다.

현재 로딩 메시지와 에러 메시지가 단순합니다. 사용자 경험 향상을 위해 더 구체적인 피드백을 제공하는 것을 고려해보세요.

- if (isLoading) return <p className="text-center">인기 체험을 불러오는 중입니다...</p>;
- if (error || !data) return <p className="text-center text-red-500">데이터를 불러오는 데 실패했어요 😢</p>;
+ if (isLoading) return (
+   <div className="text-center py-10">
+     <div className="animate-pulse">인기 체험을 불러오는 중입니다...</div>
+   </div>
+ );
+ if (error || !data) return (
+   <div className="text-center py-10 text-red-500">
+     <p>인기 체험을 불러오는 데 실패했습니다.</p>
+     <button onClick={() => window.location.reload()} className="mt-2 text-blue-500 underline">
+       다시 시도
+     </button>
+   </div>
+ );
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if (isLoading) return <p className="text-center">인기 체험을 불러오는 중입니다...</p>;
if (error || !data) return <p className="text-center text-red-500">데이터를 불러오는 데 실패했어요 😢</p>;
if (isLoading) return (
<div className="text-center py-10">
<div className="animate-pulse">인기 체험을 불러오는 중입니다...</div>
</div>
);
if (error || !data) return (
<div className="text-center py-10 text-red-500">
<p>인기 체험을 불러오는 데 실패했습니다.</p>
<button
onClick={() => window.location.reload()}
className="mt-2 text-blue-500 underline"
>
다시 시도
</button>
</div>
);
🤖 Prompt for AI Agents
In src/app/(with-header)/components/PopularExperiences.tsx around lines 36 to
37, improve the loading and error state handling by replacing the simple text
messages with more informative and user-friendly feedback. Enhance the loading
message to indicate what is being loaded specifically and consider adding retry
options or detailed error information in the error message to improve user
experience.

Comment on lines 12 to 16
interface ExperienceResponse {
activities: Experience[];
totalCount: number;
cursorId: number;
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

타입 중복 가능성을 확인해주세요.

src/types/experienceListTypes.ts에 이미 ExperienceResponse 인터페이스가 정의되어 있는 것으로 보입니다. 타입 정의 중복을 피하기 위해 기존 타입을 재사용하거나 통합하는 것을 고려해보세요.

다음 스크립트로 타입 중복을 확인해보겠습니다:


🏁 Script executed:

#!/bin/bash
# 중복된 ExperienceResponse 인터페이스 정의 확인
rg -A 5 "interface ExperienceResponse" --type ts

Length of output: 684


타입 중복 제거: 기존 ExperienceResponse 타입 재사용

src/app/api/experiences/getExperiences.ts(12–16)에서 로컬로 정의된 ExperienceResponse
src/types/experienceListTypes.ts의 동일 인터페이스가 중복되어 있습니다.
기존 타입을 import해서 중복 정의를 제거해주세요.

  • 파일: src/app/api/experiences/getExperiences.ts
  • 위치: 12–16행
--- src/app/api/experiences/getExperiences.ts
@@ 12,16
- interface ExperienceResponse {
-   activities: Experience[];
-   totalCount: number;
-   cursorId: number;
- }
+ import type { ExperienceResponse } from '../../../types/experienceListTypes';
🤖 Prompt for AI Agents
In src/app/api/experiences/getExperiences.ts at lines 12 to 16, the
ExperienceResponse interface is redundantly defined locally while the same
interface exists in src/types/experienceListTypes.ts. Remove the local
ExperienceResponse definition and import the ExperienceResponse type from
src/types/experienceListTypes.ts to eliminate duplication and maintain
consistency.

@LeeCh0129 LeeCh0129 self-requested a review August 2, 2025 09:19
Copy link
Contributor

@minimo-9 minimo-9 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

삭제 로직과 Tanstack Query를 잘 도입하셨네요!

@BokyungCodes BokyungCodes merged commit 9bde4d3 into develop Aug 2, 2025
2 checks passed
@BokyungCodes BokyungCodes deleted the refactor/92 branch August 2, 2025 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

📬 API 서버 api 통신관련 ✨ Feature 기능구현 🔨 Refactor 코드 리팩토링

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[refactor] 메인페이지에 TanStack Query 도입

5 participants