feat: 오늘 피드 — 사람 글을 묶음 대신 포스트처럼 두 장마다 한 장씩(큰 카드·댓글), 행사는 띠 대신 축제 전부와 팝업·전시·공연 2개씩 포스트로
- 사람 글 큰 카드: 머리줄·4:5 본문(사진, 없으면 글을 크게)·좋아요·댓글·보내기 - 사람 글 댓글: 로그인한 사람만, comment 표에 talk_id, talk.comment_count (init.sql) - '오늘 내 글'·'동네 사람들'·주제별 묶음, '이번 주 가까운 행사' 띠 제거 - 행사 포스트 자리 최대 40개, 앞쪽 절반에 다 못 들어가면 끝까지 한 장씩 걸러 - GA: feed_item_view(talk·event 노출), talk_comment
This commit is contained in:
1 parent
f6cb6f2deb
commit
dba3d78f14
22 files changed
+653
-318
No files matched your search
@@ -6,9 +6,7 @@ import {
|
||||
PostType,
|
||||
RainType,
|
||||
Sky,
|
||||
TalkTopic,
|
||||
type BandArticle,
|
||||
type BandEvent,
|
||||
type Hero as HeroData,
|
||||
type PostReaction,
|
||||
type ResWeatherToday,
|
||||
@@ -18,7 +16,6 @@ import {
|
||||
import { cx } from '../lib/utils'
|
||||
import { cardBg, kindOfHour, kst, type Load, loadOf, MEDALS, type TimeKind, WEEKDAYS } from '@nalssigak/shared/lib'
|
||||
import { fall } from './lib'
|
||||
import { useAuth } from './authContext'
|
||||
import { FoliageCard } from './foliageMap'
|
||||
import { InstallBanner } from './installBanner'
|
||||
import { MoonArt } from './moon'
|
||||
@@ -28,8 +25,8 @@ import { fromShare } from './myGakState'
|
||||
import { PostCard, PostCardSkel, PostFrame } from './Post'
|
||||
import { usePinnedLike } from './pinnedLike'
|
||||
import { ShortsRail } from './Shorts'
|
||||
import { FeedComposer, NearTalks, TalkGroup } from './talk'
|
||||
import { topicName, useTalkGroups, useTodayMyTalks } from './talkState'
|
||||
import { FeedComposer, TalkPost } from './talk'
|
||||
import { useTopicTalks } from './talkState'
|
||||
import { useLandingAbout, useRegion } from './regionContext'
|
||||
import { useSheet } from './sheetContext'
|
||||
import { useSky } from './skyContext'
|
||||
@@ -537,25 +534,6 @@ function Band({ tone, title, sub, to, children }: { tone: 1 | 2 | 3; title: stri
|
||||
)
|
||||
}
|
||||
|
||||
function EventsBand({ events }: { events: BandEvent[] }) {
|
||||
return (
|
||||
<Band tone={1} title="이번 주 가까운 행사" sub="30km 안 · 날씨까지 같이 보고 골라요" to="/week">
|
||||
<Rail>
|
||||
{events.map((e, i) => (
|
||||
<Link key={e.event_id} to="/week" className="w-[200px] overflow-hidden rounded-[22px] bg-white shadow-[inset_0_-5px_0_var(--shade),0_8px_16px_rgb(40_48_74/0.06)]">
|
||||
<Thumb image={e.image} icon={e.icon} credit={e.image_credit} className={cx('h-[116px]', `b-bg-${cardBg(e.icon, i)}`)} iconClassName="w-[76px]">
|
||||
<span className={cx('absolute top-2.5 left-2.5 rounded-full px-2 py-[3px] text-[11.5px] font-extrabold text-white', e.status_label === '진행 중' ? 'bg-[#1f9d62]' : 'bg-(--orange)')}>{e.status_label}</span>
|
||||
</Thumb>
|
||||
<span className="block px-3 pt-2.5 pb-3">
|
||||
<b className="block font-jua text-[16.5px] leading-snug font-normal">{e.name}</b>
|
||||
</span>
|
||||
</Link>
|
||||
))}
|
||||
</Rail>
|
||||
</Band>
|
||||
)
|
||||
}
|
||||
|
||||
function SeasonBand({ news }: { news: BandArticle[] }) {
|
||||
const { open } = useSheet()
|
||||
return (
|
||||
@@ -575,6 +553,29 @@ function SeasonBand({ news }: { news: BandArticle[] }) {
|
||||
)
|
||||
}
|
||||
|
||||
// 사람 글은 포스트 두 장마다 한 장씩 최신순으로 끼운다
|
||||
const TALK_EVERY = 2
|
||||
|
||||
/** 피드에 섞인 사람 글·행사 포스트가 처음 반쯤 보일 때 한 번 GA 로 보낸다 */
|
||||
function Seen({ item, position, children }: { item: 'talk' | 'event'; position: number; children: ReactNode }) {
|
||||
const ref = useRef<HTMLDivElement>(null)
|
||||
useEffect(() => {
|
||||
const el = ref.current
|
||||
if (!el) return
|
||||
const io = new IntersectionObserver(
|
||||
([e]) => {
|
||||
if (!e.isIntersecting) return
|
||||
track('feed_item_view', { item_type: item, position })
|
||||
io.disconnect()
|
||||
},
|
||||
{ threshold: 0.5 },
|
||||
)
|
||||
io.observe(el)
|
||||
return () => io.disconnect()
|
||||
}, [item, position])
|
||||
return <div ref={ref}>{children}</div>
|
||||
}
|
||||
|
||||
export function TodayPage() {
|
||||
const { region } = useRegion()
|
||||
const about = useLandingAbout()
|
||||
@@ -589,20 +590,10 @@ export function TodayPage() {
|
||||
const bands = f?.bands
|
||||
const nowAt = f?.hero?.now_at
|
||||
const load = loadOf(feed)
|
||||
// 사람 글은 묶음으로: '동네 사람들'은 오늘의 각 아래, 주제 묶음은 같은 주제 포스트 아래. 오늘 쓴 내 글은 글쓰기 칸 아래 '오늘 내 글'에 따로 있으니 빼고
|
||||
const { loggedIn } = useAuth()
|
||||
const mine = useTodayMyTalks(loggedIn)
|
||||
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)
|
||||
const talks = useTopicTalks().talks
|
||||
const talkAt = (i: number) => ((i + 1) % TALK_EVERY === 0 ? talks[(i + 1) / TALK_EVERY - 1] : undefined)
|
||||
const talkFrom = Math.floor(posts.length / TALK_EVERY)
|
||||
const eventNo = new Map(posts.filter((p) => p.post_type === PostType.EVENT).map((p, n) => [p.post_id, n + 1]))
|
||||
|
||||
useEffect(() => {
|
||||
window.scrollTo({ top: 0 })
|
||||
@@ -619,22 +610,8 @@ export function TodayPage() {
|
||||
if (g) open({ type: 'mix', shared: g })
|
||||
}, [open])
|
||||
|
||||
// 디자인대로 3·6·9번째 글 뒤에 띠를 넣고, 글이 모자라면 남은 띠는 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [
|
||||
[3, bands?.events?.length ? <EventsBand key="events" events={bands.events} /> : null],
|
||||
[9, bands?.season?.length ? <SeasonBand key="season" news={bands.season} /> : null],
|
||||
]
|
||||
|
||||
// 사람 글 묶음은 포스트 사이사이에 하나씩: 묶음·띠·단풍 카드가 이미 붙는 자리와 바로 앞 자리는 건너뛰어 가로 목록이 연달아 나오지 않게
|
||||
const spreadTopics = [TalkTopic.OUTFIT, ...(raining ? [] : [TalkTopic.RAIN]), ...(sunsetAt < 0 ? [TalkTopic.SKY] : [])].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))
|
||||
// 9번째 글 뒤에 계절 이야기 띠를 넣고, 글이 모자라면 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [[9, bands?.season?.length ? <SeasonBand key="season" news={bands.season} /> : null]]
|
||||
|
||||
return (
|
||||
// 피드 칸은 전국 공통이라 지역이 바뀌어도 글 번호가 같다. 지역마다 새로 그려 넘긴 슬라이드·펼친 상태가 남지 않게 한다
|
||||
@@ -643,8 +620,6 @@ export function TodayPage() {
|
||||
<TodayIcons />
|
||||
<ShortsRail />
|
||||
<FeedComposer />
|
||||
{mine.length > 0 && <TalkGroup title="오늘 내 글" talks={mine} href="/talk?mine=1" />}
|
||||
{raining && group(TalkTopic.RAIN)}
|
||||
<div id={MY_GAK_ID} className="scroll-mt-16">
|
||||
<MyGakRow />
|
||||
</div>
|
||||
@@ -656,7 +631,6 @@ 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 />}
|
||||
@@ -664,23 +638,36 @@ export function TodayPage() {
|
||||
{load !== 'loading' && !posts.length && (
|
||||
<StateBox load="ready" empty={load === 'ready' ? '오늘 올라온 글이 아직 없어요.' : '글을 불러오지 못했어요.'} hold={<PostsSkel />} className="inset-x-3 top-3.5 bottom-auto" />
|
||||
)}
|
||||
{/* 단풍철엔 단풍 지도를 포스트 맨 앞에, 단풍 이야기 묶음은 바로 아래 */}
|
||||
{load !== 'loading' && posts.length > 0 && (
|
||||
<>
|
||||
<FoliageCard />
|
||||
{group(TalkTopic.FOLIAGE)}
|
||||
</>
|
||||
)}
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{i === sunsetAt && group(TalkTopic.SKY)}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
{spreadAt.get(i)}
|
||||
</Fragment>
|
||||
))}
|
||||
{/* 글이 모자라 끼울 자리가 없던 묶음은 맨 뒤에 */}
|
||||
{feed.isSuccess && spreadLeft}
|
||||
{/* 단풍철엔 단풍 지도를 포스트 맨 앞에 */}
|
||||
{load !== 'loading' && posts.length > 0 && <FoliageCard />}
|
||||
{posts.map((p, i) => {
|
||||
const t = talkAt(i)
|
||||
const ev = eventNo.get(p.post_id)
|
||||
return (
|
||||
<Fragment key={p.post_id}>
|
||||
{ev ? (
|
||||
<Seen item="event" position={ev}>
|
||||
<PostCard post={p} />
|
||||
</Seen>
|
||||
) : (
|
||||
<PostCard post={p} />
|
||||
)}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
{t && (
|
||||
<Seen item="talk" position={(i + 1) / TALK_EVERY}>
|
||||
<TalkPost t={t} />
|
||||
</Seen>
|
||||
)}
|
||||
</Fragment>
|
||||
)
|
||||
})}
|
||||
{/* 포스트가 모자라 끼울 자리가 없던 사람 글은 맨 뒤에 */}
|
||||
{feed.isSuccess &&
|
||||
talks.slice(talkFrom).map((t, n) => (
|
||||
<Seen key={t.talk_id} item="talk" position={talkFrom + n + 1}>
|
||||
<TalkPost t={t} />
|
||||
</Seen>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
</div>
|
||||
{about && (
|
||||
|
||||
Reference in new issue
Block a user