mirror of
https://github.com/muerwre/vault-frontend.git
synced 2025-04-25 04:46:40 +07:00
made boris graphic stats
This commit is contained in:
parent
c0f8766ec6
commit
857993e354
11 changed files with 218 additions and 35 deletions
46
src/components/boris/BorisGraphicStats/index.tsx
Normal file
46
src/components/boris/BorisGraphicStats/index.tsx
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
import React, { VFC } from 'react';
|
||||||
|
|
||||||
|
import { parseISO } from 'date-fns/esm';
|
||||||
|
|
||||||
|
import { BasicCurveChart } from '~/components/charts/BasicCurveChart';
|
||||||
|
import { StatsCard } from '~/components/charts/StatsCard';
|
||||||
|
import { StatsCountdownCard } from '~/components/charts/StatsCountdownCard';
|
||||||
|
import { foundationDate } from '~/constants/boris/constants';
|
||||||
|
|
||||||
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
interface BorisGraphicStatsProps {
|
||||||
|
totalNodes: number;
|
||||||
|
nodesByMonth: number[];
|
||||||
|
totalComments: number;
|
||||||
|
commentsByMonth: number[];
|
||||||
|
}
|
||||||
|
|
||||||
|
const BorisGraphicStats: VFC<BorisGraphicStatsProps> = ({
|
||||||
|
totalComments,
|
||||||
|
commentsByMonth,
|
||||||
|
totalNodes,
|
||||||
|
nodesByMonth,
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<div className={styles.group}>
|
||||||
|
<StatsCard
|
||||||
|
background={<BasicCurveChart items={nodesByMonth} />}
|
||||||
|
title="Посты"
|
||||||
|
total={totalNodes}
|
||||||
|
className={styles.card}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StatsCard
|
||||||
|
background={<BasicCurveChart items={commentsByMonth} />}
|
||||||
|
title="Комментарии"
|
||||||
|
total={totalComments}
|
||||||
|
className={styles.card}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<StatsCountdownCard since={parseISO(foundationDate)} className={styles.card} />
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { BorisGraphicStats };
|
12
src/components/boris/BorisGraphicStats/styles.module.scss
Normal file
12
src/components/boris/BorisGraphicStats/styles.module.scss
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
@import 'src/styles/variables';
|
||||||
|
|
||||||
|
.group {
|
||||||
|
display: grid;
|
||||||
|
grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
|
||||||
|
grid-column-gap: $gap;
|
||||||
|
grid-row-gap: $gap;
|
||||||
|
}
|
||||||
|
|
||||||
|
.card {
|
||||||
|
height: 150px;
|
||||||
|
}
|
36
src/components/charts/StatsCard/index.tsx
Normal file
36
src/components/charts/StatsCard/index.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
import React, { FC, ReactNode } from 'react';
|
||||||
|
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import { SubTitle } from '~/components/common/SubTitle';
|
||||||
|
import { Card, CardProps } from '~/components/containers/Card';
|
||||||
|
import { Filler } from '~/components/containers/Filler';
|
||||||
|
import { Group } from '~/components/containers/Group';
|
||||||
|
|
||||||
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
interface StatsCardProps extends CardProps {
|
||||||
|
title?: string;
|
||||||
|
total?: number;
|
||||||
|
background?: ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatsCard: FC<StatsCardProps> = ({ children, title, background, total, ...props }) => (
|
||||||
|
<Card {...props} className={classNames(styles.card, props.className)}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
{(!!title || !!total) && (
|
||||||
|
<Group className={styles.title} horizontal>
|
||||||
|
{!!title && <SubTitle>{title}</SubTitle>}
|
||||||
|
<Filler />
|
||||||
|
{!!total && <SubTitle className={styles.total}>{total}</SubTitle>}
|
||||||
|
</Group>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{children}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{!!background && <div className={styles.background}>{background}</div>}
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
|
||||||
|
export { StatsCard };
|
22
src/components/charts/StatsCard/styles.module.scss
Normal file
22
src/components/charts/StatsCard/styles.module.scss
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
@import "src/styles/variables";
|
||||||
|
|
||||||
|
.card {
|
||||||
|
position: relative;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
z-index: 1;
|
||||||
|
position: relative;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.background {
|
||||||
|
top: 32px;
|
||||||
|
left: 0;
|
||||||
|
right: 0;
|
||||||
|
bottom: $gap;
|
||||||
|
position: absolute;
|
||||||
|
z-index: 0;
|
||||||
|
}
|
49
src/components/charts/StatsCountdownCard/index.tsx
Normal file
49
src/components/charts/StatsCountdownCard/index.tsx
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
import React, { VFC } from 'react';
|
||||||
|
|
||||||
|
import classNames from 'classnames';
|
||||||
|
import { addMonths } from 'date-fns';
|
||||||
|
import { addYears, differenceInDays, differenceInMonths, differenceInYears } from 'date-fns/esm';
|
||||||
|
|
||||||
|
import { StatsCard } from '~/components/charts/StatsCard';
|
||||||
|
import { CardProps } from '~/components/containers/Card';
|
||||||
|
|
||||||
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
|
interface StatsCountdownCardProps extends CardProps {
|
||||||
|
since: Date;
|
||||||
|
}
|
||||||
|
|
||||||
|
const StatsCountdownCard: VFC<StatsCountdownCardProps> = ({ since, ...props }) => {
|
||||||
|
const years = differenceInYears(new Date(), since);
|
||||||
|
const months = differenceInMonths(new Date(), addYears(since, years));
|
||||||
|
const days = differenceInDays(new Date(), addMonths(addYears(since, years), months));
|
||||||
|
|
||||||
|
return (
|
||||||
|
<StatsCard {...props} title="Нам уже" className={classNames(styles.card, props.className)}>
|
||||||
|
<div className={styles.content}>
|
||||||
|
{years > 0 && (
|
||||||
|
<>
|
||||||
|
<span className={styles.val}>{years}</span>
|
||||||
|
{' лет '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{months > 0 && (
|
||||||
|
<>
|
||||||
|
<span className={styles.val}>{months}</span>
|
||||||
|
{' мес. '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{days > 0 && (
|
||||||
|
<>
|
||||||
|
<span className={styles.val}>{days}</span>
|
||||||
|
{' дн. '}
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</StatsCard>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export { StatsCountdownCard };
|
19
src/components/charts/StatsCountdownCard/styles.module.scss
Normal file
19
src/components/charts/StatsCountdownCard/styles.module.scss
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
@import "src/styles/variables";
|
||||||
|
|
||||||
|
.content {
|
||||||
|
width: 100%;
|
||||||
|
flex: 1;
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
font: $font_18_semibold;
|
||||||
|
color: transparentize(white, 0.5);
|
||||||
|
padding-bottom: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
span.val {
|
||||||
|
font: $font_48_bold;
|
||||||
|
color: white;
|
||||||
|
padding: 0 $gap * 0.5 0 $gap * 2;
|
||||||
|
}
|
|
@ -2,13 +2,15 @@ import React, { FC } from 'react';
|
||||||
|
|
||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
|
||||||
|
import { DivProps } from '~/utils/types';
|
||||||
|
|
||||||
import styles from './styles.module.scss';
|
import styles from './styles.module.scss';
|
||||||
|
|
||||||
type IProps = React.HTMLAttributes<HTMLDivElement> & {
|
export type CardProps = DivProps & {
|
||||||
seamless?: boolean;
|
seamless?: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
const Card: FC<IProps> = ({ className, children, seamless, ...props }) => (
|
const Card: FC<CardProps> = ({ className, children, seamless, ...props }) => (
|
||||||
<div className={classNames(styles.card, className, { seamless })} {...props}>
|
<div className={classNames(styles.card, className, { seamless })} {...props}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -22,3 +22,5 @@ export const initialBackendStats: StatBackend = {
|
||||||
size: 0,
|
size: 0,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const foundationDate = '2009-07-21 12:28:58';
|
||||||
|
|
|
@ -2,9 +2,11 @@ import React, { FC } from 'react';
|
||||||
|
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
|
|
||||||
|
import { BorisGraphicStats } from '~/components/boris/BorisGraphicStats';
|
||||||
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
import { BorisSidebar } from '~/components/boris/BorisSidebar';
|
||||||
import { Superpower } from '~/components/boris/Superpower';
|
import { Superpower } from '~/components/boris/Superpower';
|
||||||
import { BasicCurveChart } from '~/components/charts/BasicCurveChart';
|
import { BasicCurveChart } from '~/components/charts/BasicCurveChart';
|
||||||
|
import { StatsCard } from '~/components/charts/StatsCard';
|
||||||
import { Card } from '~/components/containers/Card';
|
import { Card } from '~/components/containers/Card';
|
||||||
import { Filler } from '~/components/containers/Filler';
|
import { Filler } from '~/components/containers/Filler';
|
||||||
import { Grid } from '~/components/containers/Grid';
|
import { Grid } from '~/components/containers/Grid';
|
||||||
|
@ -51,42 +53,34 @@ const BorisLayout: FC<IProps> = ({ title, setIsBetaTester, isTester, stats, isLo
|
||||||
|
|
||||||
<div className={styles.container}>
|
<div className={styles.container}>
|
||||||
<Card className={styles.content}>
|
<Card className={styles.content}>
|
||||||
<Superpower>
|
<Group>
|
||||||
<Padder>
|
<Superpower>
|
||||||
<Group>
|
<Padder>
|
||||||
<h2>Тестовые фичи</h2>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Button onClick={() => openProfileSidebar({})}>Профиль в сайдбаре</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div>
|
|
||||||
<Button onClick={() => push(URLS.SETTINGS.BASE)}>
|
|
||||||
Профиль на отдельной странице
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<Group>
|
<Group>
|
||||||
<h4>Количество нод за год</h4>
|
<h2>Тестовые фичи</h2>
|
||||||
<Grid horizontal>
|
|
||||||
<Card style={{ padding: 0 }}>
|
|
||||||
<BasicCurveChart items={stats.backend.nodes.by_month} width={200} />
|
|
||||||
</Card>
|
|
||||||
|
|
||||||
<Card style={{ padding: 0 }}>
|
<div>
|
||||||
<BasicCurveChart items={stats.backend.comments.by_month} width={200} />
|
<Button onClick={() => openProfileSidebar({})}>Профиль в сайдбаре</Button>
|
||||||
</Card>
|
</div>
|
||||||
|
|
||||||
<Filler />
|
<div>
|
||||||
</Grid>
|
<Button onClick={() => push(URLS.SETTINGS.BASE)}>
|
||||||
|
Профиль на отдельной странице
|
||||||
<h4>Количество комментов за год</h4>
|
</Button>
|
||||||
|
</div>
|
||||||
</Group>
|
</Group>
|
||||||
</Group>
|
</Padder>
|
||||||
</Padder>
|
</Superpower>
|
||||||
</Superpower>
|
|
||||||
|
|
||||||
<BorisComments />
|
<BorisGraphicStats
|
||||||
|
totalComments={stats.backend.comments.total}
|
||||||
|
commentsByMonth={stats.backend.comments.by_month}
|
||||||
|
totalNodes={stats.backend.nodes.total}
|
||||||
|
nodesByMonth={stats.backend.nodes.by_month}
|
||||||
|
/>
|
||||||
|
|
||||||
|
<BorisComments />
|
||||||
|
</Group>
|
||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Group className={styles.stats}>
|
<Group className={styles.stats}>
|
||||||
|
|
|
@ -18,7 +18,8 @@ $font_24_bold: $bold 24px $font;
|
||||||
$font_24_semibold: $bold 24px $font;
|
$font_24_semibold: $bold 24px $font;
|
||||||
$font_24_medium: $medium 24px $font;
|
$font_24_medium: $medium 24px $font;
|
||||||
$font_24_regular: $regular 24px $font;
|
$font_24_regular: $regular 24px $font;
|
||||||
$font_20_semibold: $bold 24px $font;
|
$font_20_bold: $bold 24px $font;
|
||||||
|
$font_20_semibold: $semibold 24px $font;
|
||||||
$font_18_regular: $regular 18px $font;
|
$font_18_regular: $regular 18px $font;
|
||||||
$font_18_extra_light: $extra_light 18px $font;
|
$font_18_extra_light: $extra_light 18px $font;
|
||||||
$font_18_semibold: $semibold 18px $font;
|
$font_18_semibold: $semibold 18px $font;
|
||||||
|
|
File diff suppressed because one or more lines are too long
Loading…
Add table
Add a link
Reference in a new issue