-
Notifications
You must be signed in to change notification settings - Fork 0
피드 UX 개선 게시글 이동 방식 변경 및 스크롤 위치 복원 #312
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
Open
ho0010
wants to merge
6
commits into
refactor
Choose a base branch
from
fix/feed-ux
base: refactor
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
eb3d942
feat: 피드 게시물 상세 이동 방식 개선 및 스크롤 위치 복원
ho0010 16847e7
Merge branch 'refactor' into fix/feed-ux
ho0010 809b507
refactor(feed): 피드 캐시 로직 훅으로 분리 및 Feed 컴포넌트 코드 정리
ho0010 ba64e33
fix: import 누락
ho0010 d041cca
fix: 활성탭 상태 개선
ho0010 6d67950
fix: 피드 상세 페이지 진입 시 흰 화면 깜빡임 개선
ho0010 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| import { useState, useEffect } from 'react'; | ||
| import type { PostData } from '@/types/post'; | ||
|
|
||
| const FEED_CACHE_KEY = 'feed_page_cache'; | ||
| const FEED_CACHE_TTL = 10 * 60 * 1000; // 10분 | ||
|
|
||
| export interface FeedCache { | ||
| activeTab: string; | ||
| totalFeedPosts: PostData[]; | ||
| myFeedPosts: PostData[]; | ||
| totalNextCursor: string; | ||
| myNextCursor: string; | ||
| totalIsLast: boolean; | ||
| myIsLast: boolean; | ||
| scrollY: number; | ||
| timestamp: number; | ||
| } | ||
|
|
||
| type FeedCachePayload = Omit<FeedCache, 'scrollY' | 'timestamp'>; | ||
|
|
||
| function readCache(): FeedCache | null { | ||
| try { | ||
| const raw = sessionStorage.getItem(FEED_CACHE_KEY); | ||
| if (!raw) return null; | ||
| const cache = JSON.parse(raw) as FeedCache; | ||
| if (Date.now() - cache.timestamp < FEED_CACHE_TTL) return cache; | ||
| } catch { | ||
| // ignore | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| export function writeFeedCache(payload: FeedCachePayload): void { | ||
| const cache: FeedCache = { | ||
| ...payload, | ||
| scrollY: window.scrollY, | ||
| timestamp: Date.now(), | ||
| }; | ||
| sessionStorage.setItem(FEED_CACHE_KEY, JSON.stringify(cache)); | ||
| } | ||
|
|
||
| export function useFeedCache() { | ||
| const [initialCache] = useState<FeedCache | null>(readCache); | ||
|
|
||
| useEffect(() => { | ||
| if (!initialCache) return; | ||
| const y = initialCache.scrollY; | ||
| requestAnimationFrame(() => { | ||
| requestAnimationFrame(() => { | ||
| window.scrollTo(0, y); | ||
| }); | ||
| }); | ||
| // eslint-disable-next-line react-hooks/exhaustive-deps | ||
| }, []); | ||
|
|
||
| useEffect(() => { | ||
| let timeout: ReturnType<typeof setTimeout>; | ||
|
|
||
| const handleScroll = () => { | ||
| clearTimeout(timeout); | ||
| timeout = setTimeout(() => { | ||
| try { | ||
| const raw = sessionStorage.getItem(FEED_CACHE_KEY); | ||
| if (!raw) return; | ||
| const cache = JSON.parse(raw) as FeedCache; | ||
| cache.scrollY = window.scrollY; | ||
| sessionStorage.setItem(FEED_CACHE_KEY, JSON.stringify(cache)); | ||
| } catch { | ||
| // ignore | ||
| } | ||
| }, 100); | ||
| }; | ||
|
|
||
| window.addEventListener('scroll', handleScroll, { passive: true }); | ||
| return () => { | ||
| window.removeEventListener('scroll', handleScroll); | ||
| clearTimeout(timeout); | ||
| }; | ||
| }, []); | ||
|
|
||
| return { initialCache }; | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.