8000 Fix: 카테고리 이슈 by guesung · Pull Request #166 · guesung/Web-Memo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fix: 카테고리 이슈 #166

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 4 commits into from
Apr 13, 2025
Merged

Fix: 카테고리 이슈 #166

merged 4 commits into from
Apr 13, 2025

Conversation

guesung
Copy link
Owner
@guesung guesung commented Apr 13, 2025

Summary by CodeRabbit

  • 새로운 기능

    • 메모 작성 시 특정 문자를 입력하면 카테고리 제안이 활성화되어 보다 직관적인 선택이 가능합니다.
    • 입력 변경 감지 후 자동 저장 기능이 개선되어 데이터 보존이 원활해졌습니다.
  • 리팩토링

    • 메모 작성 이벤트 처리 로직이 정리되어 타이핑 및 편집 경험이 보다 부드럽게 개선되었습니다.

Copy link
coderabbitai bot commented Apr 13, 2025

Walkthrough

이 PR은 MemoForm 컴포넌트의 이벤트 처리 로직을 수정합니다. 기존의 handleMemoTextAreaChange 함수가 제거되고, 대신 키 입력에 반응하는 handleKeyDown과 텍스트 변경을 처리하는 handleMemoChange 함수가 추가되었습니다. handleKeyDown은 '#' 키를 감지하여 기본 동작을 막고 커서 위치에 따라 카테고리 리스트를 표시하며 상태를 업데이트합니다. 또한, handleCategorySelect 함수의 로직이 '#' 문자를 적절히 제거하도록 수정되었습니다.

Changes

파일 경로 변경 요약
pages/.../MemoForm.tsx 기존 handleMemoTextAreaChange 제거, handleKeyDownhandleMemoChange 함수 추가. 텍스트 영역의 키 입력 처리 로직 수정 및 카테고리 선택 시 '#' 문자 제거 방식 변경.

Sequence Diagram(s)

sequenceDiagram
    participant 사용자 as 사용자
    participant 텍스트영역 as Textarea
    participant 폼 as MemoForm
    participant 저장 as DebouncedSave

    사용자->>텍스트영역: keydown 이벤트 (예: '#')
    텍스트영역->>폼: handleKeyDown 호출
    폼-->>텍스트영역: '#' 삽입 및 상태 업데이트

    사용자->>텍스트영역: 텍스트 내용 변경
    텍스트영역->>폼: handleMemoChange 호출
    폼->>저장: 저장 작업 (디바운스)

    사용자->>폼: 카테고리 선택
    폼-->>텍스트영역: handleCategorySelect 호출 (불필요 '#' 제거)
Loading

Poem

나는 작은 토끼, 코드 숲을 달리네 🐇
'#' 키에 반짝임을 담아 터치하네.
변경된 로직, 깔끔하게 뚝딱!
텍스트에 춤추는 변화의 흔적,
바람 따라 즐겁게 뛰노는 내 발걸음!


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55804fb and a92b747.

📒 Files selected for processing (1)
  • pages/side-panel/src/components/MemoForm.tsx (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run end-to-end tests
🔇 Additional comments (7)
pages/side-panel/src/components/MemoForm.tsx (7)

75-75: 커서 위치 추적을 위한 ref 추가

커서 위치를 저장하기 위한 cursorPositionRef를 추가한 것은 좋은 변경입니다. 이를 통해 카테고리 선택 과정에서 사용자의 커서 위치를 기억하고 복원할 수 있어 사용자 경험이 향상됩니다.


113-149: 키보드 이벤트 기반 카테고리 기능 개선

기존 마우스 이벤트 기반의 카테고리 감지에서 키보드 이벤트 기반으로 변경한 것은 좋은 개선입니다. 사용자가 '#' 키를 타이핑할 때만 카테고리 창이 열리므로 사용자 경험이 향상되었습니다.

뷰포트 너비를 고려하여 카테고리 창의 위치를 조정하는 로직(131-133줄)도 매우 효과적입니다. 이를 통해 카테고리 창이 화면 밖으로 벗어나는 문제를 해결했습니다.


151-155: 메모 변경 핸들러 분리

텍스트 변경을 처리하는 handleMemoChange 함수를 별도로 분리한 것은 좋은 리팩토링입니다. 일반 텍스트 변경과 특수 키 감지 로직이 분리되어 코드의 가독성과 유지보수성이 향상되었습니다.


160-164: 카테고리 선택 후 # 문자 처리 개선

카테고리 선택 후 '#' 문자 처리 로직이 개선되었습니다. 마지막 '#' 문자의 정확한 위치를 찾아 제거함으로써, 다른 텍스트에 영향을 주지 않고 해당 문자만 정확히 제거할 수 있게 되었습니다.


167-172: 카테고리 선택 후 포커스 및 커서 위치 복원

카테고리 선택 후 텍스트 영역에 포커스를 다시 맞추고 원래 커서 위치를 복원하는 로직이 추가되었습니다. 이는 사용자 경험을 크게 향상시키는 좋은 개선입니다.


213-214: 이벤트 핸들러 업데이트

새로 분리된 핸들러 함수를 Textarea 컴포넌트의 이벤트에 연결한 것은 적절합니다. onChange에는 handleMemoChange를, onKeyDown에는 handleKeyDown을 사용하여 각 이벤트에 맞는 핸들러가 호출되도록 했습니다.

Also applies to: 220-221


239-244: Escape 키 처리 개선

Escape 키를 눌러 카테고리 선택을 취소할 때도 텍스트 영역에 포커스를 복원하고 원래 커서 위치를 유지하는 로직이 추가되었습니다. 이는 사용자 경험의 일관성을 유지하는 좋은 개선입니다.

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

@guesung guesung force-pushed the fix/fix-the-category-add branch from 55f8159 to 55804fb Compare April 13, 2025 03:19
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: 0

🧹 Nitpick comments (1)
pages/side-panel/src/components/MemoForm.tsx (1)

112-146: 입력 처리 로직이 명확하게 개선되었습니다.

'#' 키 입력 처리를 위한 새로운 handleKeyDown 함수가 잘 구현되었습니다. 이제 사용자가 '#'을 입력할 때 기본 동작을 방지하고, 커서 위치를 계산하여 카테고리 목록을 적절한 위치에 표시합니다. 특히 화면 너비를 고려하여 카테고리 목록이 화면 밖으로 나가지 않도록 처리한 부분이 좋습니다.

// 다음과 같이 뷰포트 너비를 확인하여 목록이 화면을 벗어나지 않도록 처리합니다
+ const viewportWidth = window.innerWidth;
+ const CATEGORY_LIST_WIDTH = 256; // w-64 = 16rem = 256px

+ if (calculatedLeft + CATEGORY_LIST_WIDTH > viewportWidth) {
+   calculatedLeft = 0;
+ }

다만 계산된 위치가 0으로 설정되는 경우, 화면 왼쪽 끝에 붙게 되는데 이는 UX 측면에서 개선할 여지가 있습니다. 사용자 경험을 더 좋게 하려면 화면 오른쪽에서 약간의 여백을 두는 것을 고려해보세요.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 55f8159 and 55804fb.

📒 Files selected for processing (1)
  • pages/side-panel/src/components/MemoForm.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Run end-to-end tests
🔇 Additional comments (4)
pages/side-panel/src/components/MemoForm.tsx (4)

148-152: 텍스트 변경 처리 기능이 분리되어 코드 가독성이 향상되었습니다.

새로 추가된 handleMemoChange 함수는 텍스트 영역의 변경 이벤트를 처리하는 역할을 명확하게 담당하고 있습니다. debounce를 활용하여 불필요한 저장 작업을 최소화한 것도 좋은 접근입니다.

이 분리를 통해 각 이벤트 핸들러가 한 가지 역할만 담당하도록 하여 단일 책임 원칙(SRP)을 잘 따르고 있습니다.


157-164: 카테고리 선택 로직의 버그 수정이 잘 이루어졌습니다.

기존에는 마지막 문자를 무조건 제거했던 방식에서, '#' 문자의 정확한 위치를 찾아 해당 문자만 제거하도록 개선되었습니다. 이는 사용자가 카테고리 선택 시 의도치 않게 다른 문자가 삭제되는 버그를 해결합니다.

- // 이전 코드는 마지막 문자를 무조건 제거했을 것입니다
+ const hashIndex = currentText.lastIndexOf('#');
+ if (hashIndex !== -1) {
+   setValue('memo', currentText.slice(0, hashIndex) + currentText.slice(hashIndex + 1));
+ }

이 방식은 마지막 '#'의 위치를 정확히 찾아 해당 문자만 제거하므로 훨씬 안전합니다.


205-206: 적절한 이벤트 핸들러 연결이 이루어졌습니다.

Textarea의 onChange 이벤트에 새로 구현된 handleMemoChange 함수를 연결하여 텍스트 변경 이벤트를 적절히 처리하고 있습니다.


212-213: 키 입력 처리 핸들러가 적절히 연결되었습니다.

Textarea에 onKeyDown 이벤트 핸들러로 handleKeyDown 함수를 연결하여 '#' 키 입력을 감지하고 처리할 수 있도록 했습니다.

Comment on lines -195 to +212
onChange: handleMemoTextAreaChange,
onChange: handleMemoChange,
})}
{...rest}
ref={e => {
ref(e);
textareaRef.current = e;
}}
>
Copy link
Owner Author

Choose a reason for hiding this comment

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

AS-IS : 마우스 커서가 #를 만나면 계속 카테고리 창이 열린다.
TO-BE : 사용자가 #를 타이핑하면 그 때 카테고리 창이 열린다.

해결 방법 : 기존 mouse이벤트의 change 타입에서 이벤트 감지 -> Keyboard이벤트의 keydown 타입에서 이벤트 감지

Comment on lines 125 to 130
const viewportWidth = window.innerWidth;
const CATEGORY_LIST_WIDTH = 256; // w-64 = 16rem = 256px

if (textareaRef.current) {
textareaRef.current.selectionStart = cursorPosition - 1;
textareaRef.current.selectionEnd = cursorPosition - 1;
if (calculatedLeft + CATEGORY_LIST_WIDTH > viewportWidth) {
calculatedLeft = 0;
}
Copy link
Owner Author

Choose a reason for hiding this comment

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

AS-IS : 마우스 커서가 우측에 있을 때 #를 눌러 카테고리 선택 창을 열 경우, 화면이 잘린다.
TO-BE : 마우스 커서가 우측에 있을 때 #를 눌러 카테고리 선택 창을 열 경우, 카테고리 창이 좌측 상단에서 열린다.
해결 방법 : calculatedLeft + CATEGORY_LIST_WIDTH > viewportWidth 즉 현재 마우스 커서의 X좌표와 카테고리 너비를 합한 X좌표가 뷰포트 너비보다 클 경우, 카테고리 창의 X좌표를 0으로 설정한다.

@guesung guesung merged commit d9e7b63 into develop Apr 13, 2025
7 of 8 checks passed
@guesung guesung deleted the fix/fix-the-category-add branch April 13, 2025 03:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant
0