Merge branch 'feat/apps-in-toss' into release/1026-merge
# Conflicts: # frontend/src/api/client/@tanstack/react-query.gen.ts # frontend/src/api/client/index.ts # frontend/src/api/client/sdk.gen.ts
This commit is contained in:
commit
d727b38260
35 files changed
+2249
-70
No files matched your search
@@ -2,6 +2,7 @@ import { useCallback, useEffect, useMemo, useState, type ReactNode } from 'react
|
||||
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 { IS_TOSS } from '../lib/platform'
|
||||
import { cx } from '../lib/utils'
|
||||
import { kindOfHour, kst, seasonOf, type TimeKind } from './lib'
|
||||
import './b.css'
|
||||
@@ -12,6 +13,7 @@ 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 { Avatar, Ic, Skel } from './ui'
|
||||
|
||||
@@ -60,7 +62,7 @@ function TopBar() {
|
||||
<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>
|
||||
{mePending ? (
|
||||
{IS_TOSS ? null : mePending ? (
|
||||
<Skel shape className="size-9 shrink-0 rounded-full" />
|
||||
) : me ? (
|
||||
<button type="button" onClick={() => open({ type: 'me' })} aria-label={`내 정보, ${me.nickname}`} className="shrink-0 cursor-pointer rounded-full shadow-[0_6px_12px_rgb(40_48_74/0.12)]">
|
||||
@@ -305,6 +307,7 @@ export function BLayout() {
|
||||
<RegionProvider>
|
||||
<SheetProvider>
|
||||
<Shell />
|
||||
<TossIntro />
|
||||
</SheetProvider>
|
||||
</RegionProvider>
|
||||
</AuthProvider>
|
||||
|
||||
@@ -302,8 +302,9 @@ function LineCard({ post }: PostProps) {
|
||||
)
|
||||
}
|
||||
|
||||
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요 */
|
||||
/** 인스타식 게시물: 옆으로 넘기는 슬라이드, 두 번 눌러 좋아요. 모르는 종류(서버에 새로 생긴 것)는 건너뛴다 */
|
||||
export function PostCard({ post }: PostProps) {
|
||||
if (!(post.post_type in ACCOUNTS)) return null
|
||||
return post.size === 'line' ? <LineCard post={post} /> : <FullCard post={post} />
|
||||
}
|
||||
|
||||
|
||||
@@ -20,6 +20,7 @@ import {
|
||||
} from '../api/client/@tanstack/react-query.gen'
|
||||
import { AuthProvider, type CommentData, type Factor, type ResAuth, type ResCommentList, type ResIndexDetail } from '../api/client/types.gen'
|
||||
import { track } from '../lib/analytics'
|
||||
import { IS_TOSS, tossShare } from '../lib/platform'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useAuth } from './authContext'
|
||||
import { ago, ARTICLE_CAT, articleMeta, AVATAR_COLORS, cardBg, CHARACTERS, dateRange, loadOf, MOODS, shortDay } from './lib'
|
||||
@@ -562,6 +563,19 @@ function ShareSheet({ share }: { share: SharePayload }) {
|
||||
const send = () => {
|
||||
if (!image) return
|
||||
const file = new File([image.blob], `nalssigak-${SHARE_SIZES[size].ratio.replace(':', 'x')}.png`, { type: 'image/png' })
|
||||
if (IS_TOSS) {
|
||||
tossShare(image.blob, file.name, share.title).then(
|
||||
(r) => {
|
||||
setToast(r === 'saved' ? '이미지를 저장하고 링크를 보냈어요' : '링크를 보냈어요')
|
||||
track('share', { content_type: 'image', item_id: share.title, method: 'share_sheet', ratio: SHARE_SIZES[size].ratio })
|
||||
},
|
||||
(e: unknown) => {
|
||||
console.error('[share] toss', e)
|
||||
setToast('보내지 못했어요. 한 번 더 눌러 주세요')
|
||||
},
|
||||
)
|
||||
return
|
||||
}
|
||||
if (navigator.canShare?.({ files: [file], text, url: SITE_URL })) {
|
||||
const copied = navigator.clipboard?.writeText(SITE_URL).then(
|
||||
() => true,
|
||||
@@ -820,6 +834,7 @@ function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: ()
|
||||
const fail = () => setError('서버에 닿지 못했어요. 잠시 뒤에 다시 해 주세요.')
|
||||
|
||||
if (me) return <MeSheet onDone={onDone} />
|
||||
if (IS_TOSS) return <TossNoLoginSheet onDone={onDone} />
|
||||
|
||||
return (
|
||||
<Body>
|
||||
@@ -843,6 +858,18 @@ function LoginSheet({ onDone, onLoggedIn }: { onDone: () => void; onLoggedIn: ()
|
||||
)
|
||||
}
|
||||
|
||||
/** 토스판은 로그인이 없다. 로그인이 필요한 곳(두 번째 내 각)에서 안내만 한다 */
|
||||
function TossNoLoginSheet({ onDone }: { onDone: () => void }) {
|
||||
return (
|
||||
<Body className="flex flex-col gap-2.5">
|
||||
<p className="m-0 text-center text-sm font-semibold text-(--ink2)">토스에서는 내 각을 하나만 만들 수 있어요. 지금 각을 지우고 새로 만들어 주세요.</p>
|
||||
<button type="button" onClick={onDone} className="cursor-pointer rounded-[14px] bg-(--orange) p-[13px] font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)]">
|
||||
알겠어요
|
||||
</button>
|
||||
</Body>
|
||||
)
|
||||
}
|
||||
|
||||
/* ---------- 내 정보: 캐릭터·닉네임·로그아웃 ---------- */
|
||||
function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
const install = useInstall()
|
||||
@@ -880,7 +907,7 @@ function MeSheet({ onDone }: { onDone: () => void }) {
|
||||
<Body className="flex flex-col gap-3">
|
||||
<div className="flex flex-col items-center gap-1.5">
|
||||
<Avatar character={me.character} color={me.color} mood={me.mood} size={64} />
|
||||
<p className="m-0 text-center text-sm font-semibold text-(--ink2)">{me.provider === AuthProvider.GOOGLE ? '구글 계정으로 로그인했어요' : `${me.login_id}(으)로 로그인했어요`}</p>
|
||||
<p className="m-0 text-center text-sm font-semibold text-(--ink2)">{me.provider === AuthProvider.TOSS ? '토스로 로그인했어요' : me.provider === AuthProvider.GOOGLE ? '구글 계정으로 로그인했어요' : `${me.login_id}(으)로 로그인했어요`}</p>
|
||||
</div>
|
||||
{installable && (
|
||||
<button type="button" onClick={() => install('menu')} className="cursor-pointer rounded-2xl bg-[#fff4ec] py-2.5 font-jua text-[15.5px] text-(--orange)">
|
||||
@@ -1046,12 +1073,12 @@ function RegionSheet({ onDone }: { onDone: () => void }) {
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<p className="mt-4 flex items-center justify-center gap-2 text-[13px] font-bold text-(--ink2)">
|
||||
{!IS_TOSS && <p className="mt-4 flex items-center justify-center gap-2 text-[13px] font-bold text-(--ink2)">
|
||||
{me ? `${me.nickname}(으)로 로그인했어요` : '로그인하면 좋아요·댓글을 쓸 수 있어요'}
|
||||
<button type="button" onClick={me ? logout : () => open({ type: 'login' })} className="cursor-pointer font-extrabold text-(--rain)">
|
||||
{me ? '로그아웃' : '로그인'}
|
||||
</button>
|
||||
</p>
|
||||
</p>}
|
||||
</Body>
|
||||
)
|
||||
}
|
||||
+35
-19
@@ -4,6 +4,7 @@ import regionPages from '../../seo/region.json'
|
||||
import { nearestRegion } from '../api/client/sdk.gen'
|
||||
import type { RegionData } from '../api/client/types.gen'
|
||||
import { track } from '../lib/analytics'
|
||||
import { IS_TOSS, tossLocation } from '../lib/platform'
|
||||
import { DEFAULT_REGION, ownPage, RegionContext, type LocateStatus } from './regionContext'
|
||||
|
||||
const KEY = 'nalssigak.b.region'
|
||||
@@ -55,8 +56,8 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
const [chosen, setRegionState] = useState<RegionData>(() => (page ? regionIn(page, stored) : (stored ?? DEFAULT_REGION)))
|
||||
// 앱 안에서 다른 지역 페이지로 옮겨 가면 그 지역으로
|
||||
const region = page && !page.regions.some((g) => g.code === chosen.code) ? regionIn(page, stored) : chosen
|
||||
const canLocate = typeof navigator !== 'undefined' && 'geolocation' in navigator
|
||||
const [locateStatus, setLocateStatus] = useState<LocateStatus>(!landing && !stored && canLocate ? 'locating' : 'idle')
|
||||
const canLocate = IS_TOSS || (typeof navigator !== 'undefined' && 'geolocation' in navigator)
|
||||
const [locateStatus, setLocateStatus] = useState<LocateStatus>(!landing && (!stored || IS_TOSS) && canLocate ? 'locating' : 'idle')
|
||||
|
||||
// 지역 페이지에서 고르면 주소도 그 지역 페이지로 바꿔, 공유한 링크가 보던 화면과 같게 한다
|
||||
const setRegion = useCallback((r: RegionData) => {
|
||||
@@ -66,18 +67,33 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
if (pageRef.current && next && next !== pageRef.current) navigate(`/${dayRef.current}/${next.path}`)
|
||||
}, [navigate])
|
||||
|
||||
// quiet 면 못 찾아도 상태를 바꾸지 않는다 (사람이 누른 게 아니라 안내 문구를 띄우지 않음)
|
||||
const findNearest = useCallback((apply: (r: RegionData) => void, quiet = false) => {
|
||||
// quiet 면 못 찾아도 상태를 바꾸지 않는다 (사람이 누른 게 아니라 안내 문구를 띄우지 않음). ask=false 면 토스에서 권한 창 없이, 이미 허용한 사람만
|
||||
const findNearest = useCallback((apply: (r: RegionData) => void, quiet = false, ask = true) => {
|
||||
const fromCoords = (lat: number, lon: number) => {
|
||||
nearestRegion({ query: { lat, lon } })
|
||||
.then(({ data: res }) => {
|
||||
if (!res.region) throw new Error('가까운 구를 찾지 못함')
|
||||
setLocateStatus('idle')
|
||||
apply(res.region)
|
||||
})
|
||||
.catch(() => !quiet && setLocateStatus('error'))
|
||||
}
|
||||
if (IS_TOSS) {
|
||||
tossLocation(ask).then(
|
||||
(loc) => {
|
||||
if (loc === null) setLocateStatus('idle')
|
||||
else if (loc === 'denied') setLocateStatus(quiet ? 'idle' : 'denied')
|
||||
else fromCoords(loc.lat, loc.lon)
|
||||
},
|
||||
(e: unknown) => {
|
||||
console.error('[region] toss location', e)
|
||||
setLocateStatus(quiet ? 'idle' : 'error')
|
||||
},
|
||||
)
|
||||
return
|
||||
}
|
||||
navigator.geolocation.getCurrentPosition(
|
||||
(pos) => {
|
||||
nearestRegion({ query: { lat: pos.coords.latitude, lon: pos.coords.longitude } })
|
||||
.then(({ data: res }) => {
|
||||
if (!res.region) throw new Error('가까운 구를 찾지 못함')
|
||||
setLocateStatus('idle')
|
||||
apply(res.region)
|
||||
})
|
||||
.catch(() => !quiet && setLocateStatus('error'))
|
||||
},
|
||||
(pos) => fromCoords(pos.coords.latitude, pos.coords.longitude),
|
||||
(err) => !quiet && setLocateStatus(err.code === err.PERMISSION_DENIED ? 'denied' : 'error'),
|
||||
{ timeout: 10000, maximumAge: 600000 },
|
||||
)
|
||||
@@ -98,14 +114,14 @@ export function RegionProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
useEffect(() => {
|
||||
if (!canLocate) return
|
||||
// 처음 온 사람만 위치 권한을 물어 가장 가까운 구로 맞춘다
|
||||
// 처음 온 사람은 위치 권한을 물어 가장 가까운 구로 맞춘다. 토스판은 지역을 고른 적 있어도 권한이 있으면 들어올 때마다 지금 위치로
|
||||
if (!landing) {
|
||||
if (!stored) {
|
||||
findNearest((r) => {
|
||||
setRegion(r)
|
||||
track('region_change', { region_name: r.name, method: 'location' })
|
||||
})
|
||||
const apply = (r: RegionData) => {
|
||||
setRegion(r)
|
||||
track('region_change', { region_name: r.name, method: 'location' })
|
||||
}
|
||||
if (!stored) findNearest(apply)
|
||||
else if (IS_TOSS) findNearest(apply, false, false)
|
||||
return
|
||||
}
|
||||
// 지역 페이지로 들어오면 그 지역을 보여 준다. 구로 나뉜 시는 위치를 이미 허용했고 그 시 안에 있으면 지금 있는 구로
|
||||
|
||||
+13
-5
@@ -12,6 +12,7 @@ import {
|
||||
import { uploadTalkImage } from '../api/client/sdk.gen'
|
||||
import { TalkReport, TalkTopic, type TalkData } from '../api/client/types.gen'
|
||||
import { API_BASE_URL } from '../api/setup'
|
||||
import { IS_TOSS } from '../lib/platform'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useAuth } from './authContext'
|
||||
import { ago, kst } from './lib'
|
||||
@@ -251,10 +252,15 @@ function TalkRow({ t, onGone, compact }: { t: TalkData; onGone?: () => void; com
|
||||
)}
|
||||
{t.image && !compact && <img src={src} alt="" loading="lazy" className="mt-2 aspect-[4/5] w-full rounded-2xl bg-[#eef4fc] object-cover" />}
|
||||
<small className={cx('block text-xs font-bold text-(--ink3)', compact ? 'mt-auto pt-1.5' : 'mt-0.5')}>
|
||||
{ago(t.created_at)} · 좋아요 {count}개 ·{' '}
|
||||
<button type="button" onClick={() => setMenu(menu === 'closed' ? 'open' : 'closed')} aria-expanded={menu !== 'closed'} className="cursor-pointer font-bold text-(--ink3)">
|
||||
{t.mine ? '내 글' : '더보기'}
|
||||
</button>
|
||||
{ago(t.created_at)} · 좋아요 {count}개
|
||||
{!IS_TOSS && (
|
||||
<>
|
||||
{' · '}
|
||||
<button type="button" onClick={() => setMenu(menu === 'closed' ? 'open' : 'closed')} aria-expanded={menu !== 'closed'} className="cursor-pointer font-bold text-(--ink3)">
|
||||
{t.mine ? '내 글' : '더보기'}
|
||||
</button>
|
||||
</>
|
||||
)}
|
||||
</small>
|
||||
{menu !== 'closed' && (
|
||||
<div className="mt-1.5 flex flex-wrap gap-1.5 text-[12.5px] font-extrabold" role="group" aria-label="글 메뉴">
|
||||
@@ -298,6 +304,7 @@ function TalkRow({ t, onGone, compact }: { t: TalkData; onGone?: () => void; com
|
||||
/** 이야기 탭: 쓰기 칸과 전국 최신 글 (아래로 더 받기) */
|
||||
/** 피드 위 쓰는 칸. 늘 펼쳐 두고, 방금 올린 글은 바로 아래에 보인다 (피드 사이 글은 새로 받을 때 섞인다) */
|
||||
export function FeedComposer({ onPosted }: { onPosted: (t: TalkData) => void }) {
|
||||
if (IS_TOSS) return null
|
||||
return (
|
||||
<div className="mt-3.5">
|
||||
<Composer onDone={onPosted} />
|
||||
@@ -367,7 +374,8 @@ export function FirstTalkCard() {
|
||||
/** '동네 사람들' 자리: 글이 GROUP_MIN 개 이상이면 묶음, 아니면 첫 글 쓰기 */
|
||||
export function NearTalks({ talks, loaded }: { talks: TalkData[]; loaded: boolean }) {
|
||||
if (!loaded) return null
|
||||
return talks.length >= GROUP_MIN ? <TalkGroup title="동네 사람들" talks={talks} /> : <FirstTalkCard />
|
||||
if (talks.length >= GROUP_MIN) return <TalkGroup title="동네 사람들" talks={talks} />
|
||||
return IS_TOSS ? null : <FirstTalkCard />
|
||||
}
|
||||
|
||||
/** 내 정보 창의 내가 쓴 글 */
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
import { useState } from 'react'
|
||||
import { IS_TOSS } from '../lib/platform'
|
||||
import { Ic } from './ui'
|
||||
|
||||
const KEY = 'nalssigak.b.tossIntroSeen'
|
||||
|
||||
const POINTS = [
|
||||
['sun', '세차·빨래·러닝 각 점수'],
|
||||
['sunset', '오늘 노을이 예쁜 시간'],
|
||||
['fireworks', '이번 주말 가까운 행사'],
|
||||
] as const
|
||||
|
||||
function seen() {
|
||||
try {
|
||||
return localStorage.getItem(KEY) === '1'
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
/** 토스판을 처음 열면 서비스 소개를 먼저 보여 준다 (앱인토스 검수: 로그인 전에 서비스 설명) */
|
||||
export function TossIntro() {
|
||||
const [open, setOpen] = useState(() => IS_TOSS && !seen())
|
||||
if (!open) return null
|
||||
|
||||
const start = () => {
|
||||
try {
|
||||
localStorage.setItem(KEY, '1')
|
||||
} catch (e) {
|
||||
console.warn('[intro] 본 기록을 저장하지 못함', e)
|
||||
}
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
return (
|
||||
<div role="dialog" aria-modal="true" aria-labelledby="toss-intro-title" className="fixed inset-0 z-70 flex flex-col items-center justify-center gap-6 bg-[#d6ebff] px-8 text-(--ink)">
|
||||
<Ic name="rabbit" className="w-24" />
|
||||
<div className="text-center">
|
||||
<h1 id="toss-intro-title" className="m-0 font-jua text-[28px] font-normal">
|
||||
날씨각
|
||||
</h1>
|
||||
<p className="m-0 mt-1.5 text-[15px] font-semibold text-(--ink2)">오늘 날씨에 맞는 일을 점수로 알려 줘요</p>
|
||||
</div>
|
||||
<ul className="m-0 flex w-full max-w-xs list-none flex-col gap-2.5 p-0">
|
||||
{POINTS.map(([icon, label]) => (
|
||||
<li key={label} className="flex items-center gap-3 rounded-[18px] bg-white/80 px-4 py-3 text-[15px] font-extrabold">
|
||||
<Ic name={icon} className="w-8 shrink-0" />
|
||||
{label}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
<button type="button" onClick={start} className="w-full max-w-xs cursor-pointer rounded-[14px] bg-(--orange) p-[13px] font-jua text-[17px] text-white shadow-[inset_0_-5px_0_var(--orange-deep)]">
|
||||
시작하기
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { useState, type CSSProperties, type ReactNode } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import { IS_TOSS } from '../lib/platform'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useCarousel, type Carousel } from './carousel'
|
||||
import { AVATAR_COLORS, iconSrc, moodEmoji, naverMap, type Load } from './lib'
|
||||
@@ -202,6 +203,8 @@ export function StateBox({ load, onRetry, empty, className, hold }: StateProps)
|
||||
/** 줄 목록 (라벨 · 값) */
|
||||
/** 위치가 정해진 장소 이름. 누르면 네이버 지도가 새 탭으로 열린다 */
|
||||
export function MapLink({ place, children, className }: { place: string; children: ReactNode; className?: string }) {
|
||||
// 앱인토스는 외부 이동을 막는다
|
||||
if (IS_TOSS) return <span className={className}>{children}</span>
|
||||
return (
|
||||
<a href={naverMap(place)} target="_blank" rel="noopener noreferrer" aria-label={`${place}, 네이버 지도에서 보기`} className={cx('underline decoration-dotted decoration-1 underline-offset-[3px]', className)}>
|
||||
{children}
|
||||
|
||||
Reference in new issue
Block a user