batch corrections
- 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>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { Feather } from "@expo/vector-icons";
|
||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||
import axios from "axios";
|
||||
import React, { useState } from "react";
|
||||
import React, { useMemo, useState } from "react";
|
||||
import {
|
||||
ActivityIndicator,
|
||||
Alert,
|
||||
@@ -54,20 +54,20 @@ export default function PostsScreen() {
|
||||
const [filter, setFilter] = useState<FilterType>("all");
|
||||
const [refreshing, setRefreshing] = useState(false);
|
||||
|
||||
const start = new Date();
|
||||
start.setMonth(start.getMonth() - 3);
|
||||
const end = new Date();
|
||||
end.setMonth(end.getMonth() + 6);
|
||||
const { startDate, endDate } = useMemo(() => {
|
||||
const s = new Date();
|
||||
s.setMonth(s.getMonth() - 3);
|
||||
const e = new Date();
|
||||
e.setMonth(e.getMonth() + 6);
|
||||
return { startDate: s.toISOString(), endDate: e.toISOString() };
|
||||
}, []);
|
||||
|
||||
const { data: posts, isLoading, error, refetch } = useQuery<PostizPost[]>({
|
||||
queryKey: ["posts-list", !!client],
|
||||
queryKey: ["posts-list", !!client, startDate, endDate],
|
||||
queryFn: async () => {
|
||||
if (!client) return [];
|
||||
const res = await client.get("posts", {
|
||||
params: {
|
||||
startDate: start.toISOString(),
|
||||
endDate: end.toISOString(),
|
||||
},
|
||||
params: { startDate, endDate },
|
||||
});
|
||||
return Array.isArray(res.data) ? res.data : res.data?.posts ?? [];
|
||||
},
|
||||
@@ -91,9 +91,7 @@ export default function PostsScreen() {
|
||||
if (!client) return;
|
||||
try {
|
||||
await client.delete(`posts/${id}`);
|
||||
queryClient.setQueryData<PostizPost[]>(["posts-list", true], (old) =>
|
||||
(old ?? []).filter((p) => p.id !== id)
|
||||
);
|
||||
queryClient.invalidateQueries({ queryKey: ["posts-list"] });
|
||||
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
||||
} catch (e: unknown) {
|
||||
const msg = extractError(e);
|
||||
|
||||
Reference in New Issue
Block a user