Skip to content

Commit 8ff0dcd

Browse files
committed
projects layout
1 parent 469f84a commit 8ff0dcd

4 files changed

Lines changed: 95 additions & 23 deletions

File tree

src/components/Home.tsx

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,19 @@
11
import me from "../assets/me.jpg";
22
import Project from "./Project";
3+
import useBreakpoint from "../hooks/breakpoint";
34
import { projects } from "../hooks/projects";
45
import ImageViewer from "./ImageViewer";
6+
import { useMemo } from "react";
57

68
export default function Home() {
9+
const breakpoint = useBreakpoint();
10+
11+
const breakpointCount = useMemo(() => {
12+
if (breakpoint === "lg") return 3;
13+
if (breakpoint === "md") return 2;
14+
return 1;
15+
}, [breakpoint]);
16+
717
return (
818
<>
919
<ImageViewer />
@@ -52,17 +62,23 @@ export default function Home() {
5262
Every side projects I made, and some from university
5363
</span>
5464
</div>
55-
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10 mt-10">
56-
{projects.map((p, index) => (
57-
<Project
58-
key={index}
59-
name={p.name}
60-
description={p.description}
61-
date={p.date}
62-
images={p.images}
63-
tools={p.tools}
64-
links={p.links}
65-
/>
65+
<div className="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-10 mt-20">
66+
{Array.from({ length: breakpointCount }).map((_, index) => (
67+
<div key={index} className="flex flex-col gap-y-10">
68+
{projects
69+
.filter((_, i) => i % breakpointCount === index)
70+
.map((p, i) => (
71+
<Project
72+
key={i}
73+
name={p.name}
74+
description={p.description}
75+
date={p.date}
76+
images={p.images}
77+
tools={p.tools}
78+
links={p.links}
79+
/>
80+
))}
81+
</div>
6682
))}
6783
</div>
6884
</div>

src/components/Project.tsx

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,20 @@ export default function Project({
3838
<h3 className="text-2xl font-bold tracking-tighter">{name}</h3>
3939
<span className="text-sm text-prim/60">{date}</span>
4040
<p className="mt-3 text-prim/80">{description}</p>
41-
<div className="flex gap-3 mt-3 h-40 overflow-x-scroll">
42-
{images.map((m, index) => (
43-
<img
44-
key={`img-${index}`}
45-
src={m}
46-
alt={`${name} image ${index + 1}`}
47-
className="w-40 h-40 rounded cursor-pointer object-cover"
48-
onClick={() => showImages(index)}
49-
/>
50-
))}
51-
</div>
52-
<div className="flex flex-wrap mt-5 gap-x-2 gap-y-0.5">
41+
{images.length > 0 ? (
42+
<div className="flex gap-3 mt-3 h-40 overflow-x-scroll">
43+
{images.map((m, index) => (
44+
<img
45+
key={`img-${index}`}
46+
src={m}
47+
alt={`${name} image ${index + 1}`}
48+
className="w-40 h-40 rounded cursor-pointer object-cover"
49+
onClick={() => showImages(index)}
50+
/>
51+
))}
52+
</div>
53+
) : null}
54+
<div className="flex flex-wrap mt-3 gap-x-2 gap-y-0.5">
5355
{tools.map((t, index) => (
5456
<>
5557
<span key={index} className="text-prim/60 italic">

src/hooks/breakpoint.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import { useState, useEffect } from "react";
2+
3+
export default function useBreakpoint() {
4+
const [breakpoint, setBreakpoint] = useState<"sm" | "md" | "lg">("sm");
5+
6+
useEffect(() => {
7+
const breakpoints = {
8+
sm: window.matchMedia("(min-width: 640px)"),
9+
md: window.matchMedia("(min-width: 768px)"),
10+
lg: window.matchMedia("(min-width: 1024px)"),
11+
};
12+
13+
const determineBreakpoint = () => {
14+
if (breakpoints.lg.matches) setBreakpoint("lg");
15+
else if (breakpoints.md.matches) setBreakpoint("md");
16+
else if (breakpoints.sm.matches) setBreakpoint("sm");
17+
else setBreakpoint("sm");
18+
};
19+
20+
Object.values(breakpoints).forEach((mq) => {
21+
mq.addEventListener("change", determineBreakpoint);
22+
});
23+
24+
determineBreakpoint();
25+
26+
return () => {
27+
Object.values(breakpoints).forEach((mq) => {
28+
mq.removeEventListener("change", determineBreakpoint);
29+
});
30+
};
31+
}, []);
32+
33+
return breakpoint;
34+
}

src/hooks/projects.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ export const projects = [
111111
},
112112
],
113113
},
114+
{
115+
name: "dowdow.github.io",
116+
description: "The current website you are scrolling.",
117+
date: "2022-09",
118+
images: [],
119+
tools: [
120+
"Typescript",
121+
"Vite",
122+
"React 19",
123+
"Tailwind",
124+
"Gamepad API",
125+
"Midi API",
126+
],
127+
links: [
128+
{
129+
name: "GitHub",
130+
link: "https://github.com/Dowdow/dowdow.github.io",
131+
},
132+
],
133+
},
114134
{
115135
name: "Event Sonar",
116136
description:

0 commit comments

Comments
 (0)