import { Trans, useLingui } from '@lingui/react/macro'; import { useContext } from 'preact/hooks'; import { ThreadCountContext } from '../utils/thread-count-context'; import Icon from './icon'; function ThreadIcon({ alt }) { return ; } function ThreadBadge({ index, showIcon, showText }) { const { t } = useLingui(); const total = useContext(ThreadCountContext); const hasIndex = index > 0; const hasTotal = total > 0; return (
{showIcon && ( <> {' '} )} {showText ? ( hasIndex ? ( hasTotal ? ( Thread {index}/{total} ) : ( Thread {index}/X ) ) : ( t`Thread` ) ) : hasIndex ? ( hasTotal ? ( t({ message: `${index}/${total}`, comment: 'index/total posts in a thread', }) ) : ( t({ message: `${index}/X`, comment: 'X is the unspecified total number of posts in a thread', }) ) ) : ( !showIcon && )}
); } export default ThreadBadge;