feat: 단풍 지도 페이지(/foliage) — 카드는 절정만 잎 아이콘, 누르면 페이지에서 확대·이동·목록, 확대할수록 이름 더, 뒤로 가면 피드 위치 그대로
This commit is contained in:
1 parent
446af2e9b5
commit
d75144a6ac
6 files changed
+652
-211
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { NavLink, Outlet, useLocation } from 'react-router'
|
||||
import { NavLink, Outlet, useLocation, useNavigationType } from 'react-router'
|
||||
import { useIsFetching, useQuery } from '@tanstack/react-query'
|
||||
import { getSeasonWeekOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
@@ -202,12 +202,34 @@ function FirstLoad() {
|
||||
)
|
||||
}
|
||||
|
||||
// 페이지마다 마지막 스크롤 위치: 뒤로 가기로 돌아오면 그 자리로
|
||||
const scrolled = new Map<string, number>()
|
||||
|
||||
function Shell() {
|
||||
const { pathname } = useLocation()
|
||||
const { pathname, key } = useLocation()
|
||||
const navType = useNavigationType()
|
||||
const { kind } = useSky()
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0 })
|
||||
}, [pathname])
|
||||
const save = () => scrolled.set(key, window.scrollY)
|
||||
window.addEventListener('scroll', save, { passive: true })
|
||||
return () => window.removeEventListener('scroll', save)
|
||||
}, [key])
|
||||
useEffect(() => {
|
||||
const top = navType === 'POP' ? scrolled.get(key) : undefined
|
||||
if (top == null) {
|
||||
window.scrollTo({ top: 0 })
|
||||
return
|
||||
}
|
||||
// 피드가 다시 그려져 그 높이가 될 때까지 몇 프레임 기다리며 맞춘다
|
||||
let tries = 0
|
||||
let raf = 0
|
||||
const go = () => {
|
||||
window.scrollTo({ top })
|
||||
if (Math.abs(window.scrollY - top) > 2 && ++tries < 60) raf = requestAnimationFrame(go)
|
||||
}
|
||||
go()
|
||||
return () => cancelAnimationFrame(raf)
|
||||
}, [pathname, key, navType])
|
||||
// 지금 보고 있는 탭을 다시 누르면 맨 위로
|
||||
const toTopIfHere = (to: string) => () => {
|
||||
if (pathname === to) window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
|
||||
Reference in new issue
Block a user