2023-02-17 09:21:02 +00:00
|
|
|
|
import { createMemo, For } from 'solid-js'
|
2022-11-22 09:27:01 +00:00
|
|
|
|
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'
|
2022-11-22 09:27:01 +00:00
|
|
|
|
|
|
|
|
|
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'
|
2022-11-22 09:27:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const StatMetrics = (props: StatMetricsProps) => {
|
2023-02-17 09:21:02 +00:00
|
|
|
|
const { t, lang } = useLocalize()
|
|
|
|
|
|
2022-11-22 09:27:01 +00:00
|
|
|
|
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'])}
|
2022-11-22 09:27:01 +00:00
|
|
|
|
</span>
|
|
|
|
|
)}
|
|
|
|
|
</For>
|
|
|
|
|
</div>
|
|
|
|
|
)
|
|
|
|
|
}
|