diff --git a/artifacts/postiz-mobile/app/(tabs)/index.tsx b/artifacts/postiz-mobile/app/(tabs)/index.tsx index 31f12d3..fcc9aa7 100644 --- a/artifacts/postiz-mobile/app/(tabs)/index.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/index.tsx @@ -70,9 +70,7 @@ export default function CalendarScreen() { year: now.getFullYear(), month: now.getMonth() + 1, }); - const [selectedDay, setSelectedDay] = useState( - formatDate(now) - ); + const [selectedDay, setSelectedDay] = useState(formatDate(now)); const startDate = useMemo(() => { const d = new Date(currentMonth.year, currentMonth.month - 1, 1); @@ -85,16 +83,17 @@ export default function CalendarScreen() { }, [currentMonth]); const { data: posts, isLoading, error, refetch } = useQuery({ - queryKey: ["posts", startDate, endDate], + queryKey: ["posts", startDate, endDate, !!client], queryFn: async () => { if (!client) return []; - const res = await client.get("/posts", { + const res = await client.get("posts", { params: { startDate, endDate }, }); return Array.isArray(res.data) ? res.data : res.data?.posts ?? []; }, enabled: !!client, retry: 1, + staleTime: 0, }); const markedDates = useMemo(() => { @@ -108,9 +107,9 @@ export default function CalendarScreen() { const key = toDateKey(post.publishDate); if (!marks[key]) marks[key] = { dots: [] }; const dotColor = - post.status === "PUBLISHED" + post.state === "PUBLISHED" ? colors.success - : post.status === "ERROR" + : post.state === "ERROR" ? colors.error : colors.primary; marks[key].dots = [...(marks[key].dots ?? []), { color: dotColor }]; @@ -254,10 +253,7 @@ export default function CalendarScreen() { } renderItem={({ item }) => ( @@ -271,7 +267,7 @@ export default function CalendarScreen() { {item.content} - + )} scrollEnabled={dayPosts.length > 0} @@ -283,9 +279,7 @@ export default function CalendarScreen() { } const styles = StyleSheet.create({ - container: { - flex: 1, - }, + container: { flex: 1 }, centered: { flex: 1, alignItems: "center", @@ -293,28 +287,11 @@ const styles = StyleSheet.create({ gap: 10, paddingHorizontal: 32, }, - emptyTitle: { - fontSize: 18, - fontFamily: "Inter_600SemiBold", - }, - emptyText: { - fontSize: 14, - fontFamily: "Inter_400Regular", - textAlign: "center", - }, - btn: { - marginTop: 8, - paddingHorizontal: 20, - paddingVertical: 10, - borderRadius: 10, - }, - btnText: { - fontSize: 14, - fontFamily: "Inter_600SemiBold", - }, - divider: { - height: StyleSheet.hairlineWidth, - }, + emptyTitle: { fontSize: 18, fontFamily: "Inter_600SemiBold" }, + emptyText: { fontSize: 14, fontFamily: "Inter_400Regular", textAlign: "center" }, + btn: { marginTop: 8, paddingHorizontal: 20, paddingVertical: 10, borderRadius: 10 }, + btnText: { fontSize: 14, fontFamily: "Inter_600SemiBold" }, + divider: { height: StyleSheet.hairlineWidth }, dayHeader: { flexDirection: "row", justifyContent: "space-between", @@ -322,14 +299,8 @@ const styles = StyleSheet.create({ paddingHorizontal: 20, paddingVertical: 12, }, - dayHeaderText: { - fontSize: 13, - fontFamily: "Inter_500Medium", - }, - countText: { - fontSize: 12, - fontFamily: "Inter_400Regular", - }, + dayHeaderText: { fontSize: 13, fontFamily: "Inter_500Medium" }, + countText: { fontSize: 12, fontFamily: "Inter_400Regular" }, dayPost: { flexDirection: "row", alignItems: "flex-start", @@ -338,42 +309,13 @@ const styles = StyleSheet.create({ borderBottomWidth: StyleSheet.hairlineWidth, gap: 12, }, - dayPostLeft: { - flex: 1, - gap: 4, - }, - timeText: { - fontSize: 12, - fontFamily: "Inter_600SemiBold", - }, - postContent: { - fontSize: 13, - fontFamily: "Inter_400Regular", - lineHeight: 18, - }, - emptyDay: { - alignItems: "center", - paddingTop: 32, - gap: 10, - }, - emptyDayText: { - fontSize: 14, - fontFamily: "Inter_400Regular", - }, - composeHint: { - flexDirection: "row", - alignItems: "center", - gap: 6, - }, - composeHintText: { - fontSize: 14, - fontFamily: "Inter_500Medium", - }, - retryBtn: { - marginTop: 4, - }, - retryText: { - fontSize: 14, - fontFamily: "Inter_500Medium", - }, + dayPostLeft: { flex: 1, gap: 4 }, + timeText: { fontSize: 12, fontFamily: "Inter_600SemiBold" }, + postContent: { fontSize: 13, fontFamily: "Inter_400Regular", lineHeight: 18 }, + emptyDay: { alignItems: "center", paddingTop: 32, gap: 10 }, + emptyDayText: { fontSize: 14, fontFamily: "Inter_400Regular" }, + composeHint: { flexDirection: "row", alignItems: "center", gap: 6 }, + composeHintText: { fontSize: 14, fontFamily: "Inter_500Medium" }, + retryBtn: { marginTop: 4 }, + retryText: { fontSize: 14, fontFamily: "Inter_500Medium" }, }); diff --git a/artifacts/postiz-mobile/app/(tabs)/posts.tsx b/artifacts/postiz-mobile/app/(tabs)/posts.tsx index 0c82e91..f4e5575 100644 --- a/artifacts/postiz-mobile/app/(tabs)/posts.tsx +++ b/artifacts/postiz-mobile/app/(tabs)/posts.tsx @@ -13,7 +13,6 @@ import { TouchableOpacity, View, } from "react-native"; - import { useSafeAreaInsets } from "react-native-safe-area-context"; import { PostCard } from "@/components/PostCard"; import { PostizPost, usePostiz } from "@/context/PostizContext"; @@ -61,10 +60,10 @@ export default function PostsScreen() { end.setMonth(end.getMonth() + 6); const { data: posts, isLoading, error, refetch } = useQuery({ - queryKey: ["posts-list"], + queryKey: ["posts-list", !!client], queryFn: async () => { if (!client) return []; - const res = await client.get("/posts", { + const res = await client.get("posts", { params: { startDate: start.toISOString(), endDate: end.toISOString(), @@ -74,12 +73,13 @@ export default function PostsScreen() { }, enabled: !!client, retry: 1, + staleTime: 0, }); const filteredPosts = filter === "all" ? posts ?? [] - : (posts ?? []).filter((p) => p.status === filter); + : (posts ?? []).filter((p) => p.state === filter); const handleRefresh = async () => { setRefreshing(true); @@ -90,8 +90,8 @@ export default function PostsScreen() { const handleDelete = async (id: string) => { if (!client) return; try { - await client.delete(`/posts/${id}`); - queryClient.setQueryData(["posts-list"], (old) => + await client.delete(`posts/${id}`); + queryClient.setQueryData(["posts-list", true], (old) => (old ?? []).filter((p) => p.id !== id) ); queryClient.invalidateQueries({ queryKey: ["posts"] }); @@ -227,9 +227,7 @@ export default function PostsScreen() { } const styles = StyleSheet.create({ - container: { - flex: 1, - }, + container: { flex: 1 }, centered: { flex: 1, alignItems: "center", @@ -237,47 +235,13 @@ const styles = StyleSheet.create({ gap: 10, paddingHorizontal: 32, }, - filterBar: { - borderBottomWidth: StyleSheet.hairlineWidth, - flexGrow: 0, - }, - filterList: { - paddingHorizontal: 16, - paddingVertical: 10, - gap: 8, - }, - filterChip: { - paddingHorizontal: 14, - paddingVertical: 6, - borderRadius: 20, - borderWidth: 1, - }, - filterText: { - fontSize: 13, - fontFamily: "Inter_500Medium", - }, - emptyState: { - alignItems: "center", - paddingTop: 64, - gap: 10, - }, - emptyTitle: { - fontSize: 18, - fontFamily: "Inter_600SemiBold", - }, - emptyText: { - fontSize: 14, - fontFamily: "Inter_400Regular", - textAlign: "center", - }, - retryBtn: { - marginTop: 4, - paddingHorizontal: 20, - paddingVertical: 10, - borderRadius: 10, - }, - retryText: { - fontSize: 14, - fontFamily: "Inter_600SemiBold", - }, + filterBar: { borderBottomWidth: StyleSheet.hairlineWidth, flexGrow: 0 }, + filterList: { paddingHorizontal: 16, paddingVertical: 10, gap: 8 }, + filterChip: { paddingHorizontal: 14, paddingVertical: 6, borderRadius: 20, borderWidth: 1 }, + filterText: { fontSize: 13, fontFamily: "Inter_500Medium" }, + emptyState: { alignItems: "center", paddingTop: 64, gap: 10 }, + emptyTitle: { fontSize: 18, fontFamily: "Inter_600SemiBold" }, + emptyText: { fontSize: 14, fontFamily: "Inter_400Regular", textAlign: "center" }, + retryBtn: { marginTop: 4, paddingHorizontal: 20, paddingVertical: 10, borderRadius: 10 }, + retryText: { fontSize: 14, fontFamily: "Inter_600SemiBold" }, }); diff --git a/artifacts/postiz-mobile/context/PostizContext.tsx b/artifacts/postiz-mobile/context/PostizContext.tsx index 2d69ab4..4ae025a 100644 --- a/artifacts/postiz-mobile/context/PostizContext.tsx +++ b/artifacts/postiz-mobile/context/PostizContext.tsx @@ -29,7 +29,7 @@ export interface PostizMediaItem { export interface PostizPost { id: string; content: string; - status: "QUEUE" | "PUBLISHED" | "ERROR" | "DRAFT"; + state: "QUEUE" | "PUBLISHED" | "ERROR" | "DRAFT"; publishDate: string; integration?: PostizIntegration; integrations?: PostizIntegration[]; @@ -63,14 +63,20 @@ const PostizContext = createContext({ }); function createClient(apiKey: string, baseUrl: string): AxiosInstance { - return axios.create({ - baseURL: baseUrl, + const normalizedUrl = baseUrl.endsWith("/") ? baseUrl : baseUrl + "/"; + const instance = axios.create({ + baseURL: normalizedUrl, headers: { - Authorization: apiKey, + Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", }, timeout: 15000, }); + instance.interceptors.request.use((config) => { + console.log(">>> REQUEST:", config.method?.toUpperCase(), (config.baseURL || "") + (config.url || "")); + return config; + }); + return instance; } export function PostizProvider({ children }: { children: React.ReactNode }) { @@ -85,7 +91,7 @@ export function PostizProvider({ children }: { children: React.ReactNode }) { const storedKey = await SecureStore.getItemAsync(API_KEY_STORAGE); const storedUrl = await SecureStore.getItemAsync(BASE_URL_STORAGE); if (storedKey) { - const url = storedUrl || DEFAULT_BASE_URL; + const url = (storedUrl || DEFAULT_BASE_URL).replace(/\/$/, ""); setApiKey(storedKey); setBaseUrl(url); setClient(createClient(storedKey, url));