From 84f9dc176ee6923b62ee53a06aa86730652a2300 Mon Sep 17 00:00:00 2001 From: glax Date: Wed, 18 Jun 2025 18:58:46 +0200 Subject: [PATCH] Image Loading (MangaCovers) with lazy load attribute, onError instead of onLoad hook, preventing requests before sizing is complete --- tranga-website/src/Components/Manga.tsx | 9 ++++++--- tranga-website/src/Components/MangaList.tsx | 15 ++++----------- tranga-website/src/api/Manga.tsx | 4 +--- 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/tranga-website/src/Components/Manga.tsx b/tranga-website/src/Components/Manga.tsx index 725d2d7..d70c21c 100644 --- a/tranga-website/src/Components/Manga.tsx +++ b/tranga-website/src/Components/Manga.tsx @@ -21,6 +21,9 @@ const coverSx : SxProps = { const coverCss : CSSProperties = { maxHeight: "calc("+CardHeight+"px + 2rem)", maxWidth: "calc("+CardWidth+"px + 2rem)", + objectFit: "cover", + width: "calc("+CardHeight+"px + 2rem)", + height: "calc("+CardHeight+"px + 2rem)", } export function MangaFromId({mangaId, children} : { mangaId: string, children?: ReactElement | ReactElement[] | undefined }){ @@ -34,7 +37,7 @@ export function MangaFromId({mangaId, children} : { mangaId: string, children?: } color={ReleaseStatusToPalette(MangaReleaseStatus.Completed)} size={"lg"}> - Manga Cover + Manga Cover - Manga Cover + onError={LoadMangaCover}/> getJobList()); },[apiUri]); - useEffect(() => { - getJobList(); - }, [apiUri]); - useEffect(() => { updateTimer(); - getJobList(); - }, [connected]); + }, [connected, apiUri]); const timerRef = React.useRef>(undefined); - const updateTimer = () => { + const updateTimer = useCallback(() => { if(!connected){ clearTimeout(timerRef.current); return; @@ -45,12 +40,10 @@ export default function MangaList({connected, setShowSearch}: {connected: boolea if(timerRef.current === undefined) { console.log("Added timer!"); getJobList(); - timerRef.current = setInterval(() => { - getJobList(); - }, 2000); + timerRef.current = setInterval(getJobList, 2000); } } - } + }, [getJobList, connected, timerRef]); return( diff --git a/tranga-website/src/api/Manga.tsx b/tranga-website/src/api/Manga.tsx index b12a4dd..7baf77b 100644 --- a/tranga-website/src/api/Manga.tsx +++ b/tranga-website/src/api/Manga.tsx @@ -29,9 +29,7 @@ export const DeleteManga = async (apiUri: string, mangaId: string) : Promise { - if(ref == null || ref == undefined) - return `${apiUri}/v2/Manga/${mangaId}/Cover?width=64&height=64`; - if(mangaId === DefaultManga.mangaId) + if(ref == null || ref == undefined || mangaId === DefaultManga.mangaId) return "/blahaj.png"; return `${apiUri}/v2/Manga/${mangaId}/Cover?width=${ref.clientWidth}&height=${ref.clientHeight}`; }