feat: 앱 동네 이야기 — /talk 주제별 글·내 글, 오늘 피드 쓰기 칸과 포스트 두 장마다 사람 글, 사진 올리기(expo-image-picker, 카메라·마이크 권한 없음), 이야기 댓글·좋아요·신고·안 보기·지우기, 내 정보 내 글. 기념일 목록을 shared로 (GA talk_post·talk_comment·feed_item_view, like·report·block talk)
Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
1 parent
e40a9a0539
commit
c15f045c64
16 files changed
+941
-300
No files matched your search
@@ -1,17 +1,53 @@
|
||||
import { getFeedOptions, getWeatherTodayOptions } from '@nalssigak/shared/api/client/@tanstack/react-query.gen';
|
||||
import { PostType } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { kst, loadOf } from '@nalssigak/shared/lib';
|
||||
import { atSlot, PREVIEW } from '@nalssigak/shared/lib/today';
|
||||
import { useQuery } from '@tanstack/react-query';
|
||||
import { Fragment, type ReactNode } from 'react';
|
||||
import { RefreshControl, ScrollView } from 'react-native';
|
||||
import { Fragment, useRef, type ReactNode } from 'react';
|
||||
import { RefreshControl, ScrollView, View, type LayoutRectangle } from 'react-native';
|
||||
|
||||
import { isAppPost, PostCard, PostCardSkel } from '@/components/post/post-card';
|
||||
import { Composer, TalkPost } from '@/components/talk/talk';
|
||||
import { GakCard } from '@/components/today/gak-card';
|
||||
import { Hero } from '@/components/today/hero';
|
||||
import { SeasonBand } from '@/components/today/rails';
|
||||
import { StateBox } from '@/components/ui';
|
||||
import { track } from '@/lib/analytics';
|
||||
import { useRegion } from '@/lib/region';
|
||||
import { useSky } from '@/lib/sky';
|
||||
import { useTopicTalks } from '@/lib/talk';
|
||||
|
||||
// 사람 글은 포스트 두 장마다 한 장씩 최신순으로 끼운다
|
||||
const TALK_EVERY = 2;
|
||||
|
||||
type Spot = { item: 'talk' | 'event'; position: number; y: number; h: number };
|
||||
|
||||
/** 피드에 섞인 사람 글·행사 포스트가 처음 반쯤 보일 때 한 번 GA 로 보낸다 (웹 Seen) */
|
||||
function useSeen() {
|
||||
const spots = useRef(new Map<string, Spot>());
|
||||
const sent = useRef(new Set<string>());
|
||||
const view = useRef({ y: 0, h: 0 });
|
||||
const check = () => {
|
||||
const { y, h } = view.current;
|
||||
if (!h) return;
|
||||
for (const [key, s] of spots.current) {
|
||||
if (sent.current.has(key) || !s.h) continue;
|
||||
const shown = Math.min(y + h, s.y + s.h) - Math.max(y, s.y);
|
||||
if (shown < s.h / 2) continue;
|
||||
sent.current.add(key);
|
||||
track('feed_item_view', { item_type: s.item, position: s.position });
|
||||
}
|
||||
};
|
||||
const at = (item: Spot['item'], position: number) => (l: LayoutRectangle) => {
|
||||
spots.current.set(`${item}:${position}`, { item, position, y: l.y, h: l.height });
|
||||
check();
|
||||
};
|
||||
const onScroll = (y: number, h: number) => {
|
||||
view.current = { y, h };
|
||||
check();
|
||||
};
|
||||
return { at, onScroll };
|
||||
}
|
||||
|
||||
export default function TodayScreen() {
|
||||
const { region } = useRegion();
|
||||
@@ -25,15 +61,31 @@ export default function TodayScreen() {
|
||||
const bands = f?.bands;
|
||||
const nowAt = f?.hero?.now_at;
|
||||
const load = loadOf(feed);
|
||||
const refresh = () => Promise.all([feed.refetch(), today.refetch()]);
|
||||
const talkList = useTopicTalks();
|
||||
const talks = talkList.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]));
|
||||
const seen = useSeen();
|
||||
const refresh = () => Promise.all([feed.refetch(), today.refetch(), talkList.refetch()]);
|
||||
|
||||
// 웹처럼 9번째 글 뒤에 계절 이야기 띠를 넣고, 글이 모자라면 맨 뒤에 붙인다
|
||||
const bandAt: [number, ReactNode][] = [[9, bands?.season?.length ? <SeasonBand news={bands.season} /> : null]];
|
||||
|
||||
return (
|
||||
// 지역마다 새로 그려 넘긴 슬라이드 위치가 남지 않게 한다
|
||||
<ScrollView key={region.code} contentContainerClassName="pb-6" refreshControl={<RefreshControl refreshing={feed.isRefetching && !feed.isPlaceholderData} onRefresh={refresh} />} style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}>
|
||||
<ScrollView
|
||||
key={region.code}
|
||||
contentContainerClassName="pb-6"
|
||||
refreshControl={<RefreshControl refreshing={feed.isRefetching && !feed.isPlaceholderData} onRefresh={refresh} />}
|
||||
style={{ opacity: feed.isPlaceholderData ? 0.6 : 1 }}
|
||||
keyboardShouldPersistTaps="handled"
|
||||
scrollEventThrottle={200}
|
||||
onLayout={(e) => seen.onScroll(0, e.nativeEvent.layout.height)}
|
||||
onScroll={(e) => seen.onScroll(e.nativeEvent.contentOffset.y, e.nativeEvent.layoutMeasurement.height)}
|
||||
>
|
||||
<Hero hero={f?.hero} post={f?.hero_post} today={today.data} ranked={stories} feedLoad={load} todayLoad={loadOf(today)} />
|
||||
<Composer />
|
||||
{/* 실패 안내는 여기 한 번만, 각 카드 스켈레톤과 같은 크기로 */}
|
||||
{stories.some((g) => g.active) ? (
|
||||
<GakCard items={stories} post={f?.gak_post} place={region.name.split(' ').at(-1)!} at={sloted ? `${PREVIEW[preview].label} 기준` : nowAt ? `${kst(nowAt).h}시 기준` : '오늘 기준'} />
|
||||
@@ -62,12 +114,34 @@ export default function TodayScreen() {
|
||||
boxClassName="inset-x-3 top-3.5"
|
||||
/>
|
||||
)}
|
||||
{posts.map((p, i) => (
|
||||
<Fragment key={p.post_id}>
|
||||
<PostCard post={p} />
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
</Fragment>
|
||||
))}
|
||||
{posts.map((p, i) => {
|
||||
const t = talkAt(i);
|
||||
const ev = eventNo.get(p.post_id);
|
||||
return (
|
||||
<Fragment key={p.post_id}>
|
||||
{ev ? (
|
||||
<View onLayout={(e) => seen.at('event', ev)(e.nativeEvent.layout)}>
|
||||
<PostCard post={p} />
|
||||
</View>
|
||||
) : (
|
||||
<PostCard post={p} />
|
||||
)}
|
||||
{bandAt.find(([at]) => at === i + 1)?.[1]}
|
||||
{t && (
|
||||
<View onLayout={(e) => seen.at('talk', (i + 1) / TALK_EVERY)(e.nativeEvent.layout)}>
|
||||
<TalkPost key={`${t.talk_id}:${t.liked}:${t.like_count}`} t={t} />
|
||||
</View>
|
||||
)}
|
||||
</Fragment>
|
||||
);
|
||||
})}
|
||||
{/* 포스트가 모자라 끼울 자리가 없던 사람 글은 맨 뒤에 */}
|
||||
{feed.isSuccess &&
|
||||
talks.slice(talkFrom).map((t, n) => (
|
||||
<View key={t.talk_id} onLayout={(e) => seen.at('talk', talkFrom + n + 1)(e.nativeEvent.layout)}>
|
||||
<TalkPost t={t} />
|
||||
</View>
|
||||
))}
|
||||
{feed.isSuccess && bandAt.filter(([at]) => at > posts.length).map(([at, node]) => <Fragment key={at}>{node}</Fragment>)}
|
||||
</ScrollView>
|
||||
);
|
||||
|
||||
Reference in new issue
Block a user