webapp/src/components/_shared/StatMetrics.tsx

45 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { For } from 'solid-js'
import type { Stat, TopicStat } from '../../graphql/types.gen'
import { locale } from '../../stores/ui'
import { plural } from '../../utils'
import { t } from '../../utils/intl'
import styles from './Stat.module.scss'
interface StatMetricsProps {
fields?: string[]
stat: Stat | TopicStat
compact?: boolean
}
const pseudonames = {
// topics: 'topics' # amount of topics for community💥
followed: 'follower',
followers: 'follower',
rating: 'like',
viewed: 'view',
views: 'view',
reacted: 'involving',
reactions: 'involving',
commented: 'discussion',
comments: 'discussion',
shouts: 'post',
authors: 'author'
}
export const StatMetrics = (props: StatMetricsProps) => {
return (
<div class={styles.statMetrics}>
<For each={props.fields}>
{(entity: string) => (
<span class={styles.statMetricsItem} classList={{ compact: props.compact }}>
{props.stat[entity] +
' ' +
t(pseudonames[entity] || entity.slice(-1)) +
plural(props.stat[entity] || 0, locale() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's'])}
</span>
)}
</For>
</div>
)
}