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