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