45 lines
2.0 KiB
TypeScript
45 lines
2.0 KiB
TypeScript
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>
|
|
)
|
|
}
|