Skip to content
Open
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
39 changes: 37 additions & 2 deletions src/components/DashboardHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"use client"
"use client";

import { useEffect, useState } from "react";
import { useSession } from "next-auth/react";
Expand All @@ -10,7 +10,10 @@ import KeyboardShortcuts from "@/components/KeyboardShortcuts";

export default function DashboardHeader() {
const { data: session } = useSession();

const [isPublic, setIsPublic] = useState<boolean | null>(null);
const [copied, setCopied] = useState(false);
const [copyError, setCopyError] = useState(false);

useEffect(() => {
if (!session) {
Expand All @@ -21,6 +24,7 @@ export default function DashboardHeader() {
async function loadSettings() {
try {
const res = await fetch("/api/user/settings");

if (res.ok) {
const data = await res.json();
setIsPublic(data.is_public === true);
Expand All @@ -36,13 +40,32 @@ export default function DashboardHeader() {
loadSettings();
}, [session]);

const handleCopy = async () => {
try {
await navigator.clipboard.writeText(window.location.href);

setCopied(true);

setTimeout(() => {
setCopied(false);
}, 2000);
} catch {
setCopyError(true);

setTimeout(() => {
setCopyError(false);
}, 2000);
}
};

return (
<header className="mb-8 border-b border-[var(--border)] p-4 pb-6">
<div className="flex flex-wrap items-center justify-between gap-3">
<div>
<h1 className="text-2xl md:text-3xl font-bold text-[var(--foreground)]">
Dashboard
</h1>

<p className="mt-1 text-[var(--muted-foreground)]">
Your coding activity at a glance
</p>
Expand All @@ -60,8 +83,20 @@ export default function DashboardHeader() {
Share Profile
</a>
)}

<KeyboardShortcuts />

<UserAvatar />

<button
type="button"
onClick={handleCopy}
aria-label="Copy dashboard link"
className="px-3 py-2 rounded-md border border-[var(--border)]"
>
{copied ? "✓ Copied!" : copyError ? "Failed" : "📋"}
</button>

<ThemeToggle />
<SignOutButton />
</div>
Expand All @@ -70,4 +105,4 @@ export default function DashboardHeader() {
<AccountToggle />
</header>
);
}
}
Loading