Skip to content

Commit

Permalink
refined approach using useRef and single Card
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriele Granello committed Jan 8, 2025
1 parent 15a23eb commit f5983b1
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 153 deletions.
39 changes: 20 additions & 19 deletions app/components/ui/Dashboard.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,37 @@
import React from "react";
import GraphCard1 from "./GraphCard1";
import GraphCard2 from "./GraphCard2";
import GraphCard3 from "./GraphCard3";
import GraphCard4 from "./GraphCard4";
import GraphCard5 from "./GraphCard5";
import GraphCard6 from "./GraphCard6";
import React, { useRef } from "react";
import GraphCard from "./GraphCard";
import { Household } from "@/app/models/Household";

interface DashboardProps {
data: Household;
}

const Dashboard: React.FC<DashboardProps> = ({ data }) => {
const scrollContainerRef = useRef<HTMLDivElement>(null);
const handleNext = () => {
const container = document.querySelector(".snap-scroll") as HTMLElement;
if (container) {
container.scrollBy({
top: window.innerHeight, // Scroll by one viewport height
behavior: "smooth", // Smooth scrolling
if (scrollContainerRef.current) {
scrollContainerRef.current.scrollBy({
top: window.innerHeight,
behavior: "smooth",
});
}
};

// Dummy identity function to avoid linting errors
const identity = (data: Household) => {
return data;
};
identity(data);

return (
<div className="snap-container">
<div className="snap-scroll">
<GraphCard1 household={data} />
<GraphCard2 household={data} />
<GraphCard3 household={data} />
<GraphCard4 household={data} />
<GraphCard5 household={data} />
<GraphCard6 household={data} />
<div className="snap-scroll" ref={scrollContainerRef}>
<GraphCard title="How much would a Fairhold home cost?" />
<GraphCard title="How much would it cost every month?" />
<GraphCard title="How would the cost change over my life?" />
<GraphCard title="How much could I sell it for?" />
<GraphCard title="What difference would Fairhold make to me, my community, and the world?" />
<GraphCard title="What would you choose?" />
</div>

<div className="fixed bottom-4 right-4">
Expand Down
15 changes: 15 additions & 0 deletions app/components/ui/GraphCard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";

type Props = React.PropsWithChildren<{
title: string;
}>;

const GraphCard: React.FC<Props> = ({ title }) => {
return (
<div className="h-screen snap-start">
<span className="text-2xl text-black">{title}</span>
</div>
);
};

export default GraphCard;
23 changes: 0 additions & 23 deletions app/components/ui/GraphCard1.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions app/components/ui/GraphCard2.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions app/components/ui/GraphCard3.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions app/components/ui/GraphCard4.tsx

This file was deleted.

23 changes: 0 additions & 23 deletions app/components/ui/GraphCard5.tsx

This file was deleted.

21 changes: 0 additions & 21 deletions app/components/ui/GraphCard6.tsx

This file was deleted.

0 comments on commit f5983b1

Please sign in to comment.