8000 Feature: History API를 활용하여 Shallow Routing by guesung · Pull Request #146 · guesung/Web-Memo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Feature: History API를 활용하여 Shallow Routing #146

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 7 commits into from
Jan 23, 2025

Conversation

guesung
Copy link
Owner
@guesung guesung commented Jan 23, 2025

Summary by CodeRabbit

  • 새로운 기능

    • 메모 대화 상자에 애니메이션 전환 효과 추가
    • 메모 대화 상자의 동적 상태 관리 개선
  • 버그 수정

    • 날짜 표시 방식 변경 (상대 시간 제거)
    • URL 상태 관리 로직 최적화
  • 문서화

    • 번역 문자열 업데이트 (마지막 업데이트 시간 표현 변경)

Copy link
coderabbitai bot commented Jan 23, 2025

Warning

Rate limit exceeded

@guesung has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 11 minutes and 8 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between a224c0f and c81795a.

📒 Files selected for processing (1)
  • packages/web/src/app/_components/InitDayjs.tsx (1 hunks)

워크스루

이 풀 리퀘스트는 메모 애플리케이션의 날짜 및 시간 처리 방식을 변경합니다. Day.js 라이브러리의 상대 시간 플러그인을 제거하고, 메모 대화 상자의 상호작용 방식을 개선했습니다. 새로운 컴포넌트 InitDayjs를 도입하여 언어별 Day.js 초기화를 관리하고, 메모 대화 상자의 상태 관리 방식을 리팩토링했습니다.

변경 사항

파일 변경 요약
packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx Day.js 상대 시간 플러그인 제거
packages/web/src/app/[lng]/(auth)/memos/_components/MemoDialog/index.tsx Framer Motion 애니메이션 추가, 대화 상자 상태 관리 개선
packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoGrid.tsx 대화 상자 상태 관리를 위한 새로운 상태 및 훅 추가
packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoItem.tsx 대화 상자 ID 설정 로직 변경
packages/web/src/app/[lng]/layout.tsx InitDayjs 컴포넌트 통합
packages/web/src/app/_components/InitDayjs.tsx 새로운 Day.js 초기화 컴포넌트 생성
packages/web/src/modules/i18n/locales/en/translation.json "Last updated" 번역 문구 수정
packages/web/src/modules/i18n/locales/ko/translation.json "업데이트" 번역 문구 수정

관련 가능성 있는 PR

시퀀스 다이어그램

sequenceDiagram
    participant User
    participant MemoGrid
    participant MemoItem
    participant MemoDialog
    participant InitDayjs

    User->>MemoGrid: 메모 항목 클릭
    MemoGrid->>MemoItem: 대화 상자 ID 설정
    MemoItem->>MemoDialog: 메모 ID 전달
    MemoDialog->>InitDayjs: 언어 설정
    InitDayjs-->>MemoDialog: Day.js 초기화
    MemoDialog->>User: 애니메이션된 대화 상자 표시
Loading

토끼의 시 🐰

데이지와 함께 춤추는 시간
상대 시간은 이제 안녕
새로운 대화 상자가 펼쳐지네
애니메이션의 마법 속에서
코드는 계속 흐르고 있어요 🌈


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ 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.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (und 8000 er 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. (Beta)
  • @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
@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: 3

🔭 Outside diff range comments (1)
packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx (1)

시간 표시 형식 불일치 확인됨

현재 구현된 dayjs(memo.created_at).fromNow() 방식은 번역 파일의 형식과 일치하지 않습니다. 번역 파일에서는 {{time}} 플레이스홀더를 사용하는 단순 시간 형식을 기대하고 있습니다.

  • packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx: fromNow() 사용을 번역 파일과 일치하도록 수정이 필요합니다.
🔗 Analysis chain

Line range hint 95-101: 시간 표시 형식을 재검토해 주세요.

translation 파일에서 "ago" 관련 문구가 제거되었다고 하는데, 여기서는 여전히 fromNow()를 사용하고 있습니다. 번역과 실제 구현이 일치하도록 수정이 필요합니다.

다음 스크립트로 번역 파일의 변경사항을 확인해 보겠습니다:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check translation files for lastUpdated key changes
rg -A 1 '"lastUpdated"' packages/web/src/modules/i18n/locales/

Length of output: 387


Script:

#!/bin/bash
# Check the implementation of time formatting in MemoCardFooter
ast-grep --pattern 'time dateTime={$_} className={$_}' packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx
rg -B 5 -A 5 'fromNow\(\)' packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx

Length of output: 314


Script:

#!/bin/bash
# Check the complete implementation of MemoCardFooter
cat packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx

# Search for dayjs usage
rg "dayjs|fromNow" packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx

Length of output: 263


Script:

#!/bin/bash
# Find the correct path first
fd -t f "index.tsx" -e tsx | grep "MemoCardFooter"

# Then use the path with proper quoting
fd -t f "index.tsx" -e tsx | grep "MemoCardFooter" | xargs cat

# Search for dayjs usage in the found file
fd -t f "index.tsx" -e tsx | grep "MemoCardFooter" | xargs rg "dayjs|fromNow"

Length of output: 3877

🧹 Nitpick comments (4)
packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoItem.tsx (2)

41-44: History API 구현이 적절합니다만, 타입 안전성 개선이 필요합니다.

History state 타입이 명시적으로 정의되어 있지 않아 타입 안전성이 보장되지 않습니다.

다음과 같이 타입을 명시적으로 정의하는 것을 추천드립니다:

interface MemoHistoryState {
  openedMemoId: number;
}

// 사용시:
history.pushState<MemoHistoryState>(
  { openedMemoId: Number(id) },
  '',
  searchParams.getUrl()
);

Line range hint 67-76: 메모이제이션 최적화 개선 필요

현재 메모이제이션 비교 로직이 불필요하게 제한적입니다. isHovered나 lng과 같은 props도 비교에 포함되어야 합니다.

다음과 같이 모든 관련 props를 비교하는 것을 추천드립니다:

(prevProps, nextProps) => {
  return (
    prevProps.memo.id === nextProps.memo.id &&
    prevProps.isSelected === nextProps.isSelected &&
    prevProps.memo.memo === nextProps.memo.memo &&
    prevProps.memo.category === nextProps.memo.category &&
    prevProps.lng === nextProps.lng &&
    prevProps.isSelecting === nextProps.isSelecting
  );
}
packages/web/src/app/[lng]/(auth)/memos/_components/MemoDialog/index.tsx (1)

72-75: History API를 활용한 Shallow Routing이 잘 구현되었습니다.

router.replace 대신 history.pushState를 사용하여 브라우저 히스토리를 관리하는 방식이 적절합니다. 다만, 타입 안정성을 위해 state 객체의 타입을 명시하는 것이 좋을 것 같습니다.

-    history.pushState({ openedMemoId: null }, '', searchParams.getUrl());
+    interface HistoryState {
+      openedMemoId: number | null;
+    }
+    history.pushState<HistoryState>({ openedMemoId: null }, '', searchParams.getUrl());
packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx (1)

Line range hint 3-14: import 구문 정렬이 필요합니다.

ESLint 규칙에 따라 import 구문을 정렬해 주세요.

'use client';

+ import { MouseEvent, PropsWithChildren } from 'react';
+ import dayjs from 'dayjs';
+ import { HeartIcon } from 'lucide-react';
+ import { useRouter } from 'next/navigation';
+
+ import { useMemoPatchMutation } from '@extension/shared/hooks';
+ import { useSearchParams } from '@extension/shared/modules/search-params';
+ import { GetMemoResponse } from '@extension/shared/types';
+ import { cn } from '@extension/shared/utils';
+ import { Badge, Button, CardFooter, toast, ToastAction } from '@src/components/ui';
+ import { LanguageType } from '@src/modules/i18n';
+ import useTranslation from '@src/modules/i18n/client';
- import { useMemoPatchMutation } from '@extension/shared/hooks';
- import { useSearchParams } from '@extension/shared/modules/sear
8000
ch-params';
- import { GetMemoResponse } from '@extension/shared/types';
- import { cn } from '@extension/shared/utils';
- import { Badge, Button, CardFooter, toast, ToastAction } from '@src/components/ui';
- import { LanguageType } from '@src/modules/i18n';
- import useTranslation from '@src/modules/i18n/client';
- import { HeartIcon } from 'lucide-react';
- import { useRouter } from 'next/navigation';
- import { MouseEvent, PropsWithChildren } from 'react';
- import MemoOption from './MemoOption';
- import dayjs from 'dayjs';
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5c550fd and a224c0f.

📒 Files selected for processing (9)
  • packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx (1 hunks)
  • packages/web/src/app/[lng]/(auth)/memos/_components/MemoDialog/index.tsx (4 hunks)
  • packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoGrid.tsx (4 hunks)
  • packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoItem.tsx (2 hunks)
  • packages/web/src/app/[lng]/layout.tsx (2 hunks)
  • packages/web/src/app/_components/InitDayjs.tsx (1 hunks)
  • packages/web/src/app/_components/index.ts (1 hunks)
  • packages/web/src/modules/i18n/locales/en/translation.json (1 hunks)
  • packages/web/src/modules/i18n/locales/ko/translation.json (1 hunks)
🧰 Additional context used
🪛 eslint
packages/web/src/app/_components/index.ts

[error] 1-4: Run autofix to sort these exports!

(simple-import-sort/exports)

packages/web/src/app/_components/InitDayjs.tsx

[error] 3-9: Run autofix to sort these imports!

(simple-import-sort/imports)

packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx

[error] 3-14: Run autofix to sort these imports!

(simple-import-sort/imports)

packages/web/src/app/[lng]/layout.tsx

[error] 1-6: Run autofix to sort these imports!

(simple-import-sort/imports)

packages/web/src/app/[lng]/(auth)/memos/_components/MemoDialog/index.tsx

[error] 10-10: 'AnimatePresence' is defined but never used.

(@typescript-eslint/no-unused-vars)

🔇 Additional comments (10)
packages/web/src/app/_components/index.ts (1)

4-4: InitDayjs 컴포넌트 내보내기가 추가되었습니다.

컴포넌트 내보내기가 올바르게 구현되었습니다.

🧰 Tools
🪛 eslint

[error] 1-4: Run autofix to sort these exports!

(simple-import-sort/exports)

packages/web/src/app/[lng]/layout.tsx (1)

25-26: InitDayjs 컴포넌트 배치가 적절합니다.

모든 프로바이더 이후에 InitDayjs 컴포넌트를 배치한 것이 올바른 구현입니다.

packages/web/src/app/[lng]/(auth)/memos/_components/MemoDialog/index.tsx (2)

18-21: 인터페이스가 적절하게 정의되었습니다.

다이얼로그 상태 관리를 위한 props가 명확하게 정의되어 있습니다.


97-134: 애니메이션이 적절하게 구현되었습니다.

Framer Motion을 사용한 레이아웃 애니메이션이 잘 구현되어 있습니다. 각 섹션별로 layoutId를 부여하여 부드러운 전환 효과를 제공합니다.

packages/web/src/app/[lng]/(auth)/memos/_components/MemoView/MemoGrid.tsx (3)

176-181: 초기 다이얼로그 상태 설정이 적절합니다.

URL 파라미터를 통한 초기 상태 설정이 잘 구현되어 있습니다.


183-192: 브라우저 히스토리 관리가 잘 구현되었습니다.

popstate 이벤트 리스너를 통한 브라우저 히스토리 관리가 적절하게 구현되어 있습니다. 컴포넌트 언마운트 시 이벤트 리스너를 정리하는 것도 잘 처리되어 있습니다.


253-253: 상태 관리 및 다이얼로그 렌더링이 적절합니다.

setDialogMemoId를 props로 전달하고 조건부 렌더링을 통해 다이얼로그를 표시하는 방식이 잘 구현되어 있습니다.

Also applies to: 259-259

packages/web/src/modules/i18n/locales/ko/translation.json (1)

24-24: 번역이 적절하게 수정되었습니다.

시간 표시 형식이 단순화되어 더 명확해졌습니다.

packages/web/src/modules/i18n/locales/en/translation.json (1)

24-24: 상대적 시간 표시에서 절대적 시간 표시로의 변경이 적절해 보입니다.

변경된 내용이 명확하고 일관성이 있습니다. 한국어 번역 파일에서도 동일한 변경이 이루어졌는지 확인이 필요합니다.

다음 스크립트를 실행하여 한국어 번역 파일의 일관성을 확인하겠습니다:

✅ Verification successful

번역 일관성이 확인되었습니다.

영문과 한글 번역 모두 절대적 시간 표시 방식으로 적절하게 변경되었으며, 각 언어의 자연스러운 어순을 잘 반영하고 있습니다.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: 한국어 번역 파일에서 lastUpdated 키의 값을 확인합니다.

rg -U --json "lastUpdated" packages/web/src/modules/i18n/locales/ko/translation.json | jq -r '.data.lines.text'

Length of output: 160

packages/web/src/app/[lng]/(auth)/memos/_components/MemoCardFooter/index.tsx (1)

Line range hint 31-36: 라우팅 구현이 잘 되었습니다.

History API를 활용한 Shallow Routing이 적절하게 구현되었습니다. scroll: false 옵션을 통해 불필요한 스크롤 동작을 방지한 것이 좋습니다.

Copy link

@guesung guesung merged commit 0e3eb9e into develop Jan 23, 2025
9 checks passed
@guesung guesung deleted the feature/control-modal-with-history branch January 23, 2025 04:49
@coderabbitai coderabbitai bot mentioned this pull request Jan 31, 2025
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