import React, { useEffect, useState } from 'react'; import { useTranslation } from 'react-i18next'; import Typography from '../Typography'; import Item from '../AnnotationItem'; import { Body } from '../../global/sidebarStyled'; type Props = { isActive: boolean; annotations: AnnotationType[]; }; const AnnotationList: React.FC = ({ isActive = false, annotations, }: Props) => { const { t } = useTranslation('sidebar'); const [list, setList] = useState([]); useEffect(() => { if (isActive) { const tmpArray = [...annotations]; tmpArray.sort((a, b) => { if (a.obj_attr.page > b.obj_attr.page) { return 1; } if (a.obj_attr.page < b.obj_attr.page) { return -1; } return 0; }); setList(tmpArray); } }, [isActive, annotations]); return (
{`${annotations.length} ${t('annotation')}`} {isActive && list.map((ele, index) => { const key = `annotation_item_${index}`; const { obj_type, obj_attr: { page, title, date, is_arrow }, } = ele; const actualPage = page + 1; const prevAnnot = list[index - 1]; const prevPage = index > 0 && prevAnnot ? prevAnnot.obj_attr.page + 1 : -1; return ( ); })}
); }; export default AnnotationList;