80 lines
4.0 KiB
TypeScript
80 lines
4.0 KiB
TypeScript
import type { PostReaction } from '@nalssigak/shared/api/client/types.gen';
|
|
import type { PinnedKey } from '@nalssigak/shared/lib/analytics';
|
|
import { LinearGradient } from 'expo-linear-gradient';
|
|
import { useRef, type ReactNode } from 'react';
|
|
import { Pressable, View } from 'react-native';
|
|
import { useCSSVariable } from 'uniwind';
|
|
|
|
import { CommentIcon, HeartIcon, SendIcon } from '@/components/post/icons';
|
|
import { Text } from '@/components/text';
|
|
import { Ic } from '@/components/ui';
|
|
import { usePinnedLike } from '@/lib/pinned-like';
|
|
import { useSheet } from '@/lib/sheet';
|
|
import { useShare } from '@/lib/share-image';
|
|
import { SITE_URL } from '@/lib/site';
|
|
|
|
type Props = { title: string; account: string; avatar: string; caption?: string; more?: ReactNode; pinned?: { key: PinnedKey; post?: PostReaction | null }; children: ReactNode };
|
|
|
|
/** 오늘의 각처럼 포스트 틀(머리줄·버튼줄·글 한 줄)만 빌려 쓰는 카드 (웹 PostFrame). 좋아요·댓글은 피드의 반응 칸(pinned)에 붙는다 */
|
|
export function PostFrame({ title, account, avatar, caption, more, pinned, children }: Props) {
|
|
const { open } = useSheet();
|
|
const [ink, heart] = useCSSVariable(['--color-ink', '--color-heart']).map(String);
|
|
const like = usePinnedLike(pinned?.key ?? 'gak_post', pinned?.post);
|
|
const postId = pinned?.post?.post_id;
|
|
const shot = useRef<View>(null);
|
|
const shareView = useShare();
|
|
const share = () => void shareView(shot, { title, message: `${title} · 날씨각 ${SITE_URL}` });
|
|
|
|
return (
|
|
<View className="mt-3.5 border-y border-line bg-card" accessibilityLabel={title}>
|
|
<View className="flex-row items-center gap-2.5 px-3 py-2.5">
|
|
<View className="size-[34px] rounded-full p-0.5">
|
|
<LinearGradient colors={['#ff7a45', '#ffc86e', '#8fcaff']} start={{ x: 0, y: 0 }} end={{ x: 1, y: 1 }} style={{ position: 'absolute', inset: 0, borderRadius: 17 }} />
|
|
<View className="flex-1 items-center justify-center rounded-full bg-card">
|
|
<Ic name={avatar} size={22} />
|
|
</View>
|
|
</View>
|
|
<View>
|
|
<Text className="text-sm leading-tight font-extrabold text-ink">날씨각</Text>
|
|
<Text className="text-xs font-semibold text-ink2">{account}</Text>
|
|
</View>
|
|
</View>
|
|
<View ref={shot} collapsable={false}>
|
|
{children}
|
|
</View>
|
|
<View className="flex-row items-center gap-3.5 px-3 pt-2.5 pb-1">
|
|
{postId != null && (
|
|
<>
|
|
<Pressable onPress={like.toggle} hitSlop={8} accessibilityRole="button" accessibilityState={{ selected: like.liked }} accessibilityLabel="좋아요">
|
|
<HeartIcon size={26} color={like.liked ? heart : ink} filled={like.liked} />
|
|
</Pressable>
|
|
<Pressable onPress={() => open({ type: 'comments', postId })} hitSlop={8} accessibilityRole="button" accessibilityLabel="댓글 보기">
|
|
<CommentIcon size={26} color={ink} />
|
|
</Pressable>
|
|
</>
|
|
)}
|
|
<Pressable onPress={share} hitSlop={8} accessibilityRole="button" accessibilityLabel="보내기">
|
|
<SendIcon size={26} color={ink} />
|
|
</Pressable>
|
|
{more != null && <View className="ml-auto">{more}</View>}
|
|
</View>
|
|
{postId != null && (
|
|
<Text className={`px-3 py-0.5 text-sm font-extrabold ${like.failed ? 'text-heart' : 'text-ink'}`} accessibilityRole={like.failed ? 'alert' : undefined}>
|
|
{like.failed ? '좋아요를 반영하지 못했어요. 다시 해 주세요.' : `좋아요 ${like.count.toLocaleString()}개`}
|
|
</Text>
|
|
)}
|
|
{!!caption && (
|
|
<Text className="px-3 pt-0.5 pb-3 text-sm text-ink">
|
|
<Text className="font-extrabold">날씨각 </Text>
|
|
{caption}
|
|
</Text>
|
|
)}
|
|
{postId != null && (
|
|
<Pressable onPress={() => open({ type: 'comments', postId })}>
|
|
<Text className="px-3 pb-3 text-sm font-semibold text-ink3">{pinned?.post?.comment_count ? `댓글 ${pinned.post.comment_count}개 모두 보기` : '첫 댓글 남기기'}</Text>
|
|
</Pressable>
|
|
)}
|
|
</View>
|
|
);
|
|
}
|