Skip to content

Commit

Permalink
Update about page image loading
Browse files Browse the repository at this point in the history
  • Loading branch information
ALPHAAAL committed Apr 15, 2024
1 parent e9b0c41 commit 96f2f5d
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
6 changes: 3 additions & 3 deletions src/components/About/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type JobRole = {
}[];
}

const VyondIcon = <LazyImage className='mr-3' needSrcSet={false} width={35} height={35} src='vyond' placeholderImage={hashToDataUrl("X+sGDwJXSIeHeIiAepp32FeGhIr3qHgP")} />;
const VyondIcon = <LazyImage className='mr-3' needSrcSet={false} width={35} height={35} src='vyond' />;
const BenoveltyIcon = <LazyImage className='mr-3' needSrcSet={false} width={35} height={35} src='benovelty' />;
const VYOND_ROLES = [
{
Expand Down Expand Up @@ -91,8 +91,8 @@ export default function About() {
<div>
<div className="w-full sm:mt-10">
<div className='grid grid-cols-1 gap-y-6 sm:pr-3 lg:grid-cols-2 lg:grid-rows-[auto_1fr]'>
<div className='lg:col-start-2 lg:pl-10'>
<LazyImage src={'DSC01603'} placeholderImage={hashToDataUrl('aggSDwKZaIiPd3h7h1d3iIh4dwVYN4AB')} />
<div className='lg:col-start-2 lg:pl-10 max-w-sm xl:max-w-xl mx-auto'>
<LazyImage width={500} height={500} src={'DSC01603'} placeholderImage={hashToDataUrl('aggSDwKZaIiPd3h7h1d3iIh4dwVYN4AB')} />
</div>
<div className='lg:col-start-1 lg:row-start-1 lg:row-span-2'>
<h1 className="mt-3 text-6xl font-bold">Alex Lau</h1>
Expand Down
2 changes: 1 addition & 1 deletion src/components/Gallery/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import IMAGE_JSON from '../../assets/img/images.json';

const images = Object.values(IMAGE_JSON).map(({ name, width, height, hash }) => {
return (
<LazyImage key={hash} src={name} width={width} height={height} placeholderImage={hashToDataUrl(hash)} />
<LazyImage className='mb-3' key={hash} src={name} width={width} height={height} placeholderImage={hashToDataUrl(hash)} />
);
});

Expand Down
4 changes: 3 additions & 1 deletion src/components/Home/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ import IMAGE_JSON from '../../assets/img/images.json';
const images = Object.values(IMAGE_JSON).map(({ name, hash, width, height }) => {
const sh = window.screen.height;
const newHeight = sh > 1280 ? Math.min(400, height) : Math.min(300, height);
const scale = newHeight / height;
const newWidth = Math.floor(width * scale);

return (
<LazyImage key={hash} src={name} height={newHeight} width={width} placeholderImage={hashToDataUrl(hash)} className='max-h-[300px] xl:max-h-[400px]' />
<LazyImage key={hash} src={name} height={newHeight} width={newWidth} placeholderImage={hashToDataUrl(hash)} className='max-h-[300px] xl:max-h-[400px]' />
);
});
const mobileImages = Object.values(IMAGE_JSON).map(({ name, hash, width, height }) => {
Expand Down
23 changes: 12 additions & 11 deletions src/components/LazyImage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { useMemo } from "react"
import clsx from "clsx";

type LazyImageProps = React.ComponentProps<'img'> & {
placeholderImage?: string;
Expand All @@ -19,16 +20,16 @@ export default function LazyImage(props: LazyImageProps) {
}, [placeholderImage]);

return (
<img
className={className}
style={style}
src={`/assets/images/${src}.webp`}
srcSet={needSrcSet ? `/assets/images/${src}.webp 1920w, /assets/images/${src}_mobile.webp 375w`: undefined}
decoding="async"
loading="lazy"
width={width}
height={height}
alt={src}
/>
<div style={style} className={clsx("flex-none self-center", className)}>
<img
src={`/assets/images/${src}.webp`}
srcSet={needSrcSet ? `/assets/images/${src}.webp 1920w, /assets/images/${src}_mobile.webp 375w` : undefined}
decoding="async"
loading="lazy"
width={width}
height={height}
alt={src}
/>
</div>
)
}

0 comments on commit 96f2f5d

Please sign in to comment.