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>
|
||||
);
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
import type { TalkTopic } from '@nalssigak/shared/api/client/types.gen';
|
||||
import { router, useLocalSearchParams } from 'expo-router';
|
||||
import { FlatList, Pressable, RefreshControl, ScrollView, View } from 'react-native';
|
||||
|
||||
import { ScreenHeader } from '@/components/screen-header';
|
||||
import { Composer, TalkCard } from '@/components/talk/talk';
|
||||
import { Text } from '@/components/text';
|
||||
import { Sec } from '@/components/ui';
|
||||
import { useAuth } from '@/lib/auth';
|
||||
import { useSheet } from '@/lib/sheet';
|
||||
import { openTopics, TOPICS, useMyTalks, useTopicTalks } from '@/lib/talk';
|
||||
|
||||
type Tab = TalkTopic | 'all' | 'mine';
|
||||
|
||||
/** 주제별 사람 글: 위 주제 탭(한 줄 가로로 밀기, 끝에 '내 글'), 아래 글 목록. ?topic= · ?mine=1 로 연다 (웹 TalkPage) */
|
||||
export default function TalkScreen() {
|
||||
const params = useLocalSearchParams<{ topic?: string; mine?: string }>();
|
||||
const { loggedIn } = useAuth();
|
||||
const { open } = useSheet();
|
||||
const raw = Number(params.topic);
|
||||
const tab: Tab = params.mine ? 'mine' : TOPICS.some(([k]) => k === raw) ? (raw as TalkTopic) : 'all';
|
||||
const topicList = useTopicTalks(tab === 'all' || tab === 'mine' ? undefined : tab);
|
||||
const mineList = useMyTalks(tab === 'mine' && loggedIn);
|
||||
const { talks, loaded, more, loadMore } = tab === 'mine' ? mineList : topicList;
|
||||
const tabs: (readonly [Tab, string])[] = [['all', '전체'], ...openTopics(), ['mine', '내 글']];
|
||||
const go = (k: Tab) => router.setParams(k === 'mine' ? { mine: '1', topic: undefined } : k === 'all' ? { mine: undefined, topic: undefined } : { mine: undefined, topic: String(k) });
|
||||
|
||||
const head = (
|
||||
<View>
|
||||
<Sec title="동네 사람들 글" sub="가까운 동네 글부터 보여요" />
|
||||
<View accessibilityRole="tablist" accessibilityLabel="글 주제">
|
||||
<ScrollView horizontal showsHorizontalScrollIndicator={false} contentContainerClassName="gap-1.5 px-4 pb-1">
|
||||
{tabs.map(([k, label]) => (
|
||||
<Pressable key={label} onPress={() => go(k)} accessibilityRole="tab" accessibilityState={{ selected: tab === k }} className={`rounded-full px-3 py-1.5 ${tab === k ? 'bg-ink-btn' : 'bg-card'}`}>
|
||||
<Text className={`text-[13px] font-extrabold ${tab === k ? 'text-white' : 'text-ink2'}`}>{label}</Text>
|
||||
</Pressable>
|
||||
))}
|
||||
</ScrollView>
|
||||
</View>
|
||||
<Composer />
|
||||
{tab === 'mine' && !loggedIn ? (
|
||||
<Text className="mx-4 mt-6 text-center text-[14px] font-semibold text-ink3">
|
||||
로그인하면 내가 쓴 글을 모아 볼 수 있어요.{' '}
|
||||
<Text onPress={() => open({ type: 'login' })} className="font-extrabold text-orange">
|
||||
로그인
|
||||
</Text>
|
||||
</Text>
|
||||
) : (
|
||||
loaded && !talks.length && <Text className="mx-4 mt-6 text-center text-[14px] font-semibold text-ink3">{tab === 'mine' ? '아직 쓴 글이 없어요. 위 칸에서 첫 글을 써 주세요.' : '아직 이 주제 글이 없어요. 위 칸에서 첫 글을 써 주세요.'}</Text>
|
||||
)}
|
||||
</View>
|
||||
);
|
||||
|
||||
return (
|
||||
<View className="flex-1">
|
||||
<ScreenHeader title="동네 이야기" />
|
||||
<FlatList
|
||||
data={talks}
|
||||
keyExtractor={(t) => `${t.talk_id}:${t.liked}:${t.like_count}`}
|
||||
renderItem={({ item }) => <TalkCard t={item} />}
|
||||
ListHeaderComponent={head}
|
||||
contentContainerClassName="pb-8"
|
||||
keyboardShouldPersistTaps="handled"
|
||||
// 목록 끝이 가까워지면 다음 쪽을 받는다 (글이 많아도 버튼 없이 이어서)
|
||||
onEndReached={() => more && loadMore()}
|
||||
onEndReachedThreshold={1}
|
||||
refreshControl={tab !== 'mine' ? <RefreshControl refreshing={topicList.refetching} onRefresh={() => topicList.refetch()} /> : undefined}
|
||||
/>
|
||||
</View>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user