fix: reschedule via delete+recreate, sort posts chrono, show account name
- Reschedule: Postiz public API v1 has no PUT/PATCH on posts; implement as delete + recreate with updated date and same content/integrations - Posts list: sort ascending by publishDate so nearest post appears first - PostCard footer: show integration name (or identifier) before the timestamp, truncated to 2 accounts with +N overflow Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -86,10 +86,15 @@ export default function PostsScreen() {
|
|||||||
staleTime: 0,
|
staleTime: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
const filteredPosts =
|
const filteredPosts = useMemo(() => {
|
||||||
|
const list =
|
||||||
filter === "all"
|
filter === "all"
|
||||||
? posts ?? []
|
? posts ?? []
|
||||||
: (posts ?? []).filter((p) => p.state === filter);
|
: (posts ?? []).filter((p) => p.state === filter);
|
||||||
|
return [...list].sort(
|
||||||
|
(a, b) => new Date(a.publishDate).getTime() - new Date(b.publishDate).getTime()
|
||||||
|
);
|
||||||
|
}, [posts, filter]);
|
||||||
|
|
||||||
const handleRefresh = async () => {
|
const handleRefresh = async () => {
|
||||||
setRefreshing(true);
|
setRefreshing(true);
|
||||||
@@ -152,8 +157,19 @@ export default function PostsScreen() {
|
|||||||
|
|
||||||
const submitReschedule = async (post: PostizPost, date: Date) => {
|
const submitReschedule = async (post: PostizPost, date: Date) => {
|
||||||
if (!client) return;
|
if (!client) return;
|
||||||
|
const integrations = post.integrations ?? (post.integration ? [post.integration] : []);
|
||||||
try {
|
try {
|
||||||
await client.put(`posts/${post.id}`, { date: date.toISOString() });
|
await client.delete(`posts/${post.id}`);
|
||||||
|
await client.post("posts", {
|
||||||
|
type: "schedule",
|
||||||
|
date: date.toISOString(),
|
||||||
|
shortLink: false,
|
||||||
|
tags: [] as string[],
|
||||||
|
posts: integrations.map((intg) => ({
|
||||||
|
integration: { id: intg.id },
|
||||||
|
value: [{ content: post.content, image: post.image ?? [] }],
|
||||||
|
})),
|
||||||
|
});
|
||||||
queryClient.invalidateQueries({ queryKey: ["posts-list"] });
|
queryClient.invalidateQueries({ queryKey: ["posts-list"] });
|
||||||
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
|
||||||
Alert.alert("Rescheduled", `Post moved to ${date.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })}`);
|
Alert.alert("Rescheduled", `Post moved to ${date.toLocaleDateString("en-US", { month: "short", day: "numeric", hour: "2-digit", minute: "2-digit" })}`);
|
||||||
|
|||||||
@@ -139,6 +139,19 @@ export function PostCard({ post, onDelete, onLongPress }: PostCardProps) {
|
|||||||
{truncatedContent}
|
{truncatedContent}
|
||||||
</Text>
|
</Text>
|
||||||
<View style={styles.footer}>
|
<View style={styles.footer}>
|
||||||
|
{integrations.length > 0 && (
|
||||||
|
<>
|
||||||
|
<Text style={[styles.accountName, { color: colors.mutedForeground }]} numberOfLines={1}>
|
||||||
|
{integrations
|
||||||
|
.slice(0, 2)
|
||||||
|
.map((i) => i.name || i.identifier || "")
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(", ")}
|
||||||
|
{integrations.length > 2 ? ` +${integrations.length - 2}` : ""}
|
||||||
|
</Text>
|
||||||
|
<Text style={[styles.dot, { color: colors.mutedForeground }]}>·</Text>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
<Feather name="clock" size={12} color={colors.mutedForeground} />
|
<Feather name="clock" size={12} color={colors.mutedForeground} />
|
||||||
<Text style={[styles.date, { color: colors.mutedForeground }]}>
|
<Text style={[styles.date, { color: colors.mutedForeground }]}>
|
||||||
{formatDate(post.publishDate)}
|
{formatDate(post.publishDate)}
|
||||||
@@ -191,6 +204,15 @@ const styles = StyleSheet.create({
|
|||||||
fontSize: 12,
|
fontSize: 12,
|
||||||
fontFamily: "Inter_400Regular",
|
fontFamily: "Inter_400Regular",
|
||||||
},
|
},
|
||||||
|
accountName: {
|
||||||
|
fontSize: 12,
|
||||||
|
fontFamily: "Inter_400Regular",
|
||||||
|
flexShrink: 1,
|
||||||
|
},
|
||||||
|
dot: {
|
||||||
|
fontSize: 12,
|
||||||
|
marginHorizontal: 3,
|
||||||
|
},
|
||||||
deleteAction: {
|
deleteAction: {
|
||||||
width: 72,
|
width: 72,
|
||||||
alignItems: "center",
|
alignItems: "center",
|
||||||
|
|||||||
Reference in New Issue
Block a user