This repository has been archived on 2026-11-17. You can view files and clone it, but cannot push or open issues or pull requests.
caelum0x bfc29616b7 feat: round-7 external harvest (18 features, all products green)
- gitgram-web (4): external link-preview/unfurl cards, rich inline embed players
  (YouTube/Twitch/Spotify/Vimeo)
- gitgram-backend (1): natural-language feed filtering (preferredLangOnly) + Post.contentLanguage
- gitgram-mobile (4): notification grouping/aggregation, shared timeAgo util
- aitm-api (7): GitNexus graph-RAG query + context retrieval endpoints (flagship surface)
- aitm-mcp (2): beads_claim atomic claim-for-work tool + brief-deps projection

Note: gitgram-backend adds Post.contentLanguage — run prisma migrate at deploy.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-28 19:17:27 +03:00

231 lines
5.3 KiB
TypeScript

import React, { useState } from 'react';
import {
ActivityIndicator,
StyleSheet,
Text,
TouchableOpacity,
View,
} from 'react-native';
import { Image } from 'expo-image';
import { useRouter } from 'expo-router';
import { logger } from '../../utils/logger';
import { timeAgo } from '../../utils/timeAgo';
import { postService } from '../../services/postService';
interface PostAuthor {
username: string;
avatar?: string;
}
interface Post {
id: string;
content: string;
author: PostAuthor;
likes: number;
commentsCount: number;
createdAt: string;
}
interface PostCardProps {
post: Post;
}
export default function PostCard({ post }: PostCardProps) {
const router = useRouter();
const [likes, setLikes] = useState(post.likes);
const [liked, setLiked] = useState(false);
const [likeLoading, setLikeLoading] = useState(false);
const handleLike = async () => {
if (likeLoading) return;
const prevLiked = liked;
const prevLikes = likes;
setLiked(!prevLiked);
setLikes(prev => (!prevLiked ? prev + 1 : prev - 1));
setLikeLoading(true);
try {
const result = await postService.likePost(post.id);
setLiked(result.liked);
setLikes(
result.likesCount !== undefined
? result.likesCount
: result.liked ? prevLikes + 1 : prevLikes - 1,
);
} catch (error: unknown) {
setLiked(prevLiked);
setLikes(prevLikes);
logger.error('PostCard: like failed', error);
} finally {
setLikeLoading(false);
}
};
const handleCardPress = () => {
router.push(`/post/${post.id}`);
};
const handleCommentPress = () => {
router.push(`/post/${post.id}`);
};
return (
<TouchableOpacity
style={styles.container}
onPress={handleCardPress}
activeOpacity={0.92}
>
{/* Header */}
<View style={styles.header}>
{post.author.avatar ? (
<Image
source={{ uri: post.author.avatar }}
style={styles.avatar}
contentFit="cover"
transition={150}
cachePolicy="memory-disk"
/>
) : (
<View style={styles.avatarPlaceholder}>
<Text style={styles.avatarInitial}>
{post.author.username[0].toUpperCase()}
</Text>
</View>
)}
<View style={styles.headerText}>
<Text style={styles.username} numberOfLines={1}>
{post.author.username}
</Text>
<Text style={styles.timestamp}>
{timeAgo(post.createdAt)}
</Text>
</View>
</View>
{/* Content */}
<Text style={styles.content} numberOfLines={4}>
{post.content}
</Text>
{/* Action Row */}
<View style={styles.actionRow}>
<TouchableOpacity
style={styles.actionBtn}
onPress={handleLike}
disabled={likeLoading}
activeOpacity={0.75}
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
>
{likeLoading ? (
<ActivityIndicator size="small" color="#7C3AED" />
) : (
<Text style={styles.actionIcon}>{liked ? '❤️' : '🤍'}</Text>
)}
<Text style={[styles.actionCount, liked && styles.actionCountActive]}>
{likes > 0 ? likes.toLocaleString() : ''}
</Text>
</TouchableOpacity>
<TouchableOpacity
style={styles.actionBtn}
onPress={handleCommentPress}
activeOpacity={0.75}
hitSlop={{ top: 8, bottom: 8, left: 8, right: 8 }}
>
<Text style={styles.actionIcon}>💬</Text>
<Text style={styles.actionCount}>
{post.commentsCount > 0 ? post.commentsCount.toLocaleString() : ''}
</Text>
</TouchableOpacity>
</View>
</TouchableOpacity>
);
}
const AVATAR_SIZE = 40;
const styles = StyleSheet.create({
container: {
backgroundColor: '#16213E',
borderRadius: 14,
padding: 14,
marginHorizontal: 16,
marginVertical: 6,
borderWidth: 1,
borderColor: '#0F3460',
},
header: {
flexDirection: 'row',
alignItems: 'center',
marginBottom: 10,
gap: 10,
},
avatar: {
width: AVATAR_SIZE,
height: AVATAR_SIZE,
borderRadius: AVATAR_SIZE / 2,
},
avatarPlaceholder: {
width: AVATAR_SIZE,
height: AVATAR_SIZE,
borderRadius: AVATAR_SIZE / 2,
backgroundColor: '#7C3AED',
alignItems: 'center',
justifyContent: 'center',
},
avatarInitial: {
color: '#fff',
fontSize: 16,
fontWeight: '700',
},
headerText: {
flex: 1,
},
username: {
color: '#E2E8F0',
fontSize: 14,
fontWeight: '700',
lineHeight: 18,
},
timestamp: {
color: '#64748B',
fontSize: 12,
lineHeight: 16,
marginTop: 1,
},
content: {
color: '#CBD5E1',
fontSize: 14,
lineHeight: 22,
marginBottom: 12,
},
actionRow: {
flexDirection: 'row',
alignItems: 'center',
gap: 20,
borderTopWidth: 1,
borderTopColor: '#0F3460',
paddingTop: 10,
},
actionBtn: {
flexDirection: 'row',
alignItems: 'center',
gap: 5,
minHeight: 28,
},
actionIcon: {
fontSize: 18,
},
actionCount: {
color: '#64748B',
fontSize: 13,
fontWeight: '500',
},
actionCountActive: {
color: '#E879A0',
},
});