import classNames from 'classnames'; import { type FunctionComponent } from 'react'; import { useAppLayout } from '@/app-layout'; import { selectDictionaryError, selectDictionaryIsLoading, selectDictionaryResults, useTranslate, useTypedSelector, } from '@/state'; import { EmptyState } from '../EmptyState'; import { Loading } from '../Loading'; import styles from './Dictionary.module.scss'; interface Props { className?: string; } export const Dictionary: FunctionComponent = ({ className }) => { const translate = useTranslate(); const { dictionaryResultsHeight } = useAppLayout(); const results = useTypedSelector(selectDictionaryResults); const isLoading = useTypedSelector(selectDictionaryIsLoading); const error = useTypedSelector(selectDictionaryError); const isLastAllowed = results.at(-1)?.isAllowed; return (
{typeof error !== 'undefined' && !isLoading && {error.message}} {typeof error === 'undefined' && !isLoading && results.length === 0 && ( {translate('dictionary.empty-state.uninitialized')} )} {results.map(({ definitions, exists, isAllowed, word }) => (
{word &&

{word}

} {isAllowed === false &&
{translate('dictionary.empty-state.not-allowed')}
} {isAllowed === true && definitions.length === 0 && ( <>
{exists ? translate('dictionary.empty-state.no-definitions') : translate('dictionary.empty-state.no-results')}
)} {isAllowed === true && definitions.length > 0 && (
    {definitions.map((result, index) => (
  • {result}
  • ))}
)} {!isLoading && isAllowed === null &&
{translate('dictionary.empty-state.no-results')}
}
))}
{isLoading && }
); };