Skip to content

Commit

Permalink
add skeleton view while images download
Browse files Browse the repository at this point in the history
  • Loading branch information
houseplayer committed Dec 29, 2024
1 parent afc14e8 commit beb57b5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions src/app/images/Images.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { KeyedMutator } from "swr"
import DeleteButton from "./DeleteButton"
import { FaTrashAlt } from "react-icons/fa"

export interface Image {
name: string
Expand All @@ -16,23 +17,35 @@ interface Props {
}

const Images = ({ data, isLoading, mutate }: Props) => {
if (isLoading) return <p>Loading...</p>
if (isLoading)
return (
<div className="flex flex-col items-center">
<div className="flex flex-col mx-2 items-center justify-center w-[300px] h-[420px] border-2 border-black mb-2">
Loading ...
</div>
<FaTrashAlt className="mb-12" />
</div>
)

const { images } = data

const sortedImages = images.sort((a, b) => (a.updatedAt > b.updatedAt ? -1 : 1))

return (
<div className="flex flex-col items-center">
<>
{sortedImages.map(({ name, id, url }) => {
return (
<div className="flex flex-col mx-2 mb-12 items-center max-w-[300px]" key={name}>
<img className="mb-2 border-2 border-black" src={url} alt="downloaded image" />
<div className="flex flex-col items-center mb-12" key={name}>
<img
className="w-[300px] h-[420px] mb-2 border-2 border-black"
src={url}
alt="downloaded image"
/>
<DeleteButton id={id} mutate={mutate} />
</div>
)
})}
</div>
</>
)
}

Expand Down

0 comments on commit beb57b5

Please sign in to comment.