feat: 작업 중이던 변경 반영 — 글 주제(동네 이야기·하늘·비·단풍·옷차림)와 주제별 묶음을 피드 사이사이에, 이야기 페이지(/talk), 애드센스 코드·ads.txt·개인정보처리방침, 사진 검증을 Blob 주소까지
This commit is contained in:
1 parent
1393fc465c
commit
3cb58b9f0f
22 files changed
+718
-60
No files matched your search
@@ -0,0 +1,44 @@
|
||||
import { useSearchParams } from 'react-router'
|
||||
import type { TalkTopic } from '../api/client/types.gen'
|
||||
import { cx } from '../lib/utils'
|
||||
import { TalkCard } from './talk'
|
||||
import { TOPICS, useTopicTalks } from './talkState'
|
||||
import { Sec } from './ui'
|
||||
|
||||
/** 주제별 사람 글: 위 주제 탭, 아래 글 목록. 피드 묶음의 '전체 보기'가 ?topic= 으로 연다 */
|
||||
export function TalkPage() {
|
||||
const [params, setParams] = useSearchParams()
|
||||
const raw = Number(params.get('topic'))
|
||||
const topic = TOPICS.some(([k]) => k === raw) ? (raw as TalkTopic) : undefined
|
||||
const { talks, loaded, more, loadMore } = useTopicTalks(topic)
|
||||
const tabs: (readonly [TalkTopic | undefined, string])[] = [[undefined, '전체'], ...TOPICS]
|
||||
|
||||
return (
|
||||
<section aria-label="동네 사람들 글">
|
||||
<Sec title="동네 사람들 글" sub="가까운 동네 글부터 보여요" />
|
||||
<div className="flex flex-wrap gap-1.5 px-4 pb-1" role="tablist" aria-label="글 주제">
|
||||
{tabs.map(([k, label]) => (
|
||||
<button
|
||||
key={label}
|
||||
type="button"
|
||||
role="tab"
|
||||
aria-selected={topic === k}
|
||||
onClick={() => setParams(k ? { topic: String(k) } : {}, { replace: true })}
|
||||
className={cx('cursor-pointer rounded-full px-3 py-1.5 text-[13px] font-extrabold', topic === k ? 'bg-(--ink) text-white' : 'bg-white text-(--ink2)')}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
{loaded && !talks.length && <p className="mx-4 mt-6 text-center text-[14px] font-semibold text-(--ink3)">아직 이 주제 글이 없어요. 오늘 탭에서 첫 글을 써 주세요.</p>}
|
||||
{talks.map((t) => (
|
||||
<TalkCard key={`${t.talk_id}:${t.liked}:${t.like_count}`} t={t} />
|
||||
))}
|
||||
{more && (
|
||||
<button type="button" onClick={() => loadMore()} className="mx-3 mt-3 w-[calc(100%-1.5rem)] cursor-pointer rounded-[14px] bg-white py-2.5 text-[13.5px] font-extrabold text-(--ink2)">
|
||||
더 보기
|
||||
</button>
|
||||
)}
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -3,8 +3,10 @@ import { Link, useLocation } from 'react-router'
|
||||
import { useQuery } from '@tanstack/react-query'
|
||||
import { getFeedOptions, getWeatherTodayOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import {
|
||||
PostType,
|
||||
RainType,
|
||||
Sky,
|
||||
TalkTopic,
|
||||
type BandArticle,
|
||||
type BandEvent,
|
||||
type Hero as HeroData,
|
||||
@@ -22,8 +24,8 @@ import { MyGakRow } from './myGak'
|
||||
import { fromShare } from './myGakState'
|
||||
import { PostCard, PostCardSkel, PostFrame } from './Post'
|
||||
import { usePinnedLike, type PinnedKey } from './pinnedLike'
|
||||
import { FeedComposer, TalkCard } from './talk'
|
||||
import { useFeedTalks } from './talkState'
|
||||
import { FeedComposer, NearTalks, TalkCard, TalkGroup } from './talk'
|
||||
import { topicName, useTalkGroups } from './talkState'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { useSky } from './skyContext'
|
||||
@@ -365,7 +367,7 @@ function Hero({ hero, post, today, ranked, all, feedLoad, todayLoad }: HeroProps
|
||||
<span className="b-cloud b-bob inset-0" />
|
||||
</span>
|
||||
))}
|
||||
<div className="b-fall absolute top-2 left-1/2 -ml-16 aspect-square w-32" style={fall('0s', '5.6s')}>
|
||||
<div className={'b-fall absolute top-2 left-1/2 -ml-16 aspect-square w-32'} style={fall('0s', '5.6s')}>
|
||||
<div className="b-sun b-bob relative grid size-full place-items-center rounded-full text-center">
|
||||
{/* 안 보이는 쪽을 덮어 오늘 밤 달 모양으로 */}
|
||||
{moon && (
|
||||
@@ -572,8 +574,6 @@ function SeasonBand({ news, post }: { news: BandArticle[]; post?: PostReaction |
|
||||
)
|
||||
}
|
||||
|
||||
const TALK_EVERY = 3
|
||||
|
||||
export function TodayPage() {
|
||||
const { region } = useRegion()
|
||||
const feed = useQuery(getFeedOptions({ query: { region: region.code } }))
|
||||
@@ -588,19 +588,18 @@ export function TodayPage() {
|
||||
const nowAt = f?.hero?.now_at
|
||||
const load = loadOf(feed)
|
||||
const [mine, setMine] = useState<TalkData[]>([])
|
||||
// 사람들이 쓴 글은 4·7·10번째 포스트 뒤에 하나씩(3번째 뒤 행사 띠와 안 붙게), 남은 글은 피드 끝에. 방금 올린 내 글은 글쓰기 칸 아래에 따로 있으니 빼고
|
||||
const feedTalks = useFeedTalks()
|
||||
const talks = feedTalks.talks.filter((t) => !mine.some((m) => m.talk_id === t.talk_id))
|
||||
const between = Math.max(0, Math.floor((posts.length - 1) / TALK_EVERY))
|
||||
const moreRef = useRef<HTMLDivElement>(null)
|
||||
const { more, loadMore } = feedTalks
|
||||
useEffect(() => {
|
||||
const el = moreRef.current
|
||||
if (!el || !more) return
|
||||
const io = new IntersectionObserver((es) => es.some((e) => e.isIntersecting) && loadMore(), { rootMargin: '600px' })
|
||||
io.observe(el)
|
||||
return () => io.disconnect()
|
||||
}, [more, loadMore])
|
||||
// 사람 글은 묶음으로: '동네 사람들'은 오늘의 각 아래, 주제 묶음은 같은 주제 포스트 아래. 방금 올린 내 글은 글쓰기 칸 아래에 따로 있으니 빼고
|
||||
const talkGroups = useTalkGroups()
|
||||
const groupOf = (topic: number) => (talkGroups.groups.get(topic) ?? []).filter((t) => !mine.some((m) => m.talk_id === t.talk_id))
|
||||
const group = (topic: number) => {
|
||||
const talks = groupOf(topic)
|
||||
return talks.length ? <TalkGroup key={`talk-${topic}`} title={topicName(topic)} topic={topic} talks={talks} /> : null
|
||||
}
|
||||
// 비·눈이 오거나 2시간 안에 올 때만 비·눈 묶음을 히어로 바로 아래로
|
||||
const at = nowAt ? Date.parse(nowAt) : 0
|
||||
const nowSlot = (today.data?.slots ?? []).filter((x) => x.temp_c != null).reduce<WeatherSlot | undefined>((a, b) => (!a || Math.abs(Date.parse(b.at) - at) < Math.abs(Date.parse(a.at) - at) ? b : a), undefined)
|
||||
const raining = ['rain', 'snow', 'sleet'].includes(weatherOf(nowSlot)) || !!f?.hero?.will_rain_2h
|
||||
const sunsetAt = posts.findIndex((p) => p.post_type === PostType.SUNSET)
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0 })
|
||||
@@ -623,6 +622,17 @@ export function TodayPage() {
|
||||
[9, bands?.season?.length ? <SeasonBand key="season" news={bands.season} post={f?.season_post} /> : null],
|
||||
]
|
||||
|
||||
// 사람 글 묶음은 포스트 사이사이에 하나씩: 묶음·띠·단풍 카드가 이미 붙는 자리와 바로 앞 자리는 건너뛰어 가로 목록이 연달아 나오지 않게
|
||||
const spreadTopics = [TalkTopic.OUTFIT, ...(raining ? [] : [TalkTopic.RAIN]), ...(sunsetAt < 0 ? [TalkTopic.SKY] : []), ...(posts.length < 2 ? [TalkTopic.FOLIAGE] : [])].filter((tp) => groupOf(tp).length)
|
||||
const taken = new Set([1, sunsetAt, ...bandAt.map(([at]) => at - 1)])
|
||||
const spreadAt = new Map<number, ReactNode>()
|
||||
let spreadN = 0
|
||||
for (let i = 0; i < posts.length && spreadN < spreadTopics.length; i++) {
|
||||
if (taken.has(i) || spreadAt.has(i - 1)) continue
|
||||
spreadAt.set(i, group(spreadTopics[spreadN++]))
|
||||
}
|
||||
const spreadLeft = spreadTopics.slice(spreadN).map((tp) => group(tp))
|
||||
|
||||
return (
|
||||
// 피드 칸은 전국 공통이라 지역이 바뀌어도 글 번호가 같다. 지역마다 새로 그려 넘긴 슬라이드·펼친 상태가 남지 않게 한다
|
||||
<section key={region.code} aria-label="오늘" aria-busy={load === 'loading'} className={cx('transition-opacity', feed.isPlaceholderData && 'opacity-60')}>
|
||||
@@ -631,6 +641,7 @@ export function TodayPage() {
|
||||
{mine.map((t) => (
|
||||
<TalkCard key={t.talk_id} t={t} onGone={() => setMine((m) => m.filter((x) => x.talk_id !== t.talk_id))} />
|
||||
))}
|
||||
{raining && group(TalkTopic.RAIN)}
|
||||
<MyGakRow />
|
||||
{/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */}
|
||||
{stories.some((g) => g.active) ? (
|
||||
@@ -640,6 +651,7 @@ export function TodayPage() {
|
||||
) : (
|
||||
<StateBox load={load} onRetry={() => feed.refetch()} empty="오늘 계산된 각이 없어요." hold={<PostCardSkel />} className="inset-x-3 top-3 bottom-1" />
|
||||
)}
|
||||
<NearTalks talks={groupOf(0)} loaded={talkGroups.loaded} />
|
||||
<InstallBanner />
|
||||
<div>
|
||||
{load === 'loading' && <PostsSkel />}
|
||||
@@ -650,14 +662,16 @@ export function TodayPage() {
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{i === sunsetAt && group(TalkTopic.SKY)}
|
||||
{i === 1 && <FoliageCard post={f?.foliage_post} />}
|
||||
{i > 0 && i % TALK_EVERY === 0 && talks[i / TALK_EVERY - 1] && <TalkCard t={talks[i / TALK_EVERY - 1]} />}
|
||||
{i === 1 && group(TalkTopic.FOLIAGE)}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
{spreadAt.get(i)}
|
||||
</Fragment>
|
||||
))}
|
||||
{/* 글이 모자라 끼울 자리가 없던 묶음은 맨 뒤에 */}
|
||||
{feed.isSuccess && spreadLeft}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
{load !== 'loading' && talks.slice(between).map((t) => <TalkCard key={t.talk_id} t={t} />)}
|
||||
<div ref={moreRef} aria-hidden />
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
|
||||
+80
-9
@@ -1,5 +1,6 @@
|
||||
import { useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { useEffect, useRef, useState, type ChangeEvent, type FormEvent } from 'react'
|
||||
import { Link } from 'react-router'
|
||||
import {
|
||||
addTalkMutation,
|
||||
blockTalkAuthorMutation,
|
||||
@@ -9,16 +10,16 @@ import {
|
||||
unlikeTalkMutation,
|
||||
} from '../api/client/@tanstack/react-query.gen'
|
||||
import { uploadTalkImage } from '../api/client/sdk.gen'
|
||||
import { TalkReport, type TalkData } from '../api/client/types.gen'
|
||||
import { TalkReport, TalkTopic, type TalkData } from '../api/client/types.gen'
|
||||
import { API_BASE_URL } from '../api/setup'
|
||||
import { cx } from '../lib/utils'
|
||||
import { useAuth } from './authContext'
|
||||
import { ago, kst } from './lib'
|
||||
import { useRegion } from './regionContext'
|
||||
import { useMyTalks } from './talkState'
|
||||
import { topicName, TOPICS, useMyTalks } from './talkState'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { HeartIcon } from './svg'
|
||||
import { Avatar, TAP44 } from './ui'
|
||||
import { Avatar, Rail, TAP44 } from './ui'
|
||||
|
||||
const BODY_MAX = 100
|
||||
const PHOTO_MAX = 10 * 1024 * 1024
|
||||
@@ -30,6 +31,10 @@ const WRITE_ERRORS: Record<string, string> = {
|
||||
INVALID_INPUT: '100자 안으로 써 주세요.',
|
||||
}
|
||||
|
||||
// 글이 이보다 적으면 '동네 사람들' 묶음 대신 첫 글 쓰기 카드
|
||||
const GROUP_MIN = 3
|
||||
const COMPOSE_ID = 'talk-compose'
|
||||
|
||||
const REASONS = [
|
||||
[TalkReport.ABUSE, '욕설·비하'],
|
||||
[TalkReport.SPAM, '광고·도배'],
|
||||
@@ -45,7 +50,7 @@ function slotWord(iso: string) {
|
||||
|
||||
function useRefreshTalks() {
|
||||
const queryClient = useQueryClient()
|
||||
return () => queryClient.invalidateQueries({ predicate: (q) => ['listTalks', 'listMyTalks'].includes((q.queryKey[0] as { _id?: string } | undefined)?._id ?? '') })
|
||||
return () => queryClient.invalidateQueries({ predicate: (q) => ['listTalks', 'listMyTalks', 'talkGroups'].includes((q.queryKey[0] as { _id?: string } | undefined)?._id ?? '') })
|
||||
}
|
||||
|
||||
function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
@@ -55,6 +60,7 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
const refresh = useRefreshTalks()
|
||||
const add = useMutation(addTalkMutation())
|
||||
const [text, setText] = useState('')
|
||||
const [topic, setTopic] = useState<TalkTopic>(TalkTopic.LOCAL)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [photo, setPhoto] = useState<{ file: File; src: string } | null>(null)
|
||||
const [uploading, setUploading] = useState(false)
|
||||
@@ -97,12 +103,13 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
upload().then(
|
||||
(image) =>
|
||||
add.mutate(
|
||||
{ body: { region_code: region.code, body, image } },
|
||||
{ body: { region_code: region.code, body, image, topic } },
|
||||
{
|
||||
onSuccess: (res) => {
|
||||
if (!res.result?.success) return setError(WRITE_ERRORS[res.result?.desc ?? ''] ?? '글을 올리지 못했어요. 다시 해 주세요.')
|
||||
setText('')
|
||||
setPhoto(null)
|
||||
setTopic(TalkTopic.LOCAL)
|
||||
refresh()
|
||||
if (res.talk) onDone?.(res.talk)
|
||||
},
|
||||
@@ -119,6 +126,7 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
return (
|
||||
<form onSubmit={submit} className="mx-3 rounded-[22px] bg-white p-3 shadow-[inset_0_-5px_0_var(--shade)]">
|
||||
<textarea
|
||||
id={COMPOSE_ID}
|
||||
value={text}
|
||||
onChange={(e) => setText(e.target.value)}
|
||||
onFocus={() => !loggedIn && open({ type: 'login' })}
|
||||
@@ -137,6 +145,20 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
<div className="mt-2 flex flex-wrap gap-1.5" role="radiogroup" aria-label="글 주제">
|
||||
{TOPICS.map(([k, label]) => (
|
||||
<button
|
||||
key={k}
|
||||
type="button"
|
||||
role="radio"
|
||||
aria-checked={topic === k}
|
||||
onClick={() => setTopic(k)}
|
||||
className={cx('cursor-pointer rounded-full px-2.5 py-1 text-[12.5px] font-extrabold', topic === k ? 'bg-(--ink) text-white' : 'bg-[#f3f6fb] text-(--ink2)')}
|
||||
>
|
||||
{label}
|
||||
</button>
|
||||
))}
|
||||
</div>
|
||||
<input ref={fileRef} type="file" accept="image/*" onChange={pick} hidden />
|
||||
<div className="mt-1.5 flex items-center gap-2 text-xs font-bold text-(--ink3)">
|
||||
<button type="button" onClick={() => (loggedIn ? fileRef.current?.click() : open({ type: 'login' }))} disabled={busy} className="shrink-0 cursor-pointer rounded-full bg-[#eef4fc] px-3 py-1.5 text-[13px] font-extrabold text-(--ink2) disabled:opacity-40">
|
||||
@@ -160,7 +182,7 @@ function Composer({ onDone }: { onDone?: (t: TalkData) => void }) {
|
||||
}
|
||||
|
||||
/** onGone: 내 글을 지웠을 때. 목록을 다시 받아도 빠지지 않는 곳(방금 쓴 글)에서 직접 뺀다 */
|
||||
function TalkRow({ t, onGone }: { t: TalkData; onGone?: () => void }) {
|
||||
function TalkRow({ t, onGone, compact }: { t: TalkData; onGone?: () => void; compact?: boolean }) {
|
||||
const { loggedIn } = useAuth()
|
||||
const { open } = useSheet()
|
||||
const refresh = useRefreshTalks()
|
||||
@@ -205,6 +227,7 @@ function TalkRow({ t, onGone }: { t: TalkData; onGone?: () => void }) {
|
||||
onError: () => setFailed(true),
|
||||
}
|
||||
const guard = (run: () => void) => (loggedIn ? run() : open({ type: 'login' }))
|
||||
const src = t.image?.startsWith('/v1/') ? API_BASE_URL + t.image : (t.image ?? undefined)
|
||||
|
||||
return (
|
||||
<div className="grid grid-cols-[34px_1fr_24px] items-start gap-2.5 border-b border-(--line) py-2.5 last:border-b-0">
|
||||
@@ -212,10 +235,11 @@ function TalkRow({ t, onGone }: { t: TalkData; onGone?: () => void }) {
|
||||
<div className="min-w-0">
|
||||
<small className="block text-xs font-bold text-(--ink3)">
|
||||
<b className="mr-1 font-extrabold text-(--ink)">{t.nickname}</b>
|
||||
{[t.region_name, slotWord(t.created_at), t.weather].filter(Boolean).join(' · ')}
|
||||
{[t.region_name, slotWord(t.created_at), t.weather, t.topic && t.topic !== TalkTopic.LOCAL ? topicName(t.topic) : null].filter(Boolean).join(' · ')}
|
||||
</small>
|
||||
<p className="m-0 mt-0.5 text-[14.5px] break-words whitespace-pre-wrap">{t.body}</p>
|
||||
{t.image && <img src={t.image.startsWith('/v1/') ? API_BASE_URL + t.image : t.image} alt="" loading="lazy" className="mt-2 aspect-[4/5] w-full rounded-2xl bg-[#eef4fc] object-cover" />}
|
||||
{t.image && compact && <img src={src} alt="" loading="lazy" className="float-right mt-1 ml-2 size-12 rounded-xl bg-[#eef4fc] object-cover" />}
|
||||
<p className={cx('m-0 mt-0.5 text-[14.5px] break-words whitespace-pre-wrap', compact && 'line-clamp-2')}>{t.body}</p>
|
||||
{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="mt-0.5 block text-xs font-bold text-(--ink3)">
|
||||
{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)">
|
||||
@@ -280,6 +304,53 @@ export function TalkCard({ t, onGone }: { t: TalkData; onGone?: () => void }) {
|
||||
)
|
||||
}
|
||||
|
||||
/** 오늘 피드의 사람 글 묶음: 옆으로 넘기는 카드, 끝에 그 주제 전체 보기 */
|
||||
export function TalkGroup({ title, topic, talks }: { title: string; topic?: number; talks: TalkData[] }) {
|
||||
return (
|
||||
<section aria-label={title} className="mt-3.5">
|
||||
<div className="flex items-end justify-between px-4">
|
||||
<h2 className="m-0 font-jua text-[19px] font-normal">{title}</h2>
|
||||
<Link to={topic ? `/talk?topic=${topic}` : '/talk'} className="text-[13px] font-bold text-(--ink2)">
|
||||
전체 보기
|
||||
</Link>
|
||||
</div>
|
||||
<Rail label={title}>
|
||||
{talks.map((t) => (
|
||||
<article key={`${t.talk_id}:${t.liked}:${t.like_count}`} className="w-[78%] max-w-[320px] rounded-[20px] bg-white px-3 shadow-[inset_0_-4px_0_var(--shade)]" aria-label={`${t.nickname}의 글`}>
|
||||
<TalkRow t={t} compact />
|
||||
</article>
|
||||
))}
|
||||
</Rail>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
|
||||
/** '동네 사람들' 글이 적을 때 묶음 대신: 위 쓰기 칸으로 데려간다 */
|
||||
export function FirstTalkCard() {
|
||||
const { region } = useRegion()
|
||||
const place = region.name.split(' ').at(-1)
|
||||
const go = () => {
|
||||
const el = document.getElementById(COMPOSE_ID)
|
||||
el?.scrollIntoView({ behavior: 'smooth', block: 'center' })
|
||||
el?.focus({ preventScroll: true })
|
||||
}
|
||||
return (
|
||||
<button type="button" onClick={go} className="mx-3 mt-3.5 flex w-[calc(100%-1.5rem)] cursor-pointer items-center gap-3 rounded-[22px] bg-white p-3.5 text-left shadow-[inset_0_-5px_0_var(--shade)]">
|
||||
<span className="font-jua text-[16.5px] leading-snug">
|
||||
지금 {place} 하늘 어때요?
|
||||
<small className="block font-sans text-[12.5px] font-semibold text-(--ink2)">첫 이야기를 남겨 주세요</small>
|
||||
</span>
|
||||
<span className="ml-auto shrink-0 rounded-full bg-(--orange) px-3.5 py-1.5 text-[13px] font-extrabold text-white">쓰기</span>
|
||||
</button>
|
||||
)
|
||||
}
|
||||
|
||||
/** '동네 사람들' 자리: 글이 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 />
|
||||
}
|
||||
|
||||
/** 내 정보 창의 내가 쓴 글 */
|
||||
export function MyTalks() {
|
||||
const { talks, loaded, more, loadMore } = useMyTalks()
|
||||
|
||||
@@ -1,17 +1,37 @@
|
||||
import { useInfiniteQuery } from '@tanstack/react-query'
|
||||
import { listMyTalksInfiniteOptions, listTalksInfiniteOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import { useInfiniteQuery, useQuery } from '@tanstack/react-query'
|
||||
import { listMyTalksInfiniteOptions, listTalksInfiniteOptions, talkGroupsOptions } from '../api/client/@tanstack/react-query.gen'
|
||||
import { TalkTopic, type TalkData } from '../api/client/types.gen'
|
||||
import { useRegion } from './regionContext'
|
||||
|
||||
/** 사람들이 쓴 글. 오늘 피드에 운영 포스트 사이사이 섞고, 남은 글은 피드 끝에 이어 붙인다 */
|
||||
export function useFeedTalks() {
|
||||
// 글 주제와 피드 묶음 이름
|
||||
export const TOPICS = [
|
||||
[TalkTopic.LOCAL, '동네 이야기'],
|
||||
[TalkTopic.SKY, '하늘·노을'],
|
||||
[TalkTopic.RAIN, '비·눈'],
|
||||
[TalkTopic.FOLIAGE, '단풍·꽃'],
|
||||
[TalkTopic.OUTFIT, '오늘 옷차림'],
|
||||
] as const
|
||||
export const topicName = (t?: number) => TOPICS.find(([k]) => k === t)?.[1] ?? '동네 이야기'
|
||||
|
||||
/** 오늘 피드 묶음: 0 은 '동네 사람들', 나머지는 주제별(3장 이상일 때만 옴) */
|
||||
export function useTalkGroups() {
|
||||
const { region } = useRegion()
|
||||
const q = useQuery(talkGroupsOptions({ query: { region: region.code } }))
|
||||
const groups = new Map<number, TalkData[]>((q.data?.groups ?? []).map((g) => [g.topic, g.talks ?? []]))
|
||||
return { groups, loaded: q.isSuccess }
|
||||
}
|
||||
|
||||
/** 주제별 글 페이지 목록 (topic 없으면 전체) */
|
||||
export function useTopicTalks(topic?: TalkTopic) {
|
||||
const { region } = useRegion()
|
||||
const list = useInfiniteQuery({
|
||||
...listTalksInfiniteOptions({ query: { region: region.code } }),
|
||||
...listTalksInfiniteOptions({ query: { region: region.code, ...(topic ? { topic } : {}) } }),
|
||||
initialPageParam: {},
|
||||
getNextPageParam: (last) => last.next_cursor ?? undefined,
|
||||
})
|
||||
return {
|
||||
talks: list.data?.pages.flatMap((p) => p.talks ?? []) ?? [],
|
||||
loaded: list.isSuccess,
|
||||
more: list.hasNextPage && !list.isFetchingNextPage,
|
||||
loadMore: list.fetchNextPage,
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user