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
4 changes: 2 additions & 2 deletions components/ui/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ export default function Navbar({ counts }: { counts?: Counts }) {
}}
>
<IconGitHub size={14} />
Sign in
Track my stack
</button>
)}
{!userLoading && user && username && (
Expand Down Expand Up @@ -440,7 +440,7 @@ export default function Navbar({ counts }: { counts?: Counts }) {
}}
>
<IconGitHub size={14} />
Sign in with GitHub
Track your AI stack
</button>
)}
{!userLoading && user && username && (
Expand Down
207 changes: 159 additions & 48 deletions components/ui/ToolUsageButton.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use client";

import { useState, useEffect } from "react";
import { useState, useEffect, useRef } from "react";
import { useUser } from "@/hooks/useUser";
import { createSupabaseBrowserClient } from "@/lib/db";

Expand All @@ -15,6 +15,19 @@ export function ToolUsageButton({ toolId, color, compact = false }: Props) {
const [count, setCount] = useState(0);
const [used, setUsed] = useState(false);
const [loading, setLoading] = useState(false);
const [tooltipOpen, setTooltipOpen] = useState(false);
const wrapperRef = useRef<HTMLDivElement>(null);

useEffect(() => {
if (!tooltipOpen) return;
function handleOutside(e: MouseEvent) {
if (wrapperRef.current && !wrapperRef.current.contains(e.target as Node)) {
setTooltipOpen(false);
}
}
document.addEventListener("mousedown", handleOutside);
return () => document.removeEventListener("mousedown", handleOutside);
}, [tooltipOpen]);

useEffect(() => {
const supabase = createSupabaseBrowserClient();
Expand All @@ -36,7 +49,7 @@ export function ToolUsageButton({ toolId, color, compact = false }: Props) {

async function toggle() {
if (!user) {
signIn();
setTooltipOpen(true);
return;
}
const supabase = createSupabaseBrowserClient();
Expand All @@ -62,70 +75,168 @@ export function ToolUsageButton({ toolId, color, compact = false }: Props) {

if (compact) {
return (
<div ref={wrapperRef} style={{ position: "relative", display: "inline-flex" }}>
<button
onClick={toggle}
disabled={loading}
title={used ? "✓ You use this tool" : "Mark as used"}
style={{
display: "flex",
alignItems: "center",
gap: 3,
padding: "0 6px",
height: 22,
borderRadius: 5,
fontSize: 10,
fontWeight: 600,
cursor: loading ? "default" : "pointer",
opacity: loading ? 0.6 : 1,
background: used ? color + "18" : "var(--surface-2)",
border: `1px solid ${used ? color + "44" : "var(--border)"}`,
color: used ? color : "var(--text-muted)",
transition: "all 150ms",
flexShrink: 0,
}}
>
{used ? "✓" : "use"}
{count > 0 && <span style={{ fontSize: 8, opacity: 0.7 }}>{count}</span>}
</button>

{tooltipOpen && (
<div
style={{
position: "absolute",
top: "calc(100% + 6px)",
left: 0,
minWidth: 200,
borderRadius: 8,
padding: "10px 12px",
background: "var(--surface-2)",
border: "1px solid var(--border)",
boxShadow: "0 4px 16px rgba(0,0,0,0.3)",
zIndex: 50,
}}
>
<p
style={{
fontSize: 11,
color: "var(--text-secondary)",
margin: "0 0 8px",
lineHeight: 1.4,
}}
>
Sign in with GitHub to track your tools and build your badge wall.
</p>
<button
onClick={() => {
setTooltipOpen(false);
signIn();
}}
style={{
width: "100%",
padding: "6px 10px",
borderRadius: 6,
fontSize: 11,
fontWeight: 600,
background: "var(--accent)",
border: "none",
color: "#fff",
cursor: "pointer",
}}
>
Continue with GitHub →
</button>
</div>
)}
</div>
);
}

return (
<div ref={wrapperRef} style={{ position: "relative", width: "100%" }}>
<button
onClick={toggle}
disabled={loading}
title={used ? "✓ You use this tool" : "Mark as used"}
style={{
display: "flex",
alignItems: "center",
gap: 3,
padding: "0 6px",
height: 22,
borderRadius: 5,
fontSize: 10,
justifyContent: "center",
gap: 5,
padding: "0 12px",
height: 32,
borderRadius: 7,
fontSize: 12,
fontWeight: 600,
cursor: loading ? "default" : "pointer",
opacity: loading ? 0.6 : 1,
background: used ? color + "18" : "var(--surface-2)",
border: `1px solid ${used ? color + "44" : "var(--border)"}`,
color: used ? color : "var(--text-muted)",
background: used ? color + "18" : "var(--btn)",
border: `1px solid ${used ? color + "44" : "var(--btn-border)"}`,
color: used ? color : "var(--text-secondary)",
transition: "all 150ms",
flexShrink: 0,
width: "100%",
}}
>
{used ? "✓" : "use"}
{count > 0 && <span style={{ fontSize: 8, opacity: 0.7 }}>{count}</span>}
{used ? "✓ Using this" : "I use this"}
{count > 0 && (
<span
style={{
fontSize: 10,
fontWeight: 500,
color: used ? color + "88" : "var(--text-muted)",
}}
>
· {count}
</span>
)}
</button>
);
}

return (
<button
onClick={toggle}
disabled={loading}
style={{
display: "flex",
alignItems: "center",
justifyContent: "center",
gap: 5,
padding: "0 12px",
height: 32,
borderRadius: 7,
fontSize: 12,
fontWeight: 600,
cursor: loading ? "default" : "pointer",
opacity: loading ? 0.6 : 1,
background: used ? color + "18" : "var(--btn)",
border: `1px solid ${used ? color + "44" : "var(--btn-border)"}`,
color: used ? color : "var(--text-secondary)",
transition: "all 150ms",
flexShrink: 0,
width: "100%",
}}
>
{used ? "✓ Using this" : "I use this"}
{count > 0 && (
<span
{tooltipOpen && (
<div
style={{
fontSize: 10,
fontWeight: 500,
color: used ? color + "88" : "var(--text-muted)",
position: "absolute",
bottom: "calc(100% + 8px)",
left: 0,
right: 0,
borderRadius: 8,
padding: "10px 12px",
background: "var(--surface-2)",
border: "1px solid var(--border)",
boxShadow: "0 4px 16px rgba(0,0,0,0.3)",
zIndex: 50,
}}
>
· {count}
</span>
<p
style={{
fontSize: 11,
color: "var(--text-secondary)",
margin: "0 0 8px",
lineHeight: 1.4,
}}
>
Sign in with GitHub to track your tools and build your badge wall.
</p>
<button
onClick={() => {
setTooltipOpen(false);
signIn();
}}
style={{
width: "100%",
padding: "6px 10px",
borderRadius: 6,
fontSize: 11,
fontWeight: 600,
background: "var(--accent)",
border: "none",
color: "#fff",
cursor: "pointer",
}}
>
Continue with GitHub →
</button>
</div>
)}
</button>
</div>
);
}
Loading