fix: QA 버그 5건 수정 — 뒤로 가기로 시트 닫기, 로그인 후 댓글 복귀, 터치 영역 44px, 순위 대기 칩 비활성, 위치 찾기 후 지역 시트 닫기
This commit is contained in:
1 parent
471353212a
commit
f1846ddf66
8 files changed
+72
-33
No files matched your search
+46
-14
@@ -28,16 +28,39 @@ import { useSky } from './skyContext'
|
||||
import { SHARE_SIZES, shareImage, type ShareSize } from './storyImage'
|
||||
import { SheetContext, useSheet, type SharePayload, type SheetState } from './sheetContext'
|
||||
import { HeartIcon } from './svg'
|
||||
import { Avatar, Ic, Skel, StateBox, Thumb } from './ui'
|
||||
import { Avatar, Ic, Skel, StateBox, TAP44, Thumb } from './ui'
|
||||
|
||||
export function SheetProvider({ children }: { children: ReactNode }) {
|
||||
const [state, setState] = useState<SheetState>(null)
|
||||
const open = useCallback((s: Exclude<SheetState, null>) => setState(s), [])
|
||||
const close = useCallback(() => setState(null), [])
|
||||
// 창이 열려 있는 동안 방문 기록을 하나 쌓아 두어 뒤로 가기가 창만 닫게 한다
|
||||
const pushed = useRef(false)
|
||||
const open = useCallback((s: Exclude<SheetState, null>) => {
|
||||
if (!pushed.current) {
|
||||
window.history.pushState({ ...window.history.state, sheet: true }, '')
|
||||
pushed.current = true
|
||||
}
|
||||
setState(s)
|
||||
}, [])
|
||||
const close = useCallback(() => {
|
||||
setState(null)
|
||||
if (!pushed.current) return
|
||||
pushed.current = false
|
||||
window.history.back()
|
||||
}, [])
|
||||
const api = useMemo(() => ({ open, close }), [open, close])
|
||||
|
||||
useEffect(() => {
|
||||
const onPop = () => {
|
||||
if (!pushed.current) return
|
||||
pushed.current = false
|
||||
setState(null)
|
||||
}
|
||||
window.addEventListener('popstate', onPop)
|
||||
return () => window.removeEventListener('popstate', onPop)
|
||||
}, [])
|
||||
|
||||
// 로그인이 필요한 요청이 401을 받으면 로그인 창을 띄운다
|
||||
useEffect(() => subscribeAuth((reason) => reason === 'required' && setState({ type: 'login' })), [])
|
||||
useEffect(() => subscribeAuth((reason) => reason === 'required' && open({ type: 'login' })), [open])
|
||||
|
||||
return (
|
||||
<SheetContext value={api}>
|
||||
@@ -53,6 +76,7 @@ const TITLES = { article: '읽을거리', seasonWeek: '이번 주 특집', share
|
||||
function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void }) {
|
||||
const ref = useRef<HTMLDialogElement>(null)
|
||||
const { kind } = useSky()
|
||||
const { open } = useSheet()
|
||||
const [gakTitle, setGakTitle] = useState('')
|
||||
const [articleTitle, setArticleTitle] = useState('')
|
||||
|
||||
@@ -75,6 +99,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
}
|
||||
}, [isOpen])
|
||||
|
||||
const then = state?.type === 'login' ? state.then : undefined
|
||||
const title = !state ? '' : state.type === 'gak' ? gakTitle : state.type === 'article' ? articleTitle || TITLES.article : TITLES[state.type]
|
||||
|
||||
return (
|
||||
@@ -93,7 +118,7 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
<div className="relative border-b border-(--line) px-4 pt-2 pb-2.5 text-center">
|
||||
<div className="mx-auto mb-2.5 h-1 w-10 rounded-full bg-(--line)" aria-hidden="true" />
|
||||
<h3 className="m-0 text-[15px] font-extrabold">{title}</h3>
|
||||
<button type="button" onClick={onClose} aria-label="닫기" className="absolute right-3 bottom-2 grid size-[30px] cursor-pointer place-items-center text-xl text-(--ink2)">
|
||||
<button type="button" onClick={onClose} aria-label="닫기" className={cx('absolute right-3 bottom-2 grid size-[30px] cursor-pointer place-items-center text-xl text-(--ink2)', TAP44)}>
|
||||
×
|
||||
</button>
|
||||
</div>
|
||||
@@ -101,8 +126,8 @@ function SheetHost({ state, onClose }: { state: SheetState; onClose: () => void
|
||||
{state.type === 'article' && <ArticleSheet articleId={state.articleId} onTitle={setArticleTitle} />}
|
||||
{state.type === 'seasonWeek' && <SeasonWeekSheet />}
|
||||
{state.type === 'share' && <ShareSheet share={state.share} />}
|
||||
{state.type === 'comments' && <CommentsSheet postId={state.postId} />}
|
||||
{state.type === 'login' && <LoginSheet onDone={onClose} />}
|
||||
{state.type === 'comments' && <CommentsSheet postId={state.postId} draft={state.draft} />}
|
||||
{state.type === 'login' && <LoginSheet onDone={onClose} onLoggedIn={then ? () => open(then) : onClose} />}
|
||||
{state.type === 'me' && <MeSheet onDone={onClose} />}
|
||||
{state.type === 'region' && <RegionSheet onDone={onClose} />}
|
||||
</div>
|
||||
@@ -632,14 +657,14 @@ function CommentRow({ c, postId }: { c: CommentData; postId: number }) {
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<button type="button" onClick={toggle} aria-pressed={liked} aria-label="댓글 좋아요" className="cursor-pointer pt-1">
|
||||
<button type="button" onClick={toggle} aria-pressed={liked} aria-label="댓글 좋아요" className={cx('relative cursor-pointer pt-1', TAP44)}>
|
||||
<HeartIcon className={cx('size-4 stroke-2', liked ? 'fill-(--heart) stroke-(--heart)' : 'fill-none stroke-(--ink3)')} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
function CommentsSheet({ postId }: { postId: number }) {
|
||||
function CommentsSheet({ postId, draft }: { postId: number; draft?: string }) {
|
||||
const { region } = useRegion()
|
||||
const { open } = useSheet()
|
||||
const { loggedIn, me } = useAuth()
|
||||
@@ -651,13 +676,13 @@ function CommentsSheet({ postId }: { postId: number }) {
|
||||
})
|
||||
const add = useMutation(addCommentMutation())
|
||||
const [addFailed, setAddFailed] = useState(false)
|
||||
const [text, setText] = useState('')
|
||||
const [text, setText] = useState(draft ?? '')
|
||||
const inputRef = useRef<HTMLInputElement>(null)
|
||||
const comments = list.data?.pages.flatMap((p) => p.comments ?? []) ?? []
|
||||
|
||||
const submit = (e: FormEvent) => {
|
||||
e.preventDefault()
|
||||
if (!loggedIn) return open({ type: 'login' })
|
||||
if (!loggedIn) return open({ type: 'login', then: { type: 'comments', postId, draft: text } })
|
||||
const body = text.trim()
|
||||
if (!body || add.isPending) return
|
||||
setAddFailed(false)
|
||||
@@ -731,7 +756,7 @@ const AUTH_ERRORS: Record<string, string> = {
|
||||
INVALID_INPUT: '아이디는 영어 소문자·숫자·_ 4~20자, 비밀번호는 8~64자, 닉네임은 2~12자로 써 주세요.',
|
||||
}
|
||||
|
||||
function LoginSheet({ onDone }: { onDone: () => void }) {
|
||||
function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: () => void }) {
|
||||
const { me } = useAuth()
|
||||
const [mode, setMode] = useState<'login' | 'signup'>('login')
|
||||
const [loginId, setLoginId] = useState('')
|
||||
@@ -748,7 +773,7 @@ function LoginSheet({ onDone }: { onDone: () => void }) {
|
||||
return
|
||||
}
|
||||
setTokens(res.access_token, res.refresh_token ?? null)
|
||||
onDone()
|
||||
onLoggedIn()
|
||||
}
|
||||
const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.')
|
||||
|
||||
@@ -925,6 +950,13 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
|
||||
const { region, setRegion, locate, locateStatus } = useRegion()
|
||||
const { me, logout } = useAuth()
|
||||
const { open } = useSheet()
|
||||
const alive = useRef(true)
|
||||
useEffect(() => {
|
||||
alive.current = true
|
||||
return () => {
|
||||
alive.current = false
|
||||
}
|
||||
}, [])
|
||||
const [q, setQ] = useState('')
|
||||
const deferred = useDeferredValue(q.trim())
|
||||
const list = useQuery(listRegionsOptions(deferred ? { query: { q: deferred } } : undefined))
|
||||
@@ -933,7 +965,7 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
|
||||
|
||||
return (
|
||||
<Body>
|
||||
<button type="button" onClick={locate} disabled={locateStatus === 'locating'} className="w-full cursor-pointer rounded-full bg-(--orange) p-3 font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
|
||||
<button type="button" onClick={() => locate(() => alive.current && onDone())} disabled={locateStatus === 'locating'} className="w-full cursor-pointer rounded-full bg-(--orange) p-3 font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)] disabled:opacity-60">
|
||||
지금 위치로 찾기
|
||||
</button>
|
||||
<p className="mt-2 min-h-5 text-center text-[13px] font-bold text-(--ink2)" aria-live="polite">
|
||||
|
||||
Reference in new issue
Block a user