From 18f95460a2cde822dfe18dbd3c724470fb49d5d6 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Thu, 29 Feb 2024 20:25:41 -0500 Subject: [PATCH] flexbox update --- package.json | 1 + pnpm-lock.yaml | 20 +++++ src/app/MockData/MockData.ts | 2 +- src/app/home/Page.tsx | 38 ++++++++- src/components/charts/NewsTable.tsx | 7 -- src/components/charts/news/NewsTable.tsx | 80 +++++++++++++++++++ src/components/charts/news/newsColumns.tsx | 19 +++++ src/components/modules/HomepageModuleCard.tsx | 4 +- src/components/modules/HomepageModules.tsx | 10 ++- 9 files changed, 165 insertions(+), 16 deletions(-) delete mode 100644 src/components/charts/NewsTable.tsx create mode 100644 src/components/charts/news/NewsTable.tsx create mode 100644 src/components/charts/news/newsColumns.tsx diff --git a/package.json b/package.json index 92a0da2..d98fe59 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "@nivo/line": "^0.84.0", "@nivo/treemap": "^0.84.0", "@radix-ui/react-slot": "^1.0.2", + "@tanstack/react-table": "^8.13.2", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", "lightweight-charts": "^4.1.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 6001972..fed0f22 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -23,6 +23,9 @@ dependencies: '@radix-ui/react-slot': specifier: ^1.0.2 version: 1.0.2(@types/react@18.2.57)(react@18.2.0) + '@tanstack/react-table': + specifier: ^8.13.2 + version: 8.13.2(react-dom@18.2.0)(react@18.2.0) class-variance-authority: specifier: ^0.7.0 version: 0.7.0 @@ -623,6 +626,23 @@ packages: tslib: 2.6.2 dev: false + /@tanstack/react-table@8.13.2(react-dom@18.2.0)(react@18.2.0): + resolution: {integrity: sha512-b6mR3mYkjRtJ443QZh9sc7CvGTce81J35F/XMr0OoWbx0KIM7TTTdyNP2XKObvkLpYnLpCrYDwI3CZnLezWvpg==} + engines: {node: '>=12'} + peerDependencies: + react: '>=16' + react-dom: '>=16' + dependencies: + '@tanstack/table-core': 8.13.2 + react: 18.2.0 + react-dom: 18.2.0(react@18.2.0) + dev: false + + /@tanstack/table-core@8.13.2: + resolution: {integrity: sha512-/2saD1lWBUV6/uNAwrsg2tw58uvMJ07bO2F1IWMxjFRkJiXKQRuc3Oq2aufeobD3873+4oIM/DRySIw7+QsPPw==} + engines: {node: '>=12'} + dev: false + /@types/d3-color@2.0.6: resolution: {integrity: sha512-tbaFGDmJWHqnenvk3QGSvD3RVwr631BjKRD7Sc7VLRgrdX5mk5hTyoeBL6rXZaeoXzmZwIl1D2HPogEdt1rHBg==} dev: false diff --git a/src/app/MockData/MockData.ts b/src/app/MockData/MockData.ts index 04b9146..3b2e7ec 100644 --- a/src/app/MockData/MockData.ts +++ b/src/app/MockData/MockData.ts @@ -689,7 +689,7 @@ export type newsDataType = { outletLogo: string; }; -export const newsData = [ +export const newsData: newsDataType[] = [ { "headline": "Tesla reports 0-60 under 1s available in latest Roadster", "subtitle": diff --git a/src/app/home/Page.tsx b/src/app/home/Page.tsx index 525144f..7fd0add 100644 --- a/src/app/home/Page.tsx +++ b/src/app/home/Page.tsx @@ -1,9 +1,39 @@ -import { PortfolioModule } from "@/components/modules/HomepageModules"; +"use client"; -export default function Page() { +import { ResponsiveTreeMap } from "@nivo/treemap"; +import { heatmapData as data } from "../MockData/MockData"; + +export default function page() { return ( -
- +
+
+
+
Heatmap
+
+
+ +
+
); } diff --git a/src/components/charts/NewsTable.tsx b/src/components/charts/NewsTable.tsx deleted file mode 100644 index 149492f..0000000 --- a/src/components/charts/NewsTable.tsx +++ /dev/null @@ -1,7 +0,0 @@ -import React from "react"; - -const NewsTable = () => { - return
NewsTable
; -}; - -export default NewsTable; diff --git a/src/components/charts/news/NewsTable.tsx b/src/components/charts/news/NewsTable.tsx new file mode 100644 index 0000000..ab02c74 --- /dev/null +++ b/src/components/charts/news/NewsTable.tsx @@ -0,0 +1,80 @@ +"use client"; + +import { + ColumnDef, + flexRender, + getCoreRowModel, + useReactTable, +} from "@tanstack/react-table"; + +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; + +interface NewsTableProps { + columns: ColumnDef[]; + data: TData[]; +} + +export function NewsTable({ + columns, + data, +}: NewsTableProps) { + const table = useReactTable({ + data, + columns, + getCoreRowModel: getCoreRowModel(), + }); + + return ( +
+ + + {table.getHeaderGroups().map((headerGroup) => ( + + {headerGroup.headers.map((header) => { + return ( + + {header.isPlaceholder + ? null + : flexRender( + header.column.columnDef.header, + header.getContext() + )} + + ); + })} + + ))} + + + {table.getRowModel().rows?.length ? ( + table.getRowModel().rows.map((row) => ( + + {row.getVisibleCells().map((cell) => ( + + {flexRender(cell.column.columnDef.cell, cell.getContext())} + + ))} + + )) + ) : ( + + + No results. + + + )} + +
+
+ ); +} diff --git a/src/components/charts/news/newsColumns.tsx b/src/components/charts/news/newsColumns.tsx new file mode 100644 index 0000000..9706b97 --- /dev/null +++ b/src/components/charts/news/newsColumns.tsx @@ -0,0 +1,19 @@ +"use client"; + +import { ColumnDef } from "@tanstack/react-table"; +import { newsDataType } from "@/app/MockData/MockData"; + +export const newsColumns: ColumnDef[] = [ + { + accessorKey: "headline", + header: "Headline", + }, + { + accessorKey: "dateTime", + header: "Time", + }, + { + accessorKey: "outlet", + header: "Outlet", + }, +]; diff --git a/src/components/modules/HomepageModuleCard.tsx b/src/components/modules/HomepageModuleCard.tsx index 35ad51d..796f41c 100644 --- a/src/components/modules/HomepageModuleCard.tsx +++ b/src/components/modules/HomepageModuleCard.tsx @@ -9,11 +9,11 @@ interface HomepageModuleProps { const HomepageModule = ({ title, children }: HomepageModuleProps) => { return ( -
+
{title}
-
{children}
+
{children}
); }; diff --git a/src/components/modules/HomepageModules.tsx b/src/components/modules/HomepageModules.tsx index a369aa3..352ea16 100644 --- a/src/components/modules/HomepageModules.tsx +++ b/src/components/modules/HomepageModules.tsx @@ -1,9 +1,11 @@ -import { heatmapData, portfolioData } from "@/app/MockData/MockData"; +import { heatmapData, newsData, portfolioData } from "@/app/MockData/MockData"; import HomepageModule from "./HomepageModuleCard"; import PortfolioChart from "../charts/PortfolioChart"; import MarketHeatmap from "../charts/MarketHeatmap"; import { Button } from "../ui/button"; import { ArrowRight } from "lucide-react"; +import { NewsTable } from "../charts/news/NewsTable"; +import { newsColumns } from "../charts/news/newsColumns"; export const PortfolioModule = () => { return ( @@ -25,7 +27,11 @@ export const PortfolioModule = () => { }; export const NewsModule = () => { - return ; + return ( + + + + ); }; export const HeatmapModule = () => {