From 36e326e0f34577cc4f3c7f84044dbd4650d00ba0 Mon Sep 17 00:00:00 2001 From: samet Date: Fri, 2 Feb 2024 14:10:41 +0300 Subject: [PATCH] I think I'm done with it :/ --- app/context/StatsContext.tsx | 5 +- components/stats/BarChartCardWrapper.tsx | 69 ++++++++++++++++++++ components/stats/ChartCardWrapper.tsx | 2 +- components/stats/Charts/CreationDate.tsx | 68 ++----------------- components/stats/Charts/GistCreationDate.tsx | 65 +----------------- components/stats/Charts/StarHistory.tsx | 6 +- components/stats/Charts/StatTable.tsx | 20 ++++-- lib/utils/stats.ts | 17 +++++ 8 files changed, 115 insertions(+), 137 deletions(-) create mode 100644 components/stats/BarChartCardWrapper.tsx diff --git a/app/context/StatsContext.tsx b/app/context/StatsContext.tsx index 4f3076c..499ae00 100644 --- a/app/context/StatsContext.tsx +++ b/app/context/StatsContext.tsx @@ -8,6 +8,7 @@ import { calculateTotalForks, calculateTotalRepos, calculateTotalStars, + calculateTotalTopics, findLatestUpdatedRepo, findMostStarredRepo, findOldestRepo, @@ -24,6 +25,7 @@ type StatsContextProps = { totalStars: number; totalGists: number; totalForks: number; + totalTopics: number; averageStarsPerRepo: number; starsPerRepo: Record; languages: Record; @@ -63,13 +65,14 @@ export const StatsProvider: React.FC<{ children: React.ReactNode }> = ({ const latestUpdatedRepo = findLatestUpdatedRepo(repos); const oldestRepo = findOldestRepo(repos); const updatePeriod = findRepoWithLongestUpdatePeriod(repos); - + const totalTopics = calculateTotalTopics(repos); // Create the context value object const statsContextValue: StatsContextProps = { totalRepos, totalGists, totalStars, totalForks, + totalTopics, averageStarsPerRepo, starsPerRepo, languages, diff --git a/components/stats/BarChartCardWrapper.tsx b/components/stats/BarChartCardWrapper.tsx new file mode 100644 index 0000000..001e124 --- /dev/null +++ b/components/stats/BarChartCardWrapper.tsx @@ -0,0 +1,69 @@ +import { Box, Card, Heading, ScrollArea, Table } from "@radix-ui/themes"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "@/components/ui/accordion"; +import { BarChart } from "@mui/x-charts/BarChart"; + +export default function BarChartCardWrapper({ + data, + title, +}: { + data: Object; + title: string; +}) { + const statsData = Object.entries(data).map(([year, count]) => ({ + category: year, + value: count, + })); + if (Object.entries(data).length === 0) return null; + return ( + + {title} + + d.category), + scaleType: "band", + }, + ]} + series={[ + { + data: statsData.map((d) => d.value), + }, + ]} + /> + + {Object.entries.length > 5 && ( + + + See All + + + + + + Year + Count + + + + {statsData.map((data) => ( + + {data.category} + {data.value} + + ))} + + + + + + + )} + + ); +} diff --git a/components/stats/ChartCardWrapper.tsx b/components/stats/ChartCardWrapper.tsx index a416b3e..10787ba 100644 --- a/components/stats/ChartCardWrapper.tsx +++ b/components/stats/ChartCardWrapper.tsx @@ -70,7 +70,7 @@ export default function ChartCardWrapper({ {Object.entries(data).length > 5 && ( - See All {title} + See All diff --git a/components/stats/Charts/CreationDate.tsx b/components/stats/Charts/CreationDate.tsx index c4bafba..49efbea 100644 --- a/components/stats/Charts/CreationDate.tsx +++ b/components/stats/Charts/CreationDate.tsx @@ -1,72 +1,14 @@ -import { Box, Card, Heading, ScrollArea, Table } from "@radix-ui/themes"; -import { - Accordion, - AccordionContent, - AccordionItem, - AccordionTrigger, -} from "@/components/ui/accordion"; -import { BarChart } from "@mui/x-charts/BarChart"; import { StatsContext } from "@/app/context/StatsContext"; import { useContext } from "react"; +import BarChartCardWrapper from "../BarChartCardWrapper"; export default function CreationDate() { const statsContext = useContext(StatsContext); const creationStats = statsContext?.creationStats || {}; - const statsData = Object.entries(creationStats).map(([year, count]) => ({ - category: year, - value: count, - })); - if (Object.entries(creationStats).length === 0) return null; return ( - <> - - Repository Creation Dates - - d.category), - scaleType: "band", - }, - ]} - series={[ - { - data: statsData.map((d) => d.value), - }, - ]} - /> - - - - See All Creation Dates - - - - - - Year - Count - - - - {statsData - .sort((a, b) => Number(b.value) - Number(a.value)) - .map((data) => ( - - {data.category} - {data.value} - - ))} - - - - - - - - + ); } diff --git a/components/stats/Charts/GistCreationDate.tsx b/components/stats/Charts/GistCreationDate.tsx index 39d9045..44bce4c 100644 --- a/components/stats/Charts/GistCreationDate.tsx +++ b/components/stats/Charts/GistCreationDate.tsx @@ -1,73 +1,12 @@ -import { Box, Card, Heading, ScrollArea, Table } from "@radix-ui/themes"; -import { - Accordion, - AccordionContent, - AccordionItem, - AccordionTrigger, -} from "@/components/ui/accordion"; -import { BarChart } from "@mui/x-charts/BarChart"; import { StatsContext } from "@/app/context/StatsContext"; import { useContext } from "react"; +import BarChartCardWrapper from "../BarChartCardWrapper"; export default function GistCreationDate() { const statsContext = useContext(StatsContext); const gistCreationStats = statsContext?.gistCreationStats || {}; - const statsData = Object.entries(gistCreationStats).map(([year, count]) => ({ - category: year, - value: count, - })); - if (Object.entries(gistCreationStats).length === 0) return null; return ( - <> - - Gist Creation Dates - - d.category), - scaleType: "band", - }, - ]} - series={[ - { - data: statsData.map((d) => d.value), - }, - ]} - /> - - - - See All Creation Dates - - - - - - Year - Count - - - - {statsData - .sort((a, b) => Number(b.value) - Number(a.value)) - .map((data) => ( - - {data.category} - {data.value} - - ))} - - - - - - - - + ); } diff --git a/components/stats/Charts/StarHistory.tsx b/components/stats/Charts/StarHistory.tsx index 703c8a4..70a0d98 100644 --- a/components/stats/Charts/StarHistory.tsx +++ b/components/stats/Charts/StarHistory.tsx @@ -69,8 +69,8 @@ export default function StarHistory({ - - + +
Star History