- Todos point logic and Family progress UI

This commit is contained in:
Dejan
2024-12-29 23:01:24 +01:00
parent afa1046d02
commit 7b809d826c
3 changed files with 100 additions and 94 deletions

View File

@ -77,7 +77,7 @@ const ToDosPage = () => {
{pageIndex == 2 && <UserChoresProgress setPageIndex={setPageIndex} />} {pageIndex == 2 && <UserChoresProgress setPageIndex={setPageIndex} />}
</View> </View>
</ScrollView> </ScrollView>
<AddChore /> {pageIndex === 0 && <AddChore />}
</> </>
); );
}; };

View File

@ -1,78 +1,74 @@
import React from "react"; import React, {useEffect, useState} from "react";
import { BarChart } from "react-native-gifted-charts"; import { BarChart } from "react-native-gifted-charts";
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
const FamilyChart = () => { const FamilyChart = ({ children }: {
// Define the data for the bars children: Array<UserProfile>;
const data = [ }) => {
{ const [dataList, setDataList] = useState([]);
value: 600, // Total value of the bar
stacks: [ useEffect(() => {
{ value: 290, color: "#e7d526" }, // First part of the bar let dayPointsMap = {
{ value: 310, color: "#00a8b6" }, // Second part of the bar Monday: {},
], Tuesday: {},
label: "M", Wednesday: {},
}, Thursday: {},
{ Friday: {},
value: 400, Saturday: {},
stacks: [ Sunday: {},
{ value: 190, color: "#e7d526" }, };
{ value: 210, color: "#00a8b6" }, children?.forEach((child) => {
], let weeklyDayPoints = child.weeklyDayPoints || {
label: "Tu", Monday: 0,
}, Tuesday: 0,
{ Wednesday: 0,
value: 400, Thursday: 0,
stacks: [ Friday: 0,
{ value: 210, color: "#e7d526" }, Saturday: 0,
{ value: 190, color: "#00a8b6" }, Sunday: 0,
], };
label: "W",
}, Object.keys(weeklyDayPoints).forEach((day) => {
{ dayPointsMap = {
value: 800, ...dayPointsMap,
stacks: [ [day]: {
{ value: 410, color: "#e7d526" }, ...dayPointsMap[day],
{ value: 390, color: "#00a8b6" }, [child.uid]: weeklyDayPoints[day]
], }
label: "Th", }
}, })
{ })
value: 600,
stacks: [ const data = Object.keys(dayPointsMap).map((day) => {
{ value: 220, color: "#e7d526" }, const userMap = dayPointsMap[day];
{ value: 380, color: "#00a8b6" }, let stacks = Object.keys(userMap).map((userId) => {
],
label: "F", let userProfile = children?.find((child) => child.uid === userId);
}, return {
{ value: userMap[userId],
value: 200, color: userProfile.eventColor
stacks: [ }
{ value: 160, color: "#e7d526" }, });
{ value: 40, color: "#00a8b6" },
], return {
label: "Sa", stacks: stacks,
}, label: day,
{ }
value: 200, });
stacks: [ setDataList(data);
{ value: 160, color: "#e7d526" }, }, [children])
{ value: 40, color: "#00a8b6" },
],
label: "Su",
},
];
return ( return (
<BarChart <BarChart
stackData={data} stackData={dataList}
width={250} width={250}
height={150} // Height of the chart height={150} // Height of the chart
barWidth={20} // Width of each bar barWidth={20} // Width of each bar
noOfSections={5} // Number of horizontal sections (for 0 to 1000 in steps of 200) noOfSections={5} // Number of horizontal sections (for 0 to 1000 in steps of 200)
maxValue={1000} // Max value on the chart maxValue={500} // Max value on the chart
stepValue={200} // Step size for horizontal lines stepValue={100} // Step size for horizontal lines
yAxisThickness={0} // Hide the Y-axis line yAxisThickness={0} // Hide the Y-axis line
yAxisLabelTexts={["0", "200", "400", "600", "800", "1000"]} // Custom Y-axis labels // yAxisLabelTexts={["0", "100", "200", "300", "400", "500"]} // Custom Y-axis labels
hideRules={false} // Show the horizontal lines hideRules={false} // Show the horizontal lines
rulesType="solid" rulesType="solid"
rulesThickness={1.2} rulesThickness={1.2}

View File

@ -1,5 +1,5 @@
import { View, Text } from "react-native-ui-lib"; import { View, Text } from "react-native-ui-lib";
import React from "react"; import React, {useCallback} from "react";
import { ImageBackground, StyleSheet } from "react-native"; import { ImageBackground, StyleSheet } from "react-native";
import FamilyChart from "./FamilyChart"; import FamilyChart from "./FamilyChart";
import { TouchableOpacity } from "react-native-ui-lib/src/incubator"; import { TouchableOpacity } from "react-native-ui-lib/src/incubator";
@ -7,17 +7,25 @@ import { Ionicons } from "@expo/vector-icons";
import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers"; import { useGetFamilyMembers } from "@/hooks/firebase/useGetFamilyMembers";
import { ProfileType } from "@/contexts/AuthContext"; import { ProfileType } from "@/contexts/AuthContext";
import { ScrollView } from "react-native-gesture-handler"; import { ScrollView } from "react-native-gesture-handler";
import {useFocusEffect} from "@react-navigation/core";
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
const FamilyChoresProgress = ({ const FamilyChoresProgress = ({
setPageIndex, setPageIndex,
}: { }: {
setPageIndex: (value: number) => void; setPageIndex: (value: number) => void;
}) => { }) => {
const { data: familyMembers } = useGetFamilyMembers(); const { data: familyMembers, refetch: refetchFamilyMembers } = useGetFamilyMembers();
const children = familyMembers?.filter( const children = familyMembers?.filter(
(member) => member.userType === ProfileType.CHILD (member) => member.userType === ProfileType.CHILD
); );
useFocusEffect(
useCallback(() => {
refetchFamilyMembers();
}, [refetchFamilyMembers])
);
return ( return (
<View marginT-20 marginH-5 marginB-100> <View marginT-20 marginH-5 marginB-100>
<ScrollView> <ScrollView>
@ -47,35 +55,37 @@ const FamilyChoresProgress = ({
Points earned this week Points earned this week
</Text> </Text>
<View row> <View row>
{children?.map((child, index) => ( {children?.map((child: UserProfile) => {
<View return child.weeklyPoints && child.weeklyPoints > 0 ? (
key={child.uid} <View
style={styles.pfpSmall} key={child.uid}
backgroundColor={child.eventColor || "#05a8b6"} style={styles.pfpSmall}
center backgroundColor={child.eventColor || "#05a8b6"}
> center
{child.pfp ? ( >
<ImageBackground {child.pfp ? (
source={{ uri: child.pfp }} <ImageBackground
style={{ source={{ uri: child.pfp }}
height: 25, style={{
aspectRatio: 1, height: 25,
borderRadius: 22, aspectRatio: 1,
overflow: "hidden", borderRadius: 22,
}} overflow: "hidden",
/> }}
) : ( />
<Text color="white" style={{fontSize: 15}}> ) : (
{child.firstName.at(0)} <Text color="white" style={{fontSize: 15}}>
{child.lastName.at(0)} {child.firstName.at(0)}
</Text> {child.lastName.at(0)}
)} </Text>
</View> )}
))} </View>
) : null
})}
</View> </View>
</View> </View>
<View style={styles.card} paddingL-10> <View style={styles.card} paddingL-10>
<FamilyChart /> <FamilyChart children={children} />
</View> </View>
<Text <Text
text70 text70