From 8c2b92d194fb5a88b5ba0edeaf2216625521a8dc Mon Sep 17 00:00:00 2001 From: BunyodL Date: Thu, 22 May 2025 09:26:52 +0500 Subject: [PATCH] update: get counter values from backend --- src/shared/components/about-counter.tsx | 75 +++++++++++++++---------- src/widgets/stats-section.tsx | 69 ++++++++++++++--------- 2 files changed, 88 insertions(+), 56 deletions(-) diff --git a/src/shared/components/about-counter.tsx b/src/shared/components/about-counter.tsx index 319fc62..ac8c7e1 100644 --- a/src/shared/components/about-counter.tsx +++ b/src/shared/components/about-counter.tsx @@ -7,47 +7,60 @@ import { useTextController } from '@/shared/language/hooks/use-text-controller'; import { useIntersectionObserver } from '../hooks/use-intersection-observer'; import AnimatedCounter from './animated-counter'; +const stats = [ + { + value: 'about.stats.items.2.value', + suffix: 'about.stats.items.2.suffix', + label: 'about.stats.items.2.label', + }, + { + value: 'about.stats.items.4.value', + suffix: 'about.stats.items.4.suffix', + label: 'about.stats.items.4.label', + }, + { + value: 'about.stats.items.5.value', + suffix: 'about.stats.items.5.suffix', + label: 'about.stats.items.5.label', + decimals: 1, + }, +]; + export default function AboutCounter() { const { t } = useTextController(); - const { sectionRef, isVisible } = useIntersectionObserver(); + const toNumber = (value: string) => { + return Number(t(value)); + }; + return (
-
-
- + {stats.map((stat, index) => ( +
+
+ +
+

+ {isVisible ? ( + + ) : ( + `0${t(stat.suffix)}` + )} +

+

{t(stat.label)}

-

- {isVisible ? : '0+'} -

-

{t('about.stats.items.2.label')}

-
-
-
- -
-

- {isVisible ? : '0M+'} -

-

{t('about.stats.items.4.label')}

-
-
-
- -
-

- {isVisible ? ( - - ) : ( - '0%' - )} -

-

{t('about.stats.items.5.label')}

-
+ ))}
); } diff --git a/src/widgets/stats-section.tsx b/src/widgets/stats-section.tsx index c3c57f4..5cfdb32 100644 --- a/src/widgets/stats-section.tsx +++ b/src/widgets/stats-section.tsx @@ -6,39 +6,58 @@ import { useTextController } from '@/shared/language/hooks/use-text-controller'; import AnimatedCounter from '../shared/components/animated-counter'; +const stats = [ + { + key: 'stations', + value: 'home.stats.stations.value', + suffix: 'home.stats.stations.suffix', + label: 'home.stats.stations', + }, + { + key: 'daily', + value: 'home.stats.daily.value', + suffix: 'home.stats.daily.suffix', + label: 'home.stats.daily', + }, + { + key: 'years', + value: 'home.stats.years.value', + suffix: '', + label: 'home.stats.years', + }, + { + key: 'mode', + value: 'home.stats.mode.value', + suffix: 'home.stats.mode.suffix', + label: 'home.stats.mode', + }, +]; + export function StatsSection() { const { t } = useTextController(); - const { sectionRef, isVisible } = useIntersectionObserver(); + const toNumber = (value: string) => Number(t(value)); + return (
-
-

- {isVisible ? : '0+'} -

-

{t('home.stats.stations')}

-
-
-

- {isVisible ? : '0+'} -

-

{t('home.stats.daily')}

-
-
-

- {isVisible ? : '0'} -

-

{t('home.stats.years')}

-
-
-

- {isVisible ? : '0/7'} -

-

{t('home.stats.mode')}

-
+ {stats.map(({ key, value, suffix, label }) => ( +
+

+ {isVisible ? ( + + ) : ( + `0${t(suffix) || ''}` + )} +

+

{t(label)}

+
+ ))}