From ffe8cc72a1e8fa8708da09ba3b18ae0da2a01a9c Mon Sep 17 00:00:00 2001 From: Dejan Date: Mon, 30 Dec 2024 12:54:04 +0100 Subject: [PATCH] - Sorted the user progress chart by day --- components/pages/todos/family-chores/FamilyChart.tsx | 3 ++- components/pages/todos/user-chores/UserChart.tsx | 10 ++++++++-- constants/common.ts | 11 +++++++++++ 3 files changed, 21 insertions(+), 3 deletions(-) create mode 100644 constants/common.ts diff --git a/components/pages/todos/family-chores/FamilyChart.tsx b/components/pages/todos/family-chores/FamilyChart.tsx index 3c10d4d..63364c0 100644 --- a/components/pages/todos/family-chores/FamilyChart.tsx +++ b/components/pages/todos/family-chores/FamilyChart.tsx @@ -1,6 +1,7 @@ import React, {useEffect, useState} from "react"; import { BarChart } from "react-native-gifted-charts"; import { UserProfile } from "@/hooks/firebase/types/profileTypes"; +import {chartDayMap} from "@/constants/common"; const FamilyChart = ({ children }: { children: Array; @@ -52,7 +53,7 @@ const FamilyChart = ({ children }: { return { stacks: stacks, - label: day, + label: chartDayMap[day], } }); setDataList(data); diff --git a/components/pages/todos/user-chores/UserChart.tsx b/components/pages/todos/user-chores/UserChart.tsx index 379f682..b6b80db 100644 --- a/components/pages/todos/user-chores/UserChart.tsx +++ b/components/pages/todos/user-chores/UserChart.tsx @@ -1,6 +1,7 @@ import React, {useEffect, useState} from "react"; import { BarChart } from "react-native-gifted-charts"; import {UserProfile} from "@/hooks/firebase/types/profileTypes"; +import {chartDayMap, weekOrder} from "@/constants/common"; const UserChart = ({ profileData }: { profileData: UserProfile | undefined; @@ -19,13 +20,18 @@ const UserChart = ({ profileData }: { Sunday: 0, }; - const data = Object.keys(weeklyDayPoints).map((day) => { + // Sort by day + const sortedWeeklyPoints = Object.fromEntries( + weekOrder.map(day => [day, weeklyDayPoints[day]]) + ); + + const data = Object.keys(sortedWeeklyPoints).map((day) => { const value = weeklyDayPoints[day]; return { value: value, frontColor: barColor, - label: day, + label: chartDayMap[day], } }); setDataList(data); diff --git a/constants/common.ts b/constants/common.ts new file mode 100644 index 0000000..f94cb1b --- /dev/null +++ b/constants/common.ts @@ -0,0 +1,11 @@ +export const chartDayMap = { + Monday: "M", + Tuesday: "Tu", + Wednesday: "W", + Thursday: "Th", + Friday: "F", + Saturday: "Sa", + Sunday: "Su", +} + +export const weekOrder = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"]; \ No newline at end of file