reload images (#515)

Co-authored-by: neil molina <neil@neils-MacBook-Pro.local>
This commit is contained in:
Neil 2023-04-27 18:03:13 +08:00 committed by GitHub
parent 7088fec009
commit 0c76b29787
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -13,6 +13,7 @@
const defaultImgUrl = "/images/default-thumb.jpg";
$: loadedImg = "";
let loaded = false;
let lastProcessedPkg: GUIPackage | null = null;
const loadImage = async (url: string): Promise<string> => {
const image = new Image();
@ -36,7 +37,7 @@
loadImage(url);
};
onMount(() => {
const getCache = async () => {
if (pkg.cached_image_url) {
loadImage(pkg.cached_image_url).catch(() => {
if (pkg.thumb_image_url) {
@ -47,7 +48,16 @@
} else if (pkg.thumb_image_url) {
recachePkg();
}
});
}
$: {
if (pkg && pkg?.slug !== lastProcessedPkg?.slug) {
loaded = false;
loadedImg = "";
lastProcessedPkg = pkg;
getCache();
}
}
</script>
<section class="bg-black {clazz} {layout}">