Skip to content

Commit

Permalink
refactor(app): 129 grid psts
Browse files Browse the repository at this point in the history
  • Loading branch information
huilensolis committed Mar 16, 2024
1 parent 82ca299 commit 20232df
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
23 changes: 13 additions & 10 deletions src/components/feature/lazy-image/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,13 @@

import { Skeleton } from "@/components/ui/skeleton";
import { ImageOff } from "lucide-react";
import { type HTMLAttributes, useEffect, useRef, useState } from "react";
import {
type HTMLAttributes,
useEffect,
useRef,
useState,
useCallback,
} from "react";

type TProps = {
src: string;
Expand Down Expand Up @@ -38,19 +44,16 @@ export function LazyImage({
setError(true);
};

const imageRef = useRef<HTMLImageElement>(null);
const imageRef = useCallback((node: HTMLImageElement) => {
if (!node) return;
if (node.complete) handleImageLoad();

useEffect(() => {
if (!imageRef.current) return;

if (imageRef.current.complete) handleImageLoad();

imageRef.current.onload = handleImageLoad;
imageRef.current.onerror = handleImageError;
node.onload = handleImageLoad;
node.onerror = handleImageError;
}, []);

return (
<div className={`relative ${containerClassname}`}>
<div className={containerClassname}>
<div className="relative">
{!error && (
<img
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function PostsGridRow({
const imageHeight = (post.asset_height * columnWidth) / post.asset_width;
return (
<li
className={`flex w-full mb-2`}
className="flex w-full mb-2"
style={{ width: columnWidth, height: imageHeight }}
>
<Link
Expand Down
4 changes: 1 addition & 3 deletions src/components/feature/posts-grid/posts-grid.component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ export function PostsGrid({
<div ref={lastItemRef} className="h-96 w-full" />
</>
)}
{(isFetching || isLoadingFirstTime) && (
<PostsGridSkeleton cuantity={32} />
)}
{isLoadingFirstTime && <PostsGridSkeleton cuantity={32} />}
</PostsGridContainer>
</>
);
Expand Down

0 comments on commit 20232df

Please sign in to comment.