Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ASC-83: Media Grid #32

Merged
merged 1 commit into from
Oct 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
"@phosphor-icons/react": "^2.0.15",
"clsx": "^2.1.0",
"firebase": "^10.12.2",
"masonic": "^4.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.9.0",
Expand Down
28 changes: 28 additions & 0 deletions src/components/MediaGrid.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { Masonry } from "masonic";
import MediaCard from "./MediaCard";

interface MediaGridProps {
data: Media[];
}

function MediaGrid({ data }: MediaGridProps) {
return (
<Masonry
items={data}
render={MasonryItem}
columnGutter={12}
columnWidth={320}
overscanBy={5}
/>
);
}

interface MasonryItemProps {
data: Media;
}

function MasonryItem({ data }: MasonryItemProps) {
return <MediaCard {...data} />;
}

export default MediaGrid;
143 changes: 88 additions & 55 deletions src/routes/test/MediaCardTestRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,94 @@
import MediaCard from "@/components/MediaCard";
import MediaGrid from "@/components/MediaGrid";
import { ToastContainer } from "react-toastify";

const getMeta = (
url: string,
cb: (error: string | Event | null, img?: HTMLImageElement | null) => void,
) => {
const img = new Image();
img.onload = () => cb(null, img);
img.onerror = (err) => cb(err);
img.src = url;
};
const data = [
{
src: "https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1234,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1723984834599-5357b87f727c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1235,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724505599369-2c1d43324fdc",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1236,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1237,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1723984834599-5357b87f727c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1238,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724505599369-2c1d43324fdc",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1239,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1240,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1723984834599-5357b87f727c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1241,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724505599369-2c1d43324fdc",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1242,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1240,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1723984834599-5357b87f727c",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1241,
date: new Date("Oct 2, 2024"),
},
{
src: "https://images.unsplash.com/photo-1724505599369-2c1d43324fdc",
caption:
"Channeling their inner artist with a paintbrush and a splash of color!",
id: 1242,
date: new Date("Oct 2, 2024"),
},
];

function MediaCardTestRoute() {
getMeta(
"https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c",
(err, img) => {
console.log(img?.naturalWidth, img?.naturalHeight);
},
);
return (
<div className="bg-blue-200 min-h-screen flex justify-center items-center p-4">
<ToastContainer
Expand All @@ -27,45 +98,7 @@ function MediaCardTestRoute() {
closeButton={false}
hideProgressBar={true}
/>
<div className="grid grid-flow-row grid-cols-4 gap-8 md:gap-12 lg:gap-16">
<MediaCard
src="https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
selectable
/>
<MediaCard
src="https://images.unsplash.com/photo-1723984834599-5357b87f727c"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
/>
<MediaCard
src="https://images.unsplash.com/photo-1724505599369-2c1d43324fdc"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
/>
<MediaCard
src="https://images.unsplash.com/photo-1724579243894-6a8c9bbfe88c"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
/>
<MediaCard
src="https://images.unsplash.com/photo-1724505599369-2c1d43324fdc"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
/>
<MediaCard
src="https://images.unsplash.com/photo-1723984834599-5357b87f727c"
caption="Channeling their inner artist with a paintbrush and a splash of color!"
id={1234}
date={new Date("Oct 2, 2024")}
/>
</div>
<MediaGrid data={data} />
</div>
);
}
Expand Down
6 changes: 6 additions & 0 deletions src/types/Media.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
interface Media {
src: string;
caption?: string | null;
date: Date;
id: number;
}
Loading