diff --git a/src/corpus/ui/ChapterLink.tsx b/src/corpus/ui/ChapterLink.tsx deleted file mode 100644 index 631957ae6..000000000 --- a/src/corpus/ui/ChapterLink.tsx +++ /dev/null @@ -1,21 +0,0 @@ -import React, { PropsWithChildren } from 'react' -import { Link } from 'react-router-dom' -import { ChapterId } from 'transliteration/domain/chapter-id' -import { stageToAbbreviation } from 'common/period' - -export default function ChapterLink({ - id: { textId, stage, name }, - children, -}: PropsWithChildren<{ - id: ChapterId -}>): JSX.Element { - return ( - - {children} - - ) -} diff --git a/src/fragmentarium/ui/search/Pagination.tsx b/src/fragmentarium/ui/search/Pagination.tsx deleted file mode 100644 index f9db58bf8..000000000 --- a/src/fragmentarium/ui/search/Pagination.tsx +++ /dev/null @@ -1,139 +0,0 @@ -import _ from 'lodash' -import React, { useEffect, useMemo, useState } from 'react' -import PaginationItems from 'fragmentarium/ui/search/PaginationItems' -import Bluebird from 'bluebird' -import withData from 'http/withData' - -type renderPaginationElement = ( - data: PaginationElement, - key: number -) => React.ReactElement<{ data: PaginationElement; key: number }> - -interface Props { - paginationElements: readonly PaginationElement[] - totalCount: number - searchPagination: ( - paginationIndex: number - ) => Bluebird - paginationIndex: number - renderPagination: ( - PaginationControlsComponent: JSX.Element, - PaginationElementComponent: JSX.Element - ) => React.ReactElement<{ - PaginationControlsComponent: JSX.Element - PaginationElementComponent: JSX.Element - }> - renderPaginationElement: renderPaginationElement - paginationURLParam: string -} - -export default function Pagination({ - paginationURLParam, - paginationElements, - totalCount, - searchPagination, - paginationIndex, - renderPagination, - renderPaginationElement, -}: Props): JSX.Element { - const [activePage, setActivePage] = useState(paginationIndex) - const [savedPaginationElements, setSavedPaginationElements] = useState([ - { - paginationElements: paginationElements, - paginationIndex: paginationIndex, - }, - ]) - - const lastPage = - totalCount > 0 ? Math.ceil(totalCount / paginationElements.length) - 1 : 0 - - const findPaginationElements = ( - index: number - ): readonly PaginationElement[] | null => { - const found = _.find(savedPaginationElements, { - paginationIndex: index, - }) - return found ? found.paginationElements : null - } - - const fetchAndSavePaginationElements = ( - paginationIndex: number - ): Bluebird => - searchPagination(paginationIndex).then((paginationElements) => { - setSavedPaginationElements((stored) => [ - ...stored, - { - paginationElements: paginationElements, - paginationIndex: paginationIndex, - }, - ]) - return paginationElements - }) - useEffect(() => { - const succeeding = activePage + 1 - if (!findPaginationElements(succeeding) && succeeding <= lastPage) { - fetchAndSavePaginationElements(succeeding) - } - }, [ - activePage, - findPaginationElements, - fetchAndSavePaginationElements, - lastPage, - ]) - - const DisplayActivePage = withData< - { - paginationElements: readonly PaginationElement[] | null - searchPagination: ( - paginationIndex: number - ) => Bluebird - activePage: number - render: renderPaginationElement - }, - { - searchPagination: ( - paginationIndex: number - ) => Bluebird - }, - readonly PaginationElement[] - >( - ({ data, render }) => ( - <> - {data.map((paginationElement, index) => - render(paginationElement, index) - )} - - ), - (props) => props.searchPagination(props.activePage), - { - filter: (props) => _.isNil(props.paginationElements), - defaultData: (props) => props.paginationElements, - } - ) - - const displayActivePageMemo = useMemo( - () => ( - - ), - [activePage] - ) - - return ( - <> - {renderPagination( - , - displayActivePageMemo - )} - - ) -}