webapp/src/components/_shared/StatMetrics.tsx

46 lines
1.2 KiB
TypeScript
Raw Normal View History

2023-02-17 09:21:02 +00:00
import { createMemo, For } from 'solid-js'
import type { Stat, TopicStat } from '../../graphql/types.gen'
import { plural } from '../../utils'
import styles from './Stat.module.scss'
2023-02-17 09:21:02 +00:00
import { useLocalize } from '../../context/localize'
interface StatMetricsProps {
fields?: string[]
stat: Stat | TopicStat
compact?: boolean
}
const pseudonames = {
2022-11-23 05:28:41 +00:00
// topics: 'topics' # amount of topics for community💥
2022-11-25 05:54:19 +00:00
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) => {
2023-02-17 09:21:02 +00:00
const { t, lang } = useLocalize()
return (
<div class={styles.statMetrics}>
<For each={props.fields}>
{(entity: string) => (
<span class={styles.statMetricsItem} classList={{ compact: props.compact }}>
{props.stat[entity] +
' ' +
2022-11-25 05:54:19 +00:00
t(pseudonames[entity] || entity.slice(-1)) +
2023-02-17 09:21:02 +00:00
plural(props.stat[entity] || 0, lang() === 'ru' ? ['ов', '', 'а'] : ['s', '', 's'])}
</span>
)}
</For>
</div>
)
}