mirror of
https://github.com/urosran/cally.git
synced 2025-07-09 22:57:16 +00:00
- Sorted the user progress chart by day
This commit is contained in:
@ -1,6 +1,7 @@
|
|||||||
import React, {useEffect, useState} 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";
|
import { UserProfile } from "@/hooks/firebase/types/profileTypes";
|
||||||
|
import {chartDayMap} from "@/constants/common";
|
||||||
|
|
||||||
const FamilyChart = ({ children }: {
|
const FamilyChart = ({ children }: {
|
||||||
children: Array<UserProfile>;
|
children: Array<UserProfile>;
|
||||||
@ -52,7 +53,7 @@ const FamilyChart = ({ children }: {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
stacks: stacks,
|
stacks: stacks,
|
||||||
label: day,
|
label: chartDayMap[day],
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setDataList(data);
|
setDataList(data);
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
import React, {useEffect, useState} 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";
|
import {UserProfile} from "@/hooks/firebase/types/profileTypes";
|
||||||
|
import {chartDayMap, weekOrder} from "@/constants/common";
|
||||||
|
|
||||||
const UserChart = ({ profileData }: {
|
const UserChart = ({ profileData }: {
|
||||||
profileData: UserProfile | undefined;
|
profileData: UserProfile | undefined;
|
||||||
@ -19,13 +20,18 @@ const UserChart = ({ profileData }: {
|
|||||||
Sunday: 0,
|
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];
|
const value = weeklyDayPoints[day];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
value: value,
|
value: value,
|
||||||
frontColor: barColor,
|
frontColor: barColor,
|
||||||
label: day,
|
label: chartDayMap[day],
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
setDataList(data);
|
setDataList(data);
|
||||||
|
11
constants/common.ts
Normal file
11
constants/common.ts
Normal file
@ -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"];
|
Reference in New Issue
Block a user