Skip to content

Commit

Permalink
[open-profile-images] make loading images smoother
Browse files Browse the repository at this point in the history
  • Loading branch information
ioj4 committed Nov 25, 2024
1 parent 18e2748 commit 70cfc29
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions plugins/open-profile-images/components/image-modal.jsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
import classes from "../styles.jsx.scss";
const {
solid: { createSignal }
} = shelter;

export default ({ url }) => {
const [isLoaded, setIsLoaded] = createSignal(false);

const lowResUrl = url.toString();
const isBanner = url.pathname.startsWith("/banners/");

url.searchParams.set("size", "4096");
const viewUrl = url.toString();
const fullResUrl = url.toString();

const preloadImage = new Image();
preloadImage.onload = () => setIsLoaded(true);
preloadImage.src = fullResUrl;

// to .png extension
const browserURL = viewUrl.replace(/\.(webp)($|\?)/, ".png$2");
const browserURL = fullResUrl.replace(/\.(webp)($|\?)/, ".png$2");

return (
<>
<div class={classes.wrapper}>
<img
class={`${classes.image} ${isBanner ? classes.banner : ""}`}
src={viewUrl}
src={isLoaded() ? fullResUrl : lowResUrl}
/>
<a
href={browserURL}
Expand Down

0 comments on commit 70cfc29

Please sign in to comment.