"use client"; import { PROJECTS } from "@/data/content"; import { useStaggerReveal } from "@/hooks/useAnimations"; import React, { useState, useCallback } from 'react'; import ProjectCard from "@/components/ProjectCard"; import { Layout, Responsive, useContainerWidth, horizontalCompactor, verticalCompactor, DefaultBreakpoints } from "react-grid-layout"; import "react-grid-layout/css/styles.css"; import "react-resizable/css/styles.css"; export default function Projects() { const rowHeight = 250; const defaultExpandedHeightUnits = 2; const visible = useStaggerReveal(PROJECTS.length, 100); const [selectedProject, setSelectedProject] = useState(1); const { width, containerRef, mounted } = useContainerWidth(); const [topCellHeight, setTopCellHeight] = useState(defaultExpandedHeightUnits); const [layouts, setLayouts] = useState>(updateLayout(1)); function setExpandedHeight(height: number) { const gridUnits = height === 0 ? defaultExpandedHeightUnits : Math.ceil(height / rowHeight); setTopCellHeight(gridUnits); setLayouts(updateLayout(selectedProject, gridUnits)); // pass both } function setSelectedHandler(projectId: number) { const id = Number(projectId); setSelectedProject(id); setLayouts(updateLayout(id, topCellHeight)); // pass both } function updateLayout(activeId: number, cellHeight?: number) : Record { const currentSelected = activeId ?? selectedProject; const currentCellHeight = cellHeight ?? topCellHeight; let isSelected = (projectId: number) => projectId === currentSelected; return { "sm": PROJECTS.map((project, i) => { return { i: project.id.toString(), x: isSelected(project.id) ? 0 : (i % 2) + 1, y: isSelected(project.id) ? 0 : Math.floor(i / 2) + (!isSelected(project.id) ? 1 : 0), w: isSelected(project.id) ? 2 : 1, h: project.images && project.images.length > 0 ? currentCellHeight : 1 }; }), "xs": PROJECTS.map((project, i) => { return { i: project.id.toString(), x: 0, y: i, w: 2, h: project.images && project.images.length > 0 ? currentCellHeight : 1 }; }), "xxs": PROJECTS.map((project, i) => { return { i: project.id.toString(), x: 0, y: i, w: 2, h: project.images && project.images.length > 0 ? currentCellHeight : 1 }; }), "md": PROJECTS.map((project, i) => { return { i: project.id.toString(), x: isSelected(project.id) ? 0 : (i % 2) + 1, y: isSelected(project.id) ? 0 : Math.floor(i / 2) + (!isSelected(project.id) ? 1 : 0), w: isSelected(project.id) ? 2 : 1, h: project.images && project.images.length > 0 ? currentCellHeight : 1 }; }), "lg": PROJECTS.map((project, i) => { return { i: project.id.toString(), x: isSelected(project.id) ? 0 : (i % 2) + 1, y: isSelected(project.id) ? 0 : Math.floor(i / 2) + (!isSelected(project.id) ? 1 : 0), w: isSelected(project.id) ? 2 : 1, h: project.images && project.images.length > 0 ? currentCellHeight : 1 }; }), }; }; return (
{"# projects"}

{"Things I've built"}

{mounted && ( {PROJECTS.map((project, i) => (
))}
)}
); }