4a31ddfb2f
- PostCard: fix post.status → post.state (all posts showed Draft) - compose: remove expo-file-system File import (not installed, Expo 54 incompatible) - compose: fix native FormData upload pattern for React Native - compose: add missing Bearer prefix on upload Authorization header - posts: memoize date range and include in query key to avoid stale closures Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
196 lines
5.0 KiB
TypeScript
196 lines
5.0 KiB
TypeScript
import { Feather } from "@expo/vector-icons";
|
|
import * as Haptics from "expo-haptics";
|
|
import React, { useRef } from "react";
|
|
import {
|
|
Alert,
|
|
Animated,
|
|
StyleSheet,
|
|
Text,
|
|
TouchableOpacity,
|
|
View,
|
|
} from "react-native";
|
|
import { Swipeable } from "react-native-gesture-handler";
|
|
import { useColors } from "@/hooks/useColors";
|
|
import { PostizPost } from "@/context/PostizContext";
|
|
import { StatusBadge } from "./StatusBadge";
|
|
|
|
interface PostCardProps {
|
|
post: PostizPost;
|
|
onDelete: (id: string) => Promise<void>;
|
|
}
|
|
|
|
function formatDate(dateStr: string): string {
|
|
try {
|
|
const d = new Date(dateStr);
|
|
return d.toLocaleDateString("en-US", {
|
|
month: "short",
|
|
day: "numeric",
|
|
hour: "2-digit",
|
|
minute: "2-digit",
|
|
});
|
|
} catch {
|
|
return dateStr;
|
|
}
|
|
}
|
|
|
|
function getNetworkIcon(type?: string): React.ComponentProps<typeof Feather>["name"] {
|
|
const t = (type ?? "").toLowerCase();
|
|
if (t.includes("twitter") || t.includes("x")) return "twitter";
|
|
if (t.includes("linkedin")) return "linkedin";
|
|
if (t.includes("instagram")) return "instagram";
|
|
if (t.includes("facebook")) return "facebook";
|
|
if (t.includes("youtube")) return "youtube";
|
|
return "globe";
|
|
}
|
|
|
|
export function PostCard({ post, onDelete }: PostCardProps) {
|
|
const colors = useColors();
|
|
const swipeRef = useRef<Swipeable>(null);
|
|
|
|
const handleDelete = () => {
|
|
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Medium);
|
|
Alert.alert("Delete Post", "Are you sure you want to delete this post?", [
|
|
{
|
|
text: "Cancel",
|
|
style: "cancel",
|
|
onPress: () => swipeRef.current?.close(),
|
|
},
|
|
{
|
|
text: "Delete",
|
|
style: "destructive",
|
|
onPress: async () => {
|
|
await onDelete(post.id);
|
|
},
|
|
},
|
|
]);
|
|
};
|
|
|
|
const renderRightActions = (
|
|
_progress: Animated.AnimatedInterpolation<number>,
|
|
dragX: Animated.AnimatedInterpolation<number>
|
|
) => {
|
|
const scale = dragX.interpolate({
|
|
inputRange: [-80, 0],
|
|
outputRange: [1, 0.8],
|
|
extrapolate: "clamp",
|
|
});
|
|
return (
|
|
<TouchableOpacity
|
|
style={[styles.deleteAction, { backgroundColor: colors.destructive }]}
|
|
onPress={handleDelete}
|
|
activeOpacity={0.8}
|
|
>
|
|
<Animated.View style={{ transform: [{ scale }] }}>
|
|
<Feather name="trash-2" size={20} color="#fff" />
|
|
</Animated.View>
|
|
</TouchableOpacity>
|
|
);
|
|
};
|
|
|
|
const integrations = post.integrations ?? (post.integration ? [post.integration] : []);
|
|
const truncatedContent =
|
|
post.content.length > 140
|
|
? post.content.slice(0, 140) + "…"
|
|
: post.content;
|
|
|
|
return (
|
|
<Swipeable
|
|
ref={swipeRef}
|
|
renderRightActions={renderRightActions}
|
|
rightThreshold={40}
|
|
friction={2}
|
|
>
|
|
<View
|
|
style={[
|
|
styles.card,
|
|
{ backgroundColor: colors.card, borderBottomColor: colors.border },
|
|
]}
|
|
>
|
|
<View style={styles.header}>
|
|
<View style={styles.integrations}>
|
|
{integrations.slice(0, 3).map((intg) => (
|
|
<View
|
|
key={intg.id}
|
|
style={[
|
|
styles.networkIcon,
|
|
{ backgroundColor: colors.secondary },
|
|
]}
|
|
>
|
|
<Feather
|
|
name={getNetworkIcon(intg.type ?? intg.internalType)}
|
|
size={12}
|
|
color={colors.mutedForeground}
|
|
/>
|
|
</View>
|
|
))}
|
|
{integrations.length > 3 && (
|
|
<Text style={[styles.moreText, { color: colors.mutedForeground }]}>
|
|
+{integrations.length - 3}
|
|
</Text>
|
|
)}
|
|
</View>
|
|
<StatusBadge status={post.state} />
|
|
</View>
|
|
<Text style={[styles.content, { color: colors.foreground }]}>
|
|
{truncatedContent}
|
|
</Text>
|
|
<View style={styles.footer}>
|
|
<Feather name="clock" size={12} color={colors.mutedForeground} />
|
|
<Text style={[styles.date, { color: colors.mutedForeground }]}>
|
|
{formatDate(post.publishDate)}
|
|
</Text>
|
|
</View>
|
|
</View>
|
|
</Swipeable>
|
|
);
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
card: {
|
|
paddingHorizontal: 20,
|
|
paddingVertical: 14,
|
|
borderBottomWidth: StyleSheet.hairlineWidth,
|
|
gap: 8,
|
|
},
|
|
header: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
justifyContent: "space-between",
|
|
},
|
|
integrations: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 4,
|
|
},
|
|
networkIcon: {
|
|
width: 22,
|
|
height: 22,
|
|
borderRadius: 11,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
moreText: {
|
|
fontSize: 11,
|
|
fontFamily: "Inter_500Medium",
|
|
},
|
|
content: {
|
|
fontSize: 14,
|
|
fontFamily: "Inter_400Regular",
|
|
lineHeight: 20,
|
|
},
|
|
footer: {
|
|
flexDirection: "row",
|
|
alignItems: "center",
|
|
gap: 4,
|
|
},
|
|
date: {
|
|
fontSize: 12,
|
|
fontFamily: "Inter_400Regular",
|
|
},
|
|
deleteAction: {
|
|
width: 72,
|
|
alignItems: "center",
|
|
justifyContent: "center",
|
|
},
|
|
});
|