Skip to content

Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.

Combine barcharts using toggle

Khuram Niazd98beaaadf10
diff --git a/src/app/dashboard/page.tsx b/src/app/dashboard/page.tsx
index c4d1ad7..42ff1be 100644
--- a/src/app/dashboard/page.tsx
+++ b/src/app/dashboard/page.tsx
@@ -9,7 +9,7 @@ import ActivityCalendar from "@/components/dashboard/ActivityCalendar";
import JobsApplied from "@/components/dashboard/JobsAppliedCard";
import NumberCardToggle from "@/components/dashboard/NumberCardToggle";
import RecentJobsCard from "@/components/dashboard/RecentJobsCard";
-import WeeklyBarChart from "@/components/dashboard/WeeklyBarChart";
+import WeeklyBarChartToggle from "@/components/dashboard/WeeklyBarChartToggle";
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
import { Metadata } from "next";
@@ -39,9 +39,9 @@ export default async function Dashboard() {
Array.from(
new Set(
data.flatMap((entry) =>
- Object.keys(entry).filter((key) => key !== "day")
- )
- )
+ Object.keys(entry).filter((key) => key !== "day"),
+ ),
+ ),
);
return (
<>
@@ -50,32 +50,36 @@ export default async function Dashboard() {
<JobsApplied />
<NumberCardToggle
data={[
- { label: "Last 7 days", num: jobsAppliedLast7Days, trend: trendFor7Days },
- { label: "Last 30 days", num: jobsAppliedLast30Days, trend: trendFor30Days },
+ {
+ label: "Last 7 days",
+ num: jobsAppliedLast7Days,
+ trend: trendFor7Days,
+ },
+ {
+ label: "Last 30 days",
+ num: jobsAppliedLast30Days,
+ trend: trendFor30Days,
+ },
]}
/>
</div>
- <Tabs defaultValue="jobs">
- <TabsList>
- <TabsTrigger value="jobs">Weekly Jobs</TabsTrigger>
- <TabsTrigger value="activities">Activities</TabsTrigger>
- </TabsList>
- <TabsContent value="jobs">
- <WeeklyBarChart
- data={weeklyData}
- keys={["value"]}
- axisLeftLegend="NUMBER OF JOBS APPLIED"
- />
- </TabsContent>
- <TabsContent value="activities">
- <WeeklyBarChart
- data={activitiesData}
- keys={activitiesDataKeys(activitiesData)}
- groupMode="stacked"
- axisLeftLegend="TIME SPENT (Hours)"
- />
- </TabsContent>
- </Tabs>
+ <WeeklyBarChartToggle
+ charts={[
+ {
+ label: "Jobs",
+ data: weeklyData,
+ keys: ["value"],
+ axisLeftLegend: "NUMBER OF JOBS APPLIED",
+ },
+ {
+ label: "Activities",
+ data: activitiesData,
+ keys: activitiesDataKeys(activitiesData),
+ groupMode: "stacked",
+ axisLeftLegend: "TIME SPENT (Hours)",
+ },
+ ]}
+ />
</div>
<div>
<RecentJobsCard jobs={recentJobs} />
diff --git a/src/components/dashboard/WeeklyBarChartToggle.tsx b/src/components/dashboard/WeeklyBarChartToggle.tsx
new file mode 100644
index 0000000..29d1c38
--- /dev/null
+++ b/src/components/dashboard/WeeklyBarChartToggle.tsx
@@ -0,0 +1,121 @@
+"use client";
+
+import { useState } from "react";
+import { ResponsiveBar } from "@nivo/bar";
+import { Card, CardContent } from "../ui/card";
+import { cn } from "@/lib/utils";
+
+type ChartConfig = {
+ label: string;
+ data: any[];
+ keys: string[];
+ groupMode?: "grouped" | "stacked";
+ axisLeftLegend: string;
+};
+
+type WeeklyBarChartToggleProps = {
+ charts: ChartConfig[];
+};
+
+export default function WeeklyBarChartToggle({
+ charts,
+}: WeeklyBarChartToggleProps) {
+ const [activeIndex, setActiveIndex] = useState(0);
+ const current = charts[activeIndex];
+
+ const roundedData = current.data.map((item) => {
+ const newItem: any = { ...item };
+ current.keys.forEach((key) => {
+ if (typeof newItem[key] === "number") {
+ newItem[key] = Math.round(newItem[key] * 100) / 100;
+ }
+ });
+ return newItem;
+ });
+
+ return (
+ <Card className="mb-2 lg:mb-0">
+ <CardContent className="h-[240px] p-3 pt-1">
+ <div className="flex items-center justify-end mb-1 mt-3">
+ <div className="flex rounded-md border text-xs">
+ {charts.map((chart, index) => (
+ <button
+ key={chart.label}
+ onClick={() => setActiveIndex(index)}
+ className={cn(
+ "px-2 py-1 transition-colors",
+ index === 0 && "rounded-l-md",
+ index === charts.length - 1 && "rounded-r-md",
+ activeIndex === index
+ ? "bg-primary text-primary-foreground"
+ : "hover:bg-muted",
+ )}
+ >
+ {chart.label}
+ </button>
+ ))}
+ </div>
+ </div>
+ <div className="h-[200px]">
+ <ResponsiveBar
+ data={roundedData}
+ keys={current.keys}
+ indexBy="day"
+ margin={{
+ top: 20,
+ right: 10,
+ bottom: 40,
+ left: 45,
+ }}
+ padding={0.6}
+ groupMode={current.groupMode}
+ colors={
+ current.groupMode === "stacked" ? { scheme: "nivo" } : "#2a7ef0"
+ }
+ enableTotals={current.groupMode === "stacked" ? true : false}
+ valueFormat={(value) => value.toFixed(2)}
+ theme={{
+ text: {
+ fill: "#9ca3af",
+ },
+ tooltip: {
+ container: {
+ background: "#1e293b",
+ color: "#fff",
+ },
+ },
+ }}
+ axisTop={null}
+ axisRight={null}
+ enableGridX={false}
+ enableGridY={false}
+ enableLabel={true}
+ labelTextColor={{
+ from: "color",
+ modifiers: [["darker", 1.6]],
+ }}
+ axisBottom={{
+ tickSize: 5,
+ tickPadding: 5,
+ tickRotation: 0,
+ legend: "DAYS OF WEEK",
+ legendPosition: "middle",
+ legendOffset: 32,
+ truncateTickAt: 0,
+ }}
+ axisLeft={{
+ tickSize: 5,
+ tickPadding: 5,
+ tickRotation: 0,
+ legend: current.axisLeftLegend,
+ legendPosition: "middle",
+ legendOffset: -40,
+ truncateTickAt: 0,
+ }}
+ motionConfig="gentle"
+ />
+ </div>
+ </CardContent>
+ </Card>
+ );
+}
diff --git a/src/components/ui/card.tsx b/src/components/ui/card.tsx
index afa13ec..828a42c 100644
--- a/src/components/ui/card.tsx
+++ b/src/components/ui/card.tsx
@@ -1,6 +1,6 @@
-import * as React from "react"
+import * as React from "react";
-import { cn } from "@/lib/utils"
+import { cn } from "@/lib/utils";
const Card = React.forwardRef<
HTMLDivElement,
@@ -10,12 +10,12 @@ const Card = React.forwardRef<
ref={ref}
className={cn(
"rounded-lg border bg-card text-card-foreground shadow-sm",
- className
+ className,
)}
{...props}
/>
-))
-Card.displayName = "Card"
+));
+Card.displayName = "Card";
const CardHeader = React.forwardRef<
HTMLDivElement,
@@ -23,11 +23,11 @@ const CardHeader = React.forwardRef<
>(({ className, ...props }, ref) => (
<div
ref={ref}
- className={cn("flex flex-col space-y-1.5 p-6", className)}
+ className={cn("flex flex-col space-y-1.5 p-4", className)}
{...props}
/>
-))
-CardHeader.displayName = "CardHeader"
+));
+CardHeader.displayName = "CardHeader";
const CardTitle = React.forwardRef<
HTMLParagraphElement,
@@ -37,12 +37,12 @@ const CardTitle = React.forwardRef<
ref={ref}
className={cn(
"text-2xl font-semibold leading-none tracking-tight",
- className
+ className,
)}
{...props}
/>
-))
-CardTitle.displayName = "CardTitle"
+));
+CardTitle.displayName = "CardTitle";
const CardDescription = React.forwardRef<
HTMLParagraphElement,
@@ -53,16 +53,16 @@ const CardDescription = React.forwardRef<
className={cn("text-sm text-muted-foreground", className)}
{...props}
/>
-))
-CardDescription.displayName = "CardDescription"
+));
+CardDescription.displayName = "CardDescription";
const CardContent = React.forwardRef<
HTMLDivElement,
React.HTMLAttributes<HTMLDivElement>
>(({ className, ...props }, ref) => (
<div ref={ref} className={cn("p-6 pt-0", className)} {...props} />
-))
-CardContent.displayName = "CardContent"
+));
+CardContent.displayName = "CardContent";
const CardFooter = React.forwardRef<
HTMLDivElement,
@@ -73,7 +73,14 @@ const CardFooter = React.forwardRef<
className={cn("flex items-center p-6 pt-0", className)}
{...props}
/>
-))
-CardFooter.displayName = "CardFooter"
+));
+CardFooter.displayName = "CardFooter";
-export { Card, CardHeader, CardFooter, CardTitle, CardDescription, CardContent }
+export {
+ Card,
+ CardHeader,
+ CardFooter,
+ CardTitle,
+ CardDescription,
+ CardContent,
+};