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:
@@ -4,7 +4,6 @@ import DateTimePicker from "@react-native-community/datetimepicker";
|
|||||||
import * as Haptics from "expo-haptics";
|
import * as Haptics from "expo-haptics";
|
||||||
import { Image } from "expo-image";
|
import { Image } from "expo-image";
|
||||||
import * as ImagePicker from "expo-image-picker";
|
import * as ImagePicker from "expo-image-picker";
|
||||||
import { File } from "expo-file-system";
|
|
||||||
import { fetch as expoFetch } from "expo/fetch";
|
import { fetch as expoFetch } from "expo/fetch";
|
||||||
import React, { useState } from "react";
|
import React, { useState } from "react";
|
||||||
import {
|
import {
|
||||||
@@ -88,12 +87,15 @@ export default function ComposeScreen() {
|
|||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
formData.append("file", blob, "upload.jpg");
|
formData.append("file", blob, "upload.jpg");
|
||||||
} else {
|
} else {
|
||||||
const file = new File(imageUri);
|
formData.append("file", {
|
||||||
formData.append("file", file as unknown as Blob);
|
uri: imageUri,
|
||||||
|
name: "upload.jpg",
|
||||||
|
type: "image/jpeg",
|
||||||
|
} as unknown as Blob);
|
||||||
}
|
}
|
||||||
const uploadRes = await expoFetch(`${baseUrl}/upload`, {
|
const uploadRes = await expoFetch(`${baseUrl}/upload`, {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: { Authorization: apiKey },
|
headers: { Authorization: `Bearer ${apiKey}` },
|
||||||
body: formData,
|
body: formData,
|
||||||
});
|
});
|
||||||
const data = await uploadRes.json() as PostizUploadResult;
|
const data = await uploadRes.json() as PostizUploadResult;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Feather } from "@expo/vector-icons";
|
import { Feather } from "@expo/vector-icons";
|
||||||
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
import { useQuery, useQueryClient } from "@tanstack/react-query";
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import React, { useState } from "react";
|
import React, { useMemo, useState } from "react";
|
||||||
import {
|
import {
|
||||||
ActivityIndicator,
|
ActivityIndicator,
|
||||||
Alert,
|
Alert,
|
||||||
@@ -54,20 +54,20 @@ export default function PostsScreen() {
|
|||||||
const [filter, setFilter] = useState<FilterType>("all");
|
const [filter, setFilter] = useState<FilterType>("all");
|
||||||
const [refreshing, setRefreshing] = useState(false);
|
const [refreshing, setRefreshing] = useState(false);
|
||||||
|
|
||||||
const start = new Date();
|
const { startDate, endDate } = useMemo(() => {
|
||||||
start.setMonth(start.getMonth() - 3);
|
const s = new Date();
|
||||||
const end = new Date();
|
s.setMonth(s.getMonth() - 3);
|
||||||
end.setMonth(end.getMonth() + 6);
|
const e = new Date();
|
||||||
|
e.setMonth(e.getMonth() + 6);
|
||||||
|
return { startDate: s.toISOString(), endDate: e.toISOString() };
|
||||||
|
}, []);
|
||||||
|
|
||||||
const { data: posts, isLoading, error, refetch } = useQuery<PostizPost[]>({
|
const { data: posts, isLoading, error, refetch } = useQuery<PostizPost[]>({
|
||||||
queryKey: ["posts-list", !!client],
|
queryKey: ["posts-list", !!client, startDate, endDate],
|
||||||
queryFn: async () => {
|
queryFn: async () => {
|
||||||
if (!client) return [];
|
if (!client) return [];
|
||||||
const res = await client.get("posts", {
|
const res = await client.get("posts", {
|
||||||
params: {
|
params: { startDate, endDate },
|
||||||
startDate: start.toISOString(),
|
|
||||||
endDate: end.toISOString(),
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
return Array.isArray(res.data) ? res.data : res.data?.posts ?? [];
|
return Array.isArray(res.data) ? res.data : res.data?.posts ?? [];
|
||||||
},
|
},
|
||||||
@@ -91,9 +91,7 @@ export default function PostsScreen() {
|
|||||||
if (!client) return;
|
if (!client) return;
|
||||||
try {
|
try {
|
||||||
await client.delete(`posts/${id}`);
|
await client.delete(`posts/${id}`);
|
||||||
queryClient.setQueryData<PostizPost[]>(["posts-list", true], (old) =>
|
queryClient.invalidateQueries({ queryKey: ["posts-list"] });
|
||||||
(old ?? []).filter((p) => p.id !== id)
|
|
||||||
);
|
|
||||||
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
queryClient.invalidateQueries({ queryKey: ["posts"] });
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
const msg = extractError(e);
|
const msg = extractError(e);
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ export function PostCard({ post, onDelete }: PostCardProps) {
|
|||||||
</Text>
|
</Text>
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
<StatusBadge status={post.status} />
|
<StatusBadge status={post.state} />
|
||||||
</View>
|
</View>
|
||||||
<Text style={[styles.content, { color: colors.foreground }]}>
|
<Text style={[styles.content, { color: colors.foreground }]}>
|
||||||
{truncatedContent}
|
{truncatedContent}
|
||||||
|
|||||||
Reference in New Issue
Block a user