diff --git a/package.json b/package.json index 62134d20..b1bd4de8 100644 --- a/package.json +++ b/package.json @@ -101,12 +101,12 @@ "react-hook-form": "7.43.9", "react-hot-toast": "2.4.0", "react-i18next": "^12.2.2", - "react-infinite-scroller": "1.2.6", "react-parallax-tilt": "^1.7.131", "react-popper": "^2.3.0", "react-scroll": "1.8.9", "react-sortablejs": "6.1.4", "react-string-replace": "^1.1.0", + "react-virtuoso": "4.3.1", "refractor": "4.8.1", "rehype-autolink-headings": "6.1.1", "rehype-infer-description-meta": "^1.1.0", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 68662fec..0f7829b4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -221,9 +221,6 @@ dependencies: react-i18next: specifier: ^12.2.2 version: 12.2.2(i18next@22.4.15)(react-dom@18.2.0)(react@18.2.0) - react-infinite-scroller: - specifier: 1.2.6 - version: 1.2.6(react@18.2.0) react-parallax-tilt: specifier: ^1.7.131 version: 1.7.131(react-dom@18.2.0)(react@18.2.0) @@ -239,6 +236,9 @@ dependencies: react-string-replace: specifier: ^1.1.0 version: 1.1.0 + react-virtuoso: + specifier: 4.3.1 + version: 4.3.1(react-dom@18.2.0)(react@18.2.0) refractor: specifier: 4.8.1 version: 4.8.1 @@ -12131,15 +12131,6 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false - /react-infinite-scroller@1.2.6(react@18.2.0): - resolution: {integrity: sha512-mGdMyOD00YArJ1S1F3TVU9y4fGSfVVl6p5gh/Vt4u99CJOptfVu/q5V/Wlle72TMgYlBwIhbxK5wF0C/R33PXQ==} - peerDependencies: - react: ^0.14.9 || ^15.3.0 || ^16.0.0 || ^17.0.0 || ^18.0.0 - dependencies: - prop-types: 15.8.1 - react: 18.2.0 - dev: false - /react-intersection-observer@9.4.3(react@18.2.0): resolution: {integrity: sha512-WNRqMQvKpupr6MzecAQI0Pj0+JQong307knLP4g/nBex7kYfIaZsPpXaIhKHR+oV8z+goUbH9e10j6lGRnTzlQ==} peerDependencies: @@ -12311,6 +12302,17 @@ packages: react-dom: 18.2.0(react@18.2.0) dev: false + /react-virtuoso@4.3.1(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-2+V0bvA1fASO+etlBG6YB0uj+StizxP3ecDJXgGW/r2z9AH067ehpJy2TSRiEIGQtDTmJAcmZnZzYVnk7AUmbw==} + engines: {node: '>=10'} + peerDependencies: + react: '>=16 || >=17 || >= 18' + react-dom: '>=16 || >=17 || >= 18' + dependencies: + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + /react@18.2.0: resolution: {integrity: sha512-/3IjMdb2L9QbBdWiW5e3P2/npwMBaU9mHCSCUzNln0ZCYbcfTsGbTJrU/kGemdH2IWmB2ioZ+zkxtmq6g09fGQ==} engines: {node: '>=0.10.0'} diff --git a/src/components/common/CharacterList.tsx b/src/components/common/CharacterList.tsx index 48d16c3a..b67d4dd0 100644 --- a/src/components/common/CharacterList.tsx +++ b/src/components/common/CharacterList.tsx @@ -1,6 +1,6 @@ import { useTranslation } from "next-i18next" import React from "react" -import InfiniteScroll from "react-infinite-scroller" +import { Virtuoso } from "react-virtuoso" import { Modal } from "~/components/ui/Modal" @@ -18,40 +18,38 @@ export const CharacterList: React.FC<{ title: string }> = ({ open, setOpen, hasMore, loadMore, list, title }) => { const { t } = useTranslation("common") + const flattenList = list?.reduce( + (acc, cur) => acc.concat(cur?.list || []), + [] as any[], + ) as any[] return ( -
- - {t("Loading")} ... -
- } - useWindow={false} - > - {list?.length ? ( - list.map((page) => - page?.list?.map((sub: any, index) => { - const character = sub?.character || sub?.fromCharacter - return ( - - ) - }), + {list?.length ? ( + loadMore()} + components={{ + Footer: hasMore ? Loader : undefined, + }} + data={flattenList} + itemContent={(index, sub) => { + const character = sub?.character || sub?.fromCharacter + return ( + ) - ) : ( -
- {t("No Content Yet.")} -
- )} - - + }} + >
+ ) : ( +
+
+ {t("No Content Yet.")} +
+
+ )} +