Skip to content

[feature] 카테고리 선택 상태 Context 전역 관리로 변경 및 페이지 이동 시 상태 유지#512

Merged
seongwon030 merged 11 commits intodevelop-fefrom
feature/#511-category-context-global-state-MOA-41
Jul 9, 2025
Merged

[feature] 카테고리 선택 상태 Context 전역 관리로 변경 및 페이지 이동 시 상태 유지#512
seongwon030 merged 11 commits intodevelop-fefrom
feature/#511-category-context-global-state-MOA-41

Conversation

@seongwon030
Copy link
Member

@seongwon030 seongwon030 commented Jun 10, 2025

#️⃣연관된 이슈

ex) #511

📝작업 내용

ContextAPI로 카테고리 상태 관리하기

  • 카테고리 상태를 전역으로 관리할 수 있는CategoryContext.tsx 컨텍스트 제작 79a5637
  • MainPage.tsx의 카테고리 로컬 상태를 useCategory() 로 대체하여 전역 상태로 변경 65a5cff
  • App.tsx에 CategoryProvider 추가 9c5d471
  • CategoryButtonList.tsx에서 카테고리 버튼 클릭시 전역으로 전달 58d9e8f
  • prop 전달 제거 65db40c

7.6 추가 변경

  • 창닫거나 언마운트 시 localstorage 데이터 제거

관리자 페이지에서도 상태 유지하기

  • localStorage에 카테고리명 저장
  • 저장된 게 있으면 가져오고, 아니면 'all'로 유지 cfaf4a5

동작 화면

2025-06-10.16.17.02.mov

중점적으로 리뷰받고 싶은 부분(선택)

리뷰어가 특별히 봐주었으면 하는 부분이 있다면 작성해주세요

ex) 메서드 XXX의 이름을 더 잘 짓고 싶은데 혹시 좋은 명칭이 있을까요?

논의하고 싶은 부분(선택)

논의하고 싶은 부분이 있다면 작성해주세요.

🫡 참고사항

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features
    • 카테고리 선택 상태를 전역적으로 관리할 수 있는 카테고리 컨텍스트가 추가되었습니다.
  • Refactor
    • 메인 페이지와 카테고리 버튼 리스트에서 카테고리 상태 관리를 컨텍스트 기반으로 변경하여, 여러 컴포넌트에서 카테고리 선택 정보를 공유할 수 있도록 개선되었습니다.
    • 전체 라우팅 구조가 카테고리 컨텍스트 프로바이더로 감싸져, 모든 라우트와 컴포넌트에서 카테고리 상태에 접근 가능해졌습니다.

- 카테고리 선택 상태(selectedCategory)를 Context로 전역 관리하도록 CategoryContext.tsx 구현
- 페이지 이동 시에도 카테고리 선택 상태가 유지되도록 구조 개선
- CategoryButtonList에서 카테고리 선택 시 setSelectedCategory(Context)로 상태 관리
- 페이지 이동 후에도 선택 상태가 유지되도록 구조 개
@seongwon030 seongwon030 requested a review from oesnuj June 10, 2025 07:17
@seongwon030 seongwon030 self-assigned this Jun 10, 2025
@seongwon030 seongwon030 added ✨ Feature 기능 개발 💻 FE Frontend labels Jun 10, 2025
@netlify
Copy link

netlify bot commented Jun 10, 2025

Deploy Preview for moadong ready!

Name Link
🔨 Latest commit 46408b4
🔍 Latest deploy log https://app.netlify.com/projects/moadong/deploys/686ceedfedf8010008414981
😎 Deploy Preview https://deploy-preview-512--moadong.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 38
Accessibility: 89
Best Practices: 92
SEO: 92
PWA: -
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jun 10, 2025

Warning

.coderabbit.yaml has a parsing error

The CodeRabbit configuration file in this repository has a parsing error and default settings were used instead. Please fix the error(s) in the configuration file. You can initialize chat with CodeRabbit to get help with the configuration file.

💥 Parsing errors (1)
Validation error: Invalid regex pattern for base branch. Received: "**" at "reviews.auto_review.base_branches[0]"
⚙️ Configuration instructions
  • 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

"""

Walkthrough

카테고리 선택 상태를 전역적으로 관리하기 위해 새로운 CategoryContextCategoryProvider가 도입되었습니다. 기존에 메인 페이지에서 로컬 상태로 관리하던 카테고리 선택 로직이 컨텍스트 기반으로 변경되었으며, 관련 컴포넌트들이 이 컨텍스트를 사용하도록 수정되었습니다.

Changes

파일/경로 변경 요약
frontend/src/context/CategoryContext.tsx CategoryContextCategoryProvider, useCategory 훅 신규 생성
frontend/src/App.tsx 라우팅 구조를 CategoryProvider로 래핑하도록 수정
frontend/src/pages/MainPage/MainPage.tsx 카테고리 상태를 로컬에서 컨텍스트 기반으로 변경
frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx 컨텍스트의 setSelectedCategory 사용 및 버튼 클릭 로직 수정

Sequence Diagram(s)

sequenceDiagram
    participant App
    participant CategoryProvider
    participant BrowserRouter
    participant MainPage
    participant CategoryButtonList

    App->>CategoryProvider: 전체 라우터 구조 래핑
    CategoryProvider->>BrowserRouter: 자식 컴포넌트로 라우터 전달
    BrowserRouter->>MainPage: 메인 페이지 렌더링
    MainPage->>CategoryContext: useCategory()로 상태 접근
    MainPage->>CategoryButtonList: props 없이 렌더링
    CategoryButtonList->>CategoryContext: useCategory()로 setSelectedCategory 사용
    CategoryButtonList->>CategoryContext: 카테고리 선택 시 setSelectedCategory 호출
Loading

Assessment against linked issues

Objective Addressed Explanation
CategoryContext 제작 (MOA-41)
메인페이지 카테고리 로컬 상태를 전역 Context로 변경 (MOA-41)

Assessment against linked issues: Out-of-scope changes

(해당 변경사항 내에서 범위를 벗어난 변경사항은 발견되지 않았습니다.)
"""


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between efa8a0b and 46408b4.

📒 Files selected for processing (1)
  • frontend/src/context/CategoryContext.tsx (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • frontend/src/context/CategoryContext.tsx
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Cursor BugBot
  • GitHub Check: run
  • GitHub Check: run
✨ Finishing Touches
  • 📝 Generate Docstrings

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 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.

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.

Copy link
Contributor

@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: 1

🔭 Outside diff range comments (1)
frontend/src/pages/MainPage/MainPage.tsx (1)

53-53: 💡 Verification agent

🧩 Analysis chain

CategoryButtonList와의 상태 동기화를 확인하세요.

CategoryButtonList가 이제 useCategory 훅을 직접 사용하고 있는데, 여기서 setSelectedCategoryonCategorySelect prop으로 전달하는 것이 중복될 수 있습니다.

다음 스크립트로 CategoryButtonList에서 상태 업데이트가 중복되고 있는지 확인해보세요:


🏁 Script executed:

#!/bin/bash
# CategoryButtonList에서 setSelectedCategory가 두 번 호출되는지 확인
rg -A 10 -B 5 "setSelectedCategory.*onCategorySelect" --type tsx

Length of output: 94


CategoryButtonList 컴포넌트에서 훅과 prop 호출을 함께 사용하고 있는지 확인하기 위해, 아래 스크립트를 실행해 주세요.


🏁 Script executed:

#!/bin/bash
# 1) CategoryButtonList 컴포넌트 파일 위치 찾기
COMPONENT_FILE=$(rg -l "CategoryButtonList" --glob "*.tsx" | head -n1)

# 2) useCategory 훅 사용 부분 확인
echo "— useCategory 훅 사용 위치 —"
rg -A5 -B5 "useCategory" "$COMPONENT_FILE"

# 3) onCategorySelect prop 사용 부분 확인
echo "— onCategorySelect prop 사용 위치 —"
rg -A5 -B5 "onCategorySelect" "$COMPONENT_FILE"

Length of output: 1639


CategoryButtonList 컴포넌트 내부에서 useCategory 훅과 onCategorySelect prop이 모두 사용되는지 확인하기 위해 아래 스크립트를 실행해 주세요.


🏁 Script executed:

#!/bin/bash
# 1) CategoryButtonList 컴포넌트 파일 위치 찾기
COMPONENT_FILE=$(rg -l "CategoryButtonList" --glob "*CategoryButtonList.tsx" | head -n1)
echo "Found: $COMPONENT_FILE"

# 2) 컴포넌트 선언부 및 props 확인
echo "---- Component Signature ----"
rg -A5 -B0 "CategoryButtonList" "$COMPONENT_FILE" | head -n20

# 3) useCategory 훅 사용 위치 확인
echo "---- useCategory Hook Usage ----"
rg -A5 -B5 "useCategory" "$COMPONENT_FILE"

# 4) onCategorySelect prop 처리 위치 확인
echo "---- onCategorySelect Prop Handling ----"
rg -A5 -B5 "onCategorySelect" "$COMPONENT_FILE"

Length of output: 3712


중복된 카테고리 상태 업데이트 제거

CategoryButtonList 컴포넌트에서 useCategory 훅의 setSelectedCategory와 부모로부터 전달받은 onCategorySelect(같은 함수)가 모두 호출되어 동일한 상태 업데이트가 두 번 발생합니다. 하나의 방식만 사용하도록 수정하세요.

  • frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx

    • handleCategoryClick 내부에서
      setSelectedCategory(category.id);
      onCategorySelect(category.id);
      두 호출이 중복됨
  • frontend/src/pages/MainPage/MainPage.tsx

    • <CategoryButtonList onCategorySelect={setSelectedCategory} /> 부분

제거할 코드 예시:

--- a/frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx
@@ const handleCategoryClick = (category: Category) => {
-    setSelectedCategory(category.id);
     onCategorySelect(category.id);

또는

--- a/frontend/src/pages/MainPage/MainPage.tsx
-  <CategoryButtonList onCategorySelect={setSelectedCategory} />
+  <CategoryButtonList />

훅 사용 또는 prop 전달 중 하나만 남겨 중복 호출을 제거해 주세요.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 551fe47 and cc52713.

📒 Files selected for processing (4)
  • frontend/src/App.tsx (2 hunks)
  • frontend/src/context/CategoryContext.tsx (1 hunks)
  • frontend/src/pages/MainPage/MainPage.tsx (2 hunks)
  • frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx (4 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (3)
frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx (1)
frontend/src/context/CategoryContext.tsx (1)
  • useCategory (11-11)
frontend/src/pages/MainPage/MainPage.tsx (1)
frontend/src/context/CategoryContext.tsx (1)
  • useCategory (11-11)
frontend/src/App.tsx (2)
frontend/src/context/CategoryContext.tsx (1)
  • CategoryProvider (13-24)
frontend/src/context/AdminClubContext.tsx (1)
  • AdminClubProvider (12-24)
🔇 Additional comments (7)
frontend/src/context/CategoryContext.tsx (1)

1-24: 전역 카테고리 상태 관리 구현이 올바릅니다.

React Context 패턴을 정확히 따르고 있으며, TypeScript 타입 정의와 기본값 설정이 적절합니다. useCategory 훅을 통한 편리한 접근 방식도 좋습니다.

frontend/src/pages/MainPage/MainPage.tsx (2)

3-3: Context 훅 import가 올바릅니다.

전역 카테고리 상태 관리를 위한 useCategory 훅 import가 적절합니다.


22-22: 로컬 상태에서 전역 상태로의 전환이 올바릅니다.

useState 대신 useCategory 훅을 사용하여 전역 상태를 관리하도록 변경된 것이 적절합니다.

frontend/src/App.tsx (2)

5-5: CategoryProvider import가 올바릅니다.

전역 카테고리 상태를 제공하기 위한 provider import가 적절합니다.


28-95: Provider 래핑이 올바르게 구현되었습니다.

CategoryProvider로 라우터를 감싸서 모든 하위 컴포넌트에서 카테고리 상태에 접근할 수 있도록 한 것이 적절합니다. Provider들의 중첩 순서도 올바릅니다.

frontend/src/pages/MainPage/components/CategoryButtonList/CategoryButtonList.tsx (2)

11-11: Context 훅 import가 올바릅니다.

전역 카테고리 상태 접근을 위한 useCategory 훅 import가 적절합니다.


66-66: 전역 상태 접근이 올바릅니다.

useCategory 훅을 통해 setSelectedCategory 함수에 접근하는 것이 적절합니다.

- useCategory 훅에서 CategoryContext가 undefined일 경우 에러를 던지도록 처리
- Provider로 감싸지 않은 경우 실수를 빠르게 인지할 수 있도록 안전성 강화
- 카테고리 선택 시 localStorage에 값 저장
- 페이지 이동, 새로고침, 다른 탭에서도 선택 상태가 유지되도록 useEffect 및 storage 이벤트 핸들러 추가
Copy link
Member

@oesnuj oesnuj left a comment

Choose a reason for hiding this comment

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

다소 불편했던 부분이었는데, 전역 상태로 해결한 점 좋았습니다.
수고 많으셨습니다!

- 카테고리 선택값을 sessionStorage에 저장하도록 수정
- 창/탭을 닫으면 값이 자동으로 삭제되어 더 일시적인 상태 관리 가능
cursor[bot]

This comment was marked as outdated.

@seongwon030 seongwon030 merged commit 20b400e into develop-fe Jul 9, 2025
8 checks passed
@seongwon030 seongwon030 deleted the feature/#511-category-context-global-state-MOA-41 branch July 9, 2025 02:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

💻 FE Frontend ✨ Feature 기능 개발

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[feature] MOA-41 카테고리 선택 상태 Context 전역 관리로 변경 및 페이지 이동 시 상태 유지

2 participants

Comments