feat: 지역 버튼에 화살표와 '다른 동네 날씨도 볼 수 있어요' 말풍선 추가 — 지역을 바꿀 수 있다는 걸 모른다는 피드백
- 위쪽 지역 버튼에 ▾ 화살표(360px 미만은 자리가 없어 뺌) - 들어올 때마다 버튼 아래 말풍선이 뜨고, 화면을 만지면(터치·클릭·휠·키) 사라진다. 말풍선이나 버튼을 누르면 지역 창. 첫 화면 덮개·토스 소개가 걷힌 뒤에 뜨고 쇼츠에서는 안 뜬다 - 400px 부터 쓰는 긴 이름(경기 성남시 분당구)은 자리가 모자라면 앞쪽만 줄이고 구 이름은 남긴다 (화살표만큼 로그인 버튼이 화면 밖으로 밀리던 것) - 토스 소개 화면을 띄울지는 BLayout 이 정한다 (tossIntroPending) - GA: region_hint_view(지역안내_말풍선_노출), region_hint_tap(지역안내_말풍선_누름, from: bubble|button)
This commit is contained in:
1 parent
ceda60bde7
commit
520fae93a8
6 files changed
+137
-26
No files matched your search
+97
-20
@@ -1,4 +1,4 @@
|
||||
import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react'
|
||||
import { useCallback, useEffect, useMemo, useRef, useState, type ReactNode } from 'react'
|
||||
import { NavLink, Outlet, useLocation, useNavigationType } from 'react-router'
|
||||
import { useIsFetching, useQuery, useQueryClient } from '@tanstack/react-query'
|
||||
import { authConfigOptions, getSeasonWeekOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen'
|
||||
@@ -16,8 +16,8 @@ import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { SheetProvider } from './Sheets'
|
||||
import { SkyContext, useSky } from './skyContext'
|
||||
import { TossIntro } from './tossIntro'
|
||||
import { PinIcon, TabIcon } from './svg'
|
||||
import { TossIntro, tossIntroPending } from './tossIntro'
|
||||
import { ChevronDownIcon, PinIcon, TabIcon } from './svg'
|
||||
import { Avatar, Ic, Skel } from './ui'
|
||||
|
||||
const TABS = [
|
||||
@@ -45,7 +45,11 @@ function SeasonChip() {
|
||||
)
|
||||
}
|
||||
|
||||
function TopBar() {
|
||||
/** 지역 말풍선이 사라지는 데 걸리는 시간(ms). 말풍선의 duration-200 과 같게 */
|
||||
const HINT_FADE = 200
|
||||
|
||||
/** hintReady: 첫 화면 덮개(불러오는 중·토스 소개)가 걷혀 지역 말풍선을 띄워도 되는지 */
|
||||
function TopBar({ hintReady }: { hintReady: boolean }) {
|
||||
const { pathname } = useLocation()
|
||||
const { region, locateStatus } = useRegion()
|
||||
const { open } = useSheet()
|
||||
@@ -53,6 +57,48 @@ function TopBar() {
|
||||
const queryClient = useQueryClient()
|
||||
const tab = TABS.find((t) => t.to !== '/' && pathname.startsWith(t.to))
|
||||
const loggedOut = !mePending && !me
|
||||
// '경기 성남시 분당구' → 앞쪽 '경기 성남시' 와 구 이름 '분당구'
|
||||
const nameParts = region.name.split(' ')
|
||||
const place = nameParts.at(-1)!
|
||||
const upper = nameParts.slice(0, -1).join(' ')
|
||||
// 지역 말풍선: 들어올 때마다 뜨고, 화면을 만지면(터치·클릭·휠·키) 사라진다. 한 번 사라지면 탭을 옮겨도 다시 안 뜬다
|
||||
const [hint, setHint] = useState<'on' | 'leaving' | 'gone'>('on')
|
||||
const hintWrap = useRef<HTMLDivElement>(null)
|
||||
// 위치를 찾는 중에는 버튼에 구 이름이 아직 없다. 쇼츠는 화면 전체가 영상이라 가리지 않는다
|
||||
const hintCan = hintReady && locateStatus !== 'locating' && !pathname.startsWith('/shorts')
|
||||
const hintOn = hintCan && hint === 'on'
|
||||
|
||||
useEffect(() => {
|
||||
if (!hintOn) return
|
||||
track('region_hint_view', {})
|
||||
const leave = (e: Event) => {
|
||||
// 지역 버튼·말풍선을 누른 것은 openRegion 이 맡는다 (여기서 먼저 지우면 말풍선을 보고 눌렀는지 알 수 없다)
|
||||
if (e.target instanceof Node && hintWrap.current?.contains(e.target)) return
|
||||
setHint('leaving')
|
||||
}
|
||||
// 스크롤 대신 터치·휠을 본다: 뒤로 가기 때 화면이 제자리를 찾아가는 스크롤에 꺼지지 않게
|
||||
const opts = { capture: true, passive: true }
|
||||
window.addEventListener('pointerdown', leave, opts)
|
||||
window.addEventListener('wheel', leave, opts)
|
||||
window.addEventListener('keydown', leave, opts)
|
||||
return () => {
|
||||
window.removeEventListener('pointerdown', leave, opts)
|
||||
window.removeEventListener('wheel', leave, opts)
|
||||
window.removeEventListener('keydown', leave, opts)
|
||||
}
|
||||
}, [hintOn])
|
||||
|
||||
useEffect(() => {
|
||||
if (hint !== 'leaving') return
|
||||
const id = setTimeout(() => setHint('gone'), HINT_FADE)
|
||||
return () => clearTimeout(id)
|
||||
}, [hint])
|
||||
|
||||
const openRegion = (from: 'bubble' | 'button') => {
|
||||
if (hintOn) track('region_hint_tap', { from })
|
||||
setHint('gone')
|
||||
open({ type: 'region' })
|
||||
}
|
||||
|
||||
// 로그인 창을 처음 열 때 버벅이지 않게 구글 로그인 준비물을 미리 받아 둔다
|
||||
useEffect(() => {
|
||||
@@ -65,15 +111,38 @@ function TopBar() {
|
||||
<header className="sticky top-0 z-20 flex h-[calc(54px+env(safe-area-inset-top,0px))] items-center justify-between gap-2 px-4 pt-[env(safe-area-inset-top,0px)]">
|
||||
{tab?.title ? <h1 className="shrink-0 font-jua text-[22px] font-normal">{tab.title}</h1> : <h1 className="shrink-0 font-jua text-[25px] font-normal text-(--orange)">날씨각</h1>}
|
||||
<SeasonChip />
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => open({ type: 'region' })}
|
||||
aria-label={`위치 바꾸기, 지금 ${region.name}`}
|
||||
className="ml-auto flex shrink-0 cursor-pointer items-center gap-1 rounded-full bg-white px-3 pt-1 pb-2 text-[13.5px] font-bold shadow-[inset_0_-4px_0_var(--shade),0_6px_12px_rgb(40_48_74/0.07)]"
|
||||
>
|
||||
<PinIcon className="size-3.5 shrink-0" />
|
||||
{locateStatus === 'locating' ? <Skel className="w-[72px]" /> : <span className="truncate whitespace-nowrap"><span className="max-[399px]:hidden">{region.name}</span><span className="min-[400px]:hidden">{region.name.split(' ').at(-1)}</span></span>}
|
||||
</button>
|
||||
{/* 400px 부터는 시·도까지 쓴 긴 이름이라 자리가 모자라면 앞쪽(시·도·시)만 줄이고(…) 구 이름은 남긴다. 그대로 두면 오른쪽 로그인 버튼이 화면 밖으로 밀린다 */}
|
||||
<div ref={hintWrap} className="relative ml-auto flex shrink-0 min-[400px]:min-w-0 min-[400px]:shrink">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openRegion('button')}
|
||||
aria-label={`위치 바꾸기, 지금 ${region.name}`}
|
||||
className="flex min-w-0 cursor-pointer items-center gap-1 rounded-full bg-white pt-1 pr-2.5 pb-2 pl-3 text-[13.5px] font-bold shadow-[inset_0_-4px_0_var(--shade),0_6px_12px_rgb(40_48_74/0.07)]"
|
||||
>
|
||||
<PinIcon className="size-3.5 shrink-0" />
|
||||
{locateStatus === 'locating' ? (
|
||||
<Skel className="w-[72px]" />
|
||||
) : (
|
||||
<span className="flex min-w-0 whitespace-nowrap">
|
||||
{upper && <span className="mr-[0.28em] truncate max-[400px]:hidden">{upper}</span>}
|
||||
<span className="shrink-0">{place}</span>
|
||||
</span>
|
||||
)}
|
||||
{/* 360px 보다 좁은 화면은 위 바에 자리가 없어 화살표를 뺀다 (로그인 버튼이 밀려 잘린다) */}
|
||||
<ChevronDownIcon className="size-3 shrink-0 opacity-60 max-[360px]:hidden" />
|
||||
</button>
|
||||
{hintCan && hint !== 'gone' && (
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => openRegion('bubble')}
|
||||
className={cx('b-hint absolute top-full right-0 mt-2 cursor-pointer rounded-2xl bg-(--ink) px-3.5 py-2 text-left text-[13px] leading-snug font-bold whitespace-nowrap text-white shadow-[0_8px_18px_rgb(40_48_74/0.25)] transition-opacity duration-200', hint === 'leaving' && 'opacity-0')}
|
||||
>
|
||||
<i className="absolute -top-1 right-7 size-3 rotate-45 rounded-[2px] bg-inherit" aria-hidden="true" />
|
||||
다른 동네 날씨도 볼 수 있어요
|
||||
<span className="block font-extrabold text-[#ffd9b5]">눌러서 바꾸기</span>
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
{mePending ? (
|
||||
<Skel shape className="size-9 shrink-0 rounded-full" />
|
||||
) : me ? (
|
||||
@@ -219,8 +288,8 @@ const NOTCH_BG: Record<TimeKind, string> = {
|
||||
night: '#0e1433',
|
||||
}
|
||||
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다 */
|
||||
function FirstLoad() {
|
||||
/** 처음 들어올 때만: 첫 데이터를 다 받을 때까지 하늘 위에 캐릭터와 '날씨 불러오는 중…'. 한 번 사라지면 다시 안 뜬다. 걷히기 시작하면 onDone 을 부른다 */
|
||||
function FirstLoad({ onDone }: { onDone: () => void }) {
|
||||
const fetching = useIsFetching()
|
||||
const { kind } = useSky()
|
||||
const [started, setStarted] = useState(false)
|
||||
@@ -237,6 +306,10 @@ function FirstLoad() {
|
||||
const id = setTimeout(() => setDone(true), 10000)
|
||||
return () => clearTimeout(id)
|
||||
}, [])
|
||||
const cleared = done || gone
|
||||
useEffect(() => {
|
||||
if (cleared) onDone()
|
||||
}, [cleared, onDone])
|
||||
if (gone) return null
|
||||
return (
|
||||
<div
|
||||
@@ -255,10 +328,13 @@ function FirstLoad() {
|
||||
// 페이지마다 마지막 스크롤 위치: 뒤로 가기로 돌아오면 그 자리로
|
||||
const scrolled = new Map<string, number>()
|
||||
|
||||
function Shell() {
|
||||
/** intro: 토스 첫 소개 화면이 떠 있는지 */
|
||||
function Shell({ intro }: { intro: boolean }) {
|
||||
const { pathname, key } = useLocation()
|
||||
const navType = useNavigationType()
|
||||
const { kind } = useSky()
|
||||
const [loaded, setLoaded] = useState(false)
|
||||
const onLoaded = useCallback(() => setLoaded(true), [])
|
||||
useEffect(() => {
|
||||
const save = () => scrolled.set(key, window.scrollY)
|
||||
window.addEventListener('scroll', save, { passive: true })
|
||||
@@ -298,7 +374,7 @@ function Shell() {
|
||||
return (
|
||||
<div className="min-h-dvh text-(--ink)">
|
||||
<SkyBg />
|
||||
<FirstLoad />
|
||||
<FirstLoad onDone={onLoaded} />
|
||||
{/* 위·아래 바: 띠는 화면 끝까지, 내용은 가운데 440px 안 */}
|
||||
<div className="b-topbg fixed inset-x-0 top-0 z-[19] h-[calc(54px+env(safe-area-inset-top,0px))] backdrop-blur-md" aria-hidden="true" />
|
||||
{HOLIDAY && (
|
||||
@@ -308,7 +384,7 @@ function Shell() {
|
||||
)}
|
||||
<div className="fixed inset-x-0 top-0 z-[19] h-[env(safe-area-inset-top,0px)] transition-colors duration-1400" style={{ backgroundColor: NOTCH_BG[kind] }} aria-hidden="true" />
|
||||
<div className="relative mx-auto min-h-dvh max-w-[440px] overflow-x-clip pb-[calc(104px+var(--sab))]">
|
||||
<TopBar />
|
||||
<TopBar hintReady={loaded && !intro} />
|
||||
<main className="relative z-[1]">
|
||||
<Outlet />
|
||||
</main>
|
||||
@@ -355,13 +431,14 @@ function SkyApp({ children }: { children: ReactNode }) {
|
||||
}
|
||||
|
||||
export function BLayout() {
|
||||
const [intro, setIntro] = useState(tossIntroPending)
|
||||
return (
|
||||
<SkyRoot>
|
||||
<AuthProvider>
|
||||
<RegionProvider>
|
||||
<SheetProvider>
|
||||
<Shell />
|
||||
<TossIntro />
|
||||
<Shell intro={intro} />
|
||||
{intro && <TossIntro onStart={() => setIntro(false)} />}
|
||||
<LevelWatcher />
|
||||
</SheetProvider>
|
||||
</RegionProvider>
|
||||
|
||||
@@ -120,6 +120,22 @@
|
||||
}
|
||||
}
|
||||
|
||||
/* 지역 버튼 아래 말풍선: 버튼 쪽(꼬리 자리)에서 톡 튀어나오듯 나타난다. 사라질 땐 opacity 전환(BLayout HINT_FADE) */
|
||||
.b-hint {
|
||||
transform-origin: calc(100% - 34px) 0;
|
||||
animation: b-hint-in 0.4s cubic-bezier(0.2, 0.9, 0.3, 1.2) 0.3s backwards;
|
||||
}
|
||||
@keyframes b-hint-in {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: translateY(-6px) scale(0.85);
|
||||
}
|
||||
100% {
|
||||
opacity: 1;
|
||||
transform: none;
|
||||
}
|
||||
}
|
||||
|
||||
/* 아래 창은 불투명한 채로 화면 아래에서 끝까지 올라오고, 닫힐 땐 다시 내려간다 (반투명으로 올라오면 뒤 탭 바가 비쳐 깜빡여 보였다) */
|
||||
.b-sheet {
|
||||
animation: b-up 0.28s cubic-bezier(0.2, 0.9, 0.3, 1);
|
||||
@@ -174,6 +190,7 @@
|
||||
.b-fall,
|
||||
.b-heart-pop,
|
||||
.b-like-bit,
|
||||
.b-hint,
|
||||
.b-sheet,
|
||||
.b-sheet-dialog[open]::backdrop {
|
||||
animation: none !important;
|
||||
|
||||
@@ -53,6 +53,14 @@ export function PinIcon({ className }: P) {
|
||||
)
|
||||
}
|
||||
|
||||
export function ChevronDownIcon({ className }: P) {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" {...line} strokeWidth="3" className={className} aria-hidden="true">
|
||||
<path d="M6 9.5l6 6 6-6" />
|
||||
</svg>
|
||||
)
|
||||
}
|
||||
|
||||
export function TabIcon({ name, className }: P & { name: 'today' | 'gak' | 'sky' | 'week' | 'season' | 'talk' }) {
|
||||
return (
|
||||
<svg viewBox="0 0 24 24" {...line} className={className} aria-hidden="true">
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
import { useState } from 'react'
|
||||
import { IS_TOSS } from '../lib/platform'
|
||||
import { Ic } from './ui'
|
||||
import { track } from '../lib/analytics'
|
||||
@@ -19,11 +18,13 @@ function seen() {
|
||||
}
|
||||
}
|
||||
|
||||
/** 토스판을 처음 열면 서비스 소개를 먼저 보여 준다 (앱인토스 검수: 로그인 전에 서비스 설명) */
|
||||
export function TossIntro() {
|
||||
const [open, setOpen] = useState(() => IS_TOSS && !seen())
|
||||
if (!open) return null
|
||||
/** 토스판을 처음 열어 소개 화면을 보여 줘야 하는지 */
|
||||
export function tossIntroPending() {
|
||||
return IS_TOSS && !seen()
|
||||
}
|
||||
|
||||
/** 토스판을 처음 열면 서비스 소개를 먼저 보여 준다 (앱인토스 검수: 로그인 전에 서비스 설명). 띄울지는 부르는 쪽이 tossIntroPending 으로 정한다 */
|
||||
export function TossIntro({ onStart }: { onStart: () => void }) {
|
||||
const start = () => {
|
||||
try {
|
||||
localStorage.setItem(KEY, '1')
|
||||
@@ -31,7 +32,7 @@ export function TossIntro() {
|
||||
console.warn('[intro] 본 기록을 저장하지 못함', e)
|
||||
}
|
||||
track('toss_intro_start', {})
|
||||
setOpen(false)
|
||||
onStart()
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user