Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/app/api/dashboard/overview/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ describe("/api/dashboard/overview", () => {
expect(getDashboardOverviewMock).toHaveBeenCalledWith({
accessToken: "supabase-token",
forceRefresh: false,
requestOrigin: "https://gitfusion.test",
});
});

Expand Down Expand Up @@ -128,6 +129,7 @@ describe("/api/dashboard/overview", () => {
expect(getDashboardOverviewMock).toHaveBeenCalledWith({
accessToken: "supabase-token",
forceRefresh: true,
requestOrigin: "https://gitfusion.test",
});
});

Expand Down
1 change: 1 addition & 0 deletions src/app/api/dashboard/overview/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export async function GET(request: NextRequest) {
const result = await getDashboardOverview({
accessToken,
forceRefresh,
requestOrigin: request.nextUrl.origin,
});

return NextResponse.json(result);
Expand Down
360 changes: 330 additions & 30 deletions src/app/dashboard/page.tsx

Large diffs are not rendered by default.

27 changes: 15 additions & 12 deletions src/app/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@
}

.dark {
--background: #080a17;
--foreground: #f4f4f5;
--background: #070a16;
--foreground: #f4f6fb;

--surface: #101421;
--card: #151927;
--card-hover: #1a1f2f;
--surface: #0d1222;
--card: #0d1324;
--card-hover: #131a2d;

--border: #252a3b;
--border: #27315a;

--muted: #1b2030;
--muted-foreground: #9299aa;
--muted: #171d34;
--muted-foreground: #97a0b8;

--heatmap-empty: #1b2030;
--heatmap-empty: #151b34;
}

@theme {
Expand All @@ -62,7 +62,10 @@
}

body {
background: var(--background);
background:
radial-gradient(circle at 70% -12%, rgba(139, 92, 246, 0.16), transparent 30rem),
radial-gradient(circle at 4% 8%, rgba(76, 29, 149, 0.16), transparent 24rem),
var(--background);
color: var(--foreground);
}

Expand Down Expand Up @@ -128,8 +131,8 @@ body {
}

.gf-contribution-calendar .react-calendar-heatmap rect {
rx: 2px;
ry: 2px;
rx: 2.5px;
ry: 2.5px;
}

/* Empty days */
Expand Down
45 changes: 33 additions & 12 deletions src/features/dashboard/components/activity-list.tsx
Original file line number Diff line number Diff line change
@@ -1,34 +1,55 @@
import { useState } from "react";
import { FaGithub, FaGitlab } from "react-icons/fa";
import { ActivityItem } from "@/types/mock-app";

export function ActivityList({ activities }: { activities: ActivityItem[] }) {
export function ActivityList({ activities, className = "" }: { activities: ActivityItem[]; className?: string }) {
const [showAllOnMobile, setShowAllOnMobile] = useState(false);
const visibleActivities = activities.slice(0, 6);

return (
<section className="min-w-0 rounded-lg border border-gray-200 bg-card p-4 shadow-sm dark:border-gray-800 sm:p-5">
<h2 className="text-lg font-extrabold">Recent activity</h2>
<div className="mt-4 space-y-4">
<section className={`min-w-0 flex flex-col rounded-lg border border-border bg-card/85 p-5 shadow-sm ${className}`}>
<div className="flex items-center justify-between gap-3">
<h2 className="text-base font-extrabold">Recent activity</h2>
<span className="text-xs font-bold text-muted-foreground">Latest</span>
</div>
<div className="mt-4 divide-y divide-border/70 overflow-hidden">
{!activities.length && (
<div className="rounded-md border border-gray-200 bg-background p-4 text-sm leading-6 text-muted-foreground dark:border-gray-800">
<div className="rounded-md border border-border bg-background p-4 text-sm leading-6 text-muted-foreground">
No recent provider activity was returned yet.
</div>
)}
{activities.map((activity) => {
{visibleActivities.map((activity, index) => {
const Icon = activity.platform === "github" ? FaGithub : FaGitlab;
const isExtraOnMobile = index >= 4 && !showAllOnMobile;

return (
<article key={activity.id} className="flex gap-3">
<span className="mt-1 grid size-8 shrink-0 place-items-center rounded-md bg-background text-muted-foreground">
<article
key={activity.id}
className={`gap-3 py-3 first:pt-0 last:pb-0 sm:flex ${isExtraOnMobile ? "hidden" : "flex"}`}
>
<span className="mt-0.5 grid size-9 shrink-0 place-items-center rounded-lg border border-primary/15 bg-primary/12 text-primary">
<Icon className="size-4" aria-hidden />
</span>
<div className="min-w-0 flex-1">
<div className="flex flex-col gap-1 sm:flex-row sm:items-center sm:justify-between">
<h3 className="font-bold">{activity.title}</h3>
<time className="text-xs font-semibold text-muted-foreground">{activity.time}</time>
<div className="flex items-start justify-between gap-3">
<h3 className="min-w-0 truncate text-sm font-extrabold">{activity.title}</h3>
<time className="shrink-0 text-xs font-semibold text-muted-foreground">{activity.time}</time>
</div>
<p className="mt-1 overflow-hidden text-ellipsis text-sm text-muted-foreground sm:truncate">{activity.description}</p>
<p className="mt-1 overflow-hidden text-ellipsis text-xs font-semibold text-muted-foreground sm:truncate">{activity.description}</p>
</div>
</article>
);
})}
</div>
{visibleActivities.length > 4 && (
<button
type="button"
onClick={() => setShowAllOnMobile((current) => !current)}
className="mt-3 text-center text-xs font-extrabold text-primary sm:hidden"
>
{showAllOnMobile ? "Show less" : "View all"}
</button>
)}
</section>
);
}
24 changes: 17 additions & 7 deletions src/features/dashboard/components/contribution-chart.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { SVGAttributes } from "react";
import { SVGAttributes, useEffect, useRef } from "react";
import CalendarHeatmap, { ReactCalendarHeatmapValue } from "react-calendar-heatmap";
import "react-calendar-heatmap/dist/styles.css";
import { Tooltip } from "react-tooltip";
Expand All @@ -9,6 +9,8 @@ import { DailyContribution } from "@/types/mock-app";
type CalendarContribution = ReactCalendarHeatmapValue<Date> & Omit<DailyContribution, "date">;

export function ContributionChart({ data }: { data: DailyContribution[] }) {
const scrollRef = useRef<HTMLDivElement>(null);

const values: CalendarContribution[] = data.map((contribution) => ({
...contribution,
date: parseLocalDate(contribution.date),
Expand All @@ -18,6 +20,14 @@ export function ContributionChart({ data }: { data: DailyContribution[] }) {
const startDate = values[0]?.date ?? new Date();
const endDate = values[values.length - 1]?.date ?? new Date();

useEffect(() => {
const node = scrollRef.current;

if (node) {
node.scrollLeft = node.scrollWidth;
}
}, [data]);

const tooltipDataAttrs = (value?: ReactCalendarHeatmapValue<Date>): SVGAttributes<SVGElement> => {
const contribution = value as CalendarContribution | undefined;

Expand All @@ -32,20 +42,20 @@ export function ContributionChart({ data }: { data: DailyContribution[] }) {
};

return (
<section className="min-w-0 rounded-lg border border-gray-200 bg-card p-4 shadow-sm dark:border-gray-800 sm:p-5">
<section className="min-w-0 rounded-lg border border-border bg-card/85 p-5 shadow-sm lg:p-6">
<div className="flex min-w-0 flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
<div className="min-w-0">
<h2 className="text-lg font-extrabold">Contribution graph</h2>
<h2 className="text-lg font-extrabold">Contribution activity</h2>
<p className="mt-1 text-sm text-muted-foreground">Daily activity across connected platforms.</p>
</div>
<div className="flex flex-wrap gap-4 text-xs font-bold text-muted-foreground">
<span className="flex items-center gap-2"><span className="size-2 rounded-full bg-slate-900 dark:bg-slate-200" />GitHub</span>
<span className="flex items-center gap-2"><span className="size-2 rounded-full bg-primary" />GitHub</span>
<span className="flex items-center gap-2"><span className="size-2 rounded-full bg-orange-500" />GitLab</span>
</div>
</div>

<div className="gf-contribution-calendar mt-6 max-w-full overflow-x-auto">
<div className="min-w-[34rem] sm:min-w-[42rem]">
<div ref={scrollRef} className="gf-contribution-calendar mt-6 max-w-full overflow-x-auto pb-1">
<div className="min-w-[720px] xl:min-w-[58rem] 2xl:min-w-0">
<CalendarHeatmap
startDate={startDate}
endDate={endDate}
Expand All @@ -60,7 +70,7 @@ export function ContributionChart({ data }: { data: DailyContribution[] }) {
</div>

<div className="mt-4 flex flex-col gap-3 text-xs font-medium text-muted-foreground sm:flex-row sm:items-center sm:justify-between">
<p>Each square represents one day. Tooltip values are already split by platform.</p>
<p>Each square represents one day.</p>
<div className="flex items-center gap-2">
<span>Less</span>
{[0, 1, 2, 3, 4].map((level) => (
Expand Down
65 changes: 59 additions & 6 deletions src/features/dashboard/components/metric-card.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,65 @@
import { IconType } from "react-icons";
import { DashboardMetric } from "@/types/mock-app";

export function MetricCard({ metric }: { metric: DashboardMetric }) {
type EnhancedMetric = DashboardMetric & {
icon?: IconType;
visual?: "sparkline" | "bars" | "progress";
};

export function MetricCard({ metric, className = "" }: { metric: EnhancedMetric; className?: string }) {
const Icon = metric.icon;

return (
<article className={`${metric.mobile ? "sm:hidden" : ""} min-w-0 rounded-lg border border-gray-200 bg-card p-4 shadow-sm dark:border-gray-800 sm:p-5`}>
<p className="text-sm font-bold text-muted-foreground">{metric.label}</p>
<div className="mt-3 break-words text-2xl font-extrabold tracking-normal sm:text-3xl">{metric.value}</div>
<p className="mt-2 text-sm text-muted-foreground">{metric.helper}</p>
<p className="mt-4 text-sm font-bold text-primary">{metric.trend}</p>
<article className={`${metric.mobile ? "sm:hidden" : ""} ${className} relative min-w-0 overflow-hidden rounded-lg border border-primary/18 bg-card/85 p-5 shadow-sm`}>
<div className="flex min-w-0 items-start justify-between gap-4">
<div className="flex min-w-0 items-start gap-4">
{Icon && (
<span className="grid size-11 shrink-0 place-items-center rounded-lg border border-primary/25 bg-primary/14 text-primary shadow-[0_0_28px_rgba(139,92,246,0.12)]">
<Icon className="size-5" aria-hidden />
</span>
)}
<div className="min-w-0">
<p className="truncate text-sm font-bold text-muted-foreground">{metric.label}</p>
<div className="mt-3 break-words text-2xl font-extrabold tracking-normal sm:text-3xl">{metric.value}</div>
<p className="mt-2 text-xs font-semibold text-muted-foreground">{metric.helper}</p>
</div>
</div>
<span className="hidden size-8 shrink-0 place-items-center rounded-full border border-primary/15 bg-background/70 text-primary sm:grid">↗</span>
</div>

<div className="mt-4 flex items-end justify-between gap-4">
<p className="min-w-0 truncate text-sm font-bold text-primary">{metric.trend}</p>
<MetricVisual type={metric.visual} />
</div>
</article>
);
}

function MetricVisual({ type }: { type?: EnhancedMetric["visual"] }) {
if (type === "bars") {
return (
<div className="hidden h-10 shrink-0 items-end gap-1.5 sm:flex" aria-hidden>
{[18, 24, 30, 25, 34, 39, 46].map((height, index) => (
<span key={index} className="w-2 rounded-t-sm bg-primary/80" style={{ height }} />
))}
</div>
);
}

if (type === "progress") {
return (
<div className="hidden shrink-0 gap-1.5 sm:flex" aria-hidden>
{[0, 1, 2, 3, 4, 5, 6].map((index) => (
<span key={index} className={"h-3 w-2 rounded-full " + (index < 4 ? "bg-primary" : "bg-muted")} />
))}
</div>
);
}

return (
<svg viewBox="0 0 92 38" className="hidden h-10 w-24 shrink-0 sm:block" aria-hidden>
<path d="M1 31 C12 12 20 28 31 18 S47 31 59 17 78 8 91 7" fill="none" stroke="var(--primary)" strokeWidth="3" strokeLinecap="round" />
<path d="M1 37 C12 20 20 34 31 24 S47 37 59 23 78 14 91 13 L91 38 L1 38 Z" fill="var(--primary)" opacity="0.16" />
</svg>
);
}
Loading
Loading