thumbnail caching

This commit is contained in:
Aria Moradi
2021-01-29 14:19:24 +03:30
parent 345be95ce9
commit 9caae5f1e5
11 changed files with 279 additions and 84 deletions

View File

@@ -12,15 +12,21 @@ interface IProps{
hasNextPage: boolean
lastPageNum: number
setLastPageNum: (lastPageNum: number) => void
setMangas: (mangas: IManga[]) => void
}
export default function MangaGrid(props: IProps) {
const {
mangas, message, hasNextPage, lastPageNum, setLastPageNum,
mangas, message, hasNextPage, lastPageNum, setLastPageNum, setMangas,
} = props;
let mapped;
const lastManga = useRef<HTMLInputElement>();
function setMangaThumbnailUrl(index: number, thumbnailUrl: string) {
mangas[index].thumbnailUrl = thumbnailUrl;
setMangas(mangas);
}
const scrollHandler = () => {
if (lastManga.current) {
const rect = lastManga.current.getBoundingClientRect();
@@ -41,9 +47,24 @@ export default function MangaGrid(props: IProps) {
} else {
mapped = mangas.map((it, idx) => {
if (idx === mangas.length - 1) {
return <MangaCard manga={it} ref={lastManga} />;
return (
<MangaCard
manga={it}
ref={lastManga}
setMangaThumbnailUrl={
(thumbnailUrl:string) => setMangaThumbnailUrl(idx, thumbnailUrl)
}
/>
);
}
return <MangaCard manga={it} />;
return (
<MangaCard
manga={it}
setMangaThumbnailUrl={
(thumbnailUrl:string) => setMangaThumbnailUrl(idx, thumbnailUrl)
}
/>
);
});
}