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