Skip to content

Commit

Permalink
refactor: simplify the stats page and its components
Browse files Browse the repository at this point in the history
Signed-off-by: Raphael Arce <raphael.arce@ts.berlin>
  • Loading branch information
raphael-arce committed Jul 19, 2024
1 parent 80eafba commit a93afab
Show file tree
Hide file tree
Showing 21 changed files with 1,121 additions and 1,122 deletions.
284 changes: 0 additions & 284 deletions src/components/stats/bar-chart.tsx

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,15 +1,27 @@
import React from "react";
import React, { useMemo } from "react";
import { adoptionsFillColor } from "./chart-colors";
import { useI18nStore } from "../../../../i18n/i18n-store";
import { useStatsStore } from "../../store/stats-store";

interface AdoptionsChartProps {
veryThirstyAdoptionsRate: number;
legend?: string;
}
/**
* This chart shows the number of adopted trees and,
* among them, the percentage that are very thirsty
*/
export const AdoptionsChart: React.FC = () => {
const i18n = useI18nStore().i18n();
const { gdkStats } = useStatsStore();

const veryThirstyAdoptionsRate = useMemo(() => {
if (!gdkStats) {
return 0;
}

return Math.round(
(gdkStats.treeAdoptions.veryThirstyCount / gdkStats.treeAdoptions.count) *
100,
);
}, [gdkStats]);

export const AdoptionsChart: React.FC<AdoptionsChartProps> = ({
veryThirstyAdoptionsRate,
legend,
}) => {
return (
<div className="w-full">
<div className="w-full grid grid-cols-1 grid-rows-">
Expand All @@ -32,7 +44,7 @@ export const AdoptionsChart: React.FC<AdoptionsChartProps> = ({
className={`text-[${adoptionsFillColor}] text-xl pt-2`}
>
<span className="font-bold">{veryThirstyAdoptionsRate}% </span>
{legend}
{i18n.stats.adoptionStat.legend}
</div>
</div>
</div>
Expand Down
Loading

0 comments on commit a93afab

Please sign in to comment.