api call optimized
This commit is contained in:
1 parent
97436c6823
commit
612259f020
12 files changed
+727
-177
No files matched your search
@@ -3,33 +3,24 @@ import { View, Text, StyleSheet, ActivityIndicator } from "react-native";
|
||||
import { LinearGradient } from "expo-linear-gradient";
|
||||
import { Ionicons } from "@expo/vector-icons";
|
||||
import { theme } from "../styles/theme";
|
||||
import { useUser } from "@clerk/clerk-expo";
|
||||
import { getUserStatistics } from "../api/statistics";
|
||||
import { useStatistics } from "../contexts/StatisticsContext";
|
||||
import type { WeeklyTrendData } from "../api/types";
|
||||
|
||||
export function WeeklyProgressWidget() {
|
||||
const { user } = useUser();
|
||||
const { statistics, loading, refetchStatistics } = useStatistics();
|
||||
const [weeklyData, setWeeklyData] = useState<WeeklyTrendData[]>([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const loadWeeklyData = async () => {
|
||||
if (!user?.id) return;
|
||||
refetchStatistics();
|
||||
}, [refetchStatistics]);
|
||||
|
||||
try {
|
||||
const stats = await getUserStatistics(user.id);
|
||||
// Get last 4 weeks for compact display
|
||||
const last4Weeks = stats.weeklyTrend.slice(-4);
|
||||
setWeeklyData(last4Weeks);
|
||||
} catch (error) {
|
||||
console.error("Failed to load weekly data:", error);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
loadWeeklyData();
|
||||
}, [user?.id]);
|
||||
useEffect(() => {
|
||||
if (statistics?.weeklyTrend) {
|
||||
// Get last 4 weeks for compact display
|
||||
const last4Weeks = statistics.weeklyTrend.slice(-4);
|
||||
setWeeklyData(last4Weeks);
|
||||
}
|
||||
}, [statistics]);
|
||||
|
||||
if (loading) {
|
||||
return (
|
||||
|
||||
Reference in new issue
Block a user