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: 1 addition & 1 deletion src/components/AppLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export function AppLayout({ children }: { children: ReactNode }) {
<div className="min-h-screen flex w-full bg-transparent relative z-10">
<AppSidebar />
<div className="flex-1 flex flex-col min-w-0">
<header className="sticky top-0 z-40 h-16 flex items-center border-b border-border bg-background/60 backdrop-blur-xl px-6">
<header className="sticky top-0 z-40 h-header flex items-center border-b border-border bg-background/60 backdrop-blur-xl px-6">
<div className="flex items-center gap-3">
<SidebarTrigger className="text-muted-foreground hover:text-foreground" />
</div>
Expand Down
55 changes: 39 additions & 16 deletions src/components/AppSidebar.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { NavLink, useLocation } from "react-router-dom";
import { LayoutDashboard, BookOpen, Layers, Upload, BarChart3, ScrollText, GraduationCap, Bot, CalendarCheck } from "lucide-react";
import { LayoutDashboard, BookOpen, Layers, Upload, BarChart3, GraduationCap, Bot, CalendarCheck } from "lucide-react";
import { useEffect, useState } from "react";
import { apiFetch } from "@/lib/api";
import { topicIdentity } from "@/lib/topicIdentity";
import { cn } from "@/lib/utils";
import {
Sidebar, SidebarContent, SidebarGroup, SidebarGroupContent, SidebarGroupLabel,
Expand Down Expand Up @@ -45,10 +46,18 @@ export function AppSidebar() {

return (
<Sidebar collapsible="icon" className="border-r border-sidebar-border">
{/* Collapsed, the header drops its own padding so the mark can centre in the
full 4rem rail instead of being inset twice. Expanded is untouched. */}
<SidebarHeader className={cn("border-b border-sidebar-border", collapsed && "p-0")}>
<div className={cn("flex items-center gap-2 py-3", collapsed ? "justify-center" : "px-2")}>
{/* Fixed to the same shared height as the main topbar, so the two bottom
borders form one continuous line. It used to size itself from its
contents — 76px expanded, 68px collapsed — which is why the divider sat
lower than the topbar's and shifted when the rail collapsed. Collapsing
now changes the header's contents, never its height. */}
<SidebarHeader
className={cn(
"h-header shrink-0 justify-center border-b border-sidebar-border",
collapsed ? "p-0" : "px-2",
)}
>
<div className={cn("flex items-center gap-2", collapsed && "justify-center")}>
<div
className={cn(
"flex shrink-0 items-center justify-center rounded-lg bg-gradient-brand shadow-glow",
Expand Down Expand Up @@ -94,17 +103,31 @@ export function AppSidebar() {
</SidebarGroupLabel>
<SidebarGroupContent>
<SidebarMenu>
{topics.map((t) => (
<SidebarMenuItem key={t.title}>
<SidebarMenuButton className="group justify-between">
<div className="flex items-center gap-2">
<ScrollText className="h-3.5 w-3.5 text-muted-foreground group-hover:text-accent" />
<span className="text-sm">{t.title}</span>
</div>
<span className="text-[10px] font-mono text-muted-foreground">{t.count}%</span>
</SidebarMenuButton>
</SidebarMenuItem>
))}
{topics.map((t) => {
const { Icon, accent, chip } = topicIdentity(t.title);
return (
<SidebarMenuItem key={t.title}>
{/* Fixed icon / flexible title / fixed count. `min-w-0` on the
middle column is what lets the title ellipsis instead of
pushing the percentage onto a second line. */}
<SidebarMenuButton
className="group gap-2.5"
title={t.title}
aria-label={`${t.title}, ${t.count}% mastery`}
>
<span
className={`flex h-5 w-5 shrink-0 items-center justify-center rounded ${chip} ${accent}`}
>
<Icon className="h-3 w-3" />
</span>
<span className="min-w-0 flex-1 truncate text-sm">{t.title}</span>
<span className="shrink-0 font-mono text-[10px] tabular-nums text-muted-foreground">
{t.count}%
</span>
</SidebarMenuButton>
</SidebarMenuItem>
);
})}
</SidebarMenu>
</SidebarGroupContent>
</SidebarGroup>
Expand Down
4 changes: 4 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@
--shadow-glow: 0 0 40px hsl(210 90% 65% / 0.25);
--shadow-card: 0 4px 24px -8px hsl(0 0% 0% / 0.6);

/* Shared application-chrome height, consumed by both the sidebar brand header
and the main topbar so their bottom borders form one continuous line. */
--app-header-height: 4rem;

--transition-smooth: cubic-bezier(0.4, 0, 0.2, 1);

/* sidebar */
Expand Down
113 changes: 113 additions & 0 deletions src/lib/topicIdentity.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
/**
* Topic identity
* ==============
*
* Every topic in the sidebar navigation rendered the same `ScrollText` glyph in the
* same muted grey, so the icon communicated nothing and the list read as one
* undifferentiated block. Long titles then wrapped across two lines and competed
* with the mastery percentage for space.
*
* Two rules shape this module:
*
* 1. **Deterministic.** The same topic always gets the same icon and accent, in
* this render and the next one. Nothing is random or time-seeded, so the
* sidebar does not reshuffle itself on reload.
* 2. **Restrained.** One small tinted icon, not a coloured card. The dashboard
* already carries the strong colour; navigation stays quiet and lets typography
* do the work. Accents follow the same 400-level tones the subject cards use, so
* the two read as one system.
*
* Keyword matching handles topics that name their subject. Anything unrecognised
* falls back to a stable hash across a small fixed set, which guarantees every
* topic still has a distinct, repeatable identity rather than collapsing to a
* default.
*/

import {
Atom,
BarChart3,
BookOpen,
Boxes,
Brain,
Briefcase,
Cpu,
Database,
FlaskConical,
GitBranch,
Landmark,
MessagesSquare,
Microscope,
Network,
Scale,
ShoppingBag,
Sigma,
Users,
type LucideIcon,
} from "lucide-react";

export interface TopicIdentity {
Icon: LucideIcon;
/** Tint for the icon. Paired tones, so light and dark both stay legible. */
accent: string;
/** Faint background for the fixed-size icon chip. */
chip: string;
}

interface Rule {
match: RegExp;
Icon: LucideIcon;
accent: string;
chip: string;
}

/** Ordered: the first match wins, so specific phrases precede broad ones. */
const RULES: Rule[] = [
// Plurals are written `s?` deliberately: a trailing `\b` after the keyword made
// "Operating Systems" and "Computer Networks" fall through to the hash fallback,
// which is exactly how the most common topics lost their identity.
{ match: /\b(os|operating systems?)\b/i, Icon: Cpu, accent: "text-sky-400", chip: "bg-sky-400/10" },
{ match: /\bdsa|algorithms?|data structures?\b/i, Icon: GitBranch, accent: "text-emerald-400", chip: "bg-emerald-400/10" },
{ match: /\b(dbms|databases?|sql)\b/i, Icon: Database, accent: "text-amber-400", chip: "bg-amber-400/10" },
{ match: /\b(networks?|cnn|neural networks?)\b/i, Icon: Network, accent: "text-cyan-400", chip: "bg-cyan-400/10" },
{ match: /\b(dl|deep learning|machine learning|ml|neural)\b/i, Icon: Brain, accent: "text-violet-400", chip: "bg-violet-400/10" },
{ match: /\b(nlp|natural language|transformers?)\b/i, Icon: MessagesSquare, accent: "text-teal-400", chip: "bg-teal-400/10" },
{ match: /\b(cv|computer vision|images?)\b/i, Icon: Microscope, accent: "text-pink-400", chip: "bg-pink-400/10" },
{ match: /\b(churn|retention|customers?)\b/i, Icon: Users, accent: "text-rose-400", chip: "bg-rose-400/10" },
{ match: /\b(retail|e-?commerce|stores?)\b/i, Icon: ShoppingBag, accent: "text-orange-400", chip: "bg-orange-400/10" },
{ match: /\b(intern|internships?|placements?)\b/i, Icon: Briefcase, accent: "text-blue-400", chip: "bg-blue-400/10" },
{ match: /\b(reports?|documentation|projects?)\b/i, Icon: BookOpen, accent: "text-indigo-400", chip: "bg-indigo-400/10" },
{ match: /\b(analytics|statistics?|metrics?)\b/i, Icon: BarChart3, accent: "text-lime-400", chip: "bg-lime-400/10" },
{ match: /\b(physics|quantum|mechanics?)\b/i, Icon: Atom, accent: "text-violet-300", chip: "bg-violet-300/10" },
{ match: /\b(law|legal|polic(?:y|ies))\b/i, Icon: Scale, accent: "text-stone-400", chip: "bg-stone-400/10" },
{ match: /\b(economics?|finance|accounts?|markets?)\b/i, Icon: Landmark, accent: "text-emerald-300", chip: "bg-emerald-300/10" },
{ match: /\b(chemistry|chemical|labs?)\b/i, Icon: FlaskConical, accent: "text-lime-300", chip: "bg-lime-300/10" },
{ match: /\b(math|algebra|calculus|probability)\b/i, Icon: Sigma, accent: "text-cyan-300", chip: "bg-cyan-300/10" },
{ match: /\b(cloud|devops|systems?|infrastructure)\b/i, Icon: Boxes, accent: "text-sky-300", chip: "bg-sky-300/10" },
];

/** Used when nothing matches, so an unknown topic still looks deliberate. */
const FALLBACKS: TopicIdentity[] = [
{ Icon: BookOpen, accent: "text-sky-400", chip: "bg-sky-400/10" },
{ Icon: Atom, accent: "text-violet-400", chip: "bg-violet-400/10" },
{ Icon: Boxes, accent: "text-emerald-400", chip: "bg-emerald-400/10" },
{ Icon: Sigma, accent: "text-amber-400", chip: "bg-amber-400/10" },
];

/** Small, stable string hash. Not cryptographic — only needs to not collide often. */
const hash = (value: string): number => {
let h = 0;
for (let i = 0; i < value.length; i += 1) {
h = (h << 5) - h + value.charCodeAt(i);
h |= 0;
}
return Math.abs(h);
};

/**
* Resolves a topic's icon and accent. Pure and stable for a given title.
*/
export const topicIdentity = (title: string): TopicIdentity => {
const rule = RULES.find((r) => r.match.test(title));
if (rule) return { Icon: rule.Icon, accent: rule.accent, chip: rule.chip };
return FALLBACKS[hash(title) % FALLBACKS.length];
};
23 changes: 19 additions & 4 deletions src/test/sidebarProportions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,20 @@ describe("collapsed sidebar rail", () => {
expect(sidebar).not.toMatch(/const SIDEBAR_WIDTH_ICON = "3rem";/);
});

it("the brand header and the main topbar share one height", () => {
// The header used to size itself from its contents — 76px expanded, 68px
// collapsed, against the topbar's fixed 64px — so their bottom borders never
// lined up and the sidebar's moved when the rail collapsed. Both now read the
// same token, which is the only thing that keeps them aligned.
const css = read("src/index.css");
const config = read("tailwind.config.ts");

expect(css).toContain("--app-header-height: 4rem");
expect(config).toContain('header: "var(--app-header-height)"');
expect(read("src/components/AppSidebar.tsx")).toContain("h-header");
expect(read("src/components/AppLayout.tsx")).toContain("h-header");
});

it("leaves the expanded and mobile widths alone", () => {
const sidebar = read("src/components/ui/sidebar.tsx");

Expand All @@ -52,13 +66,14 @@ describe("collapsed brand mark", () => {
const appSidebar = () => read("src/components/AppSidebar.tsx");

it("centres the brand block when collapsed", () => {
expect(appSidebar()).toContain('collapsed ? "justify-center" : "px-2"');
// Applied only in the collapsed state, as a conditional class.
expect(appSidebar()).toContain('collapsed && "justify-center"');
});

it("drops the header padding only when collapsed", () => {
expect(appSidebar()).toContain(
'cn("border-b border-sidebar-border", collapsed && "p-0")',
);
// Expanded keeps its own horizontal inset; collapsed goes edge to edge so the
// mark can centre in the full rail.
expect(appSidebar()).toContain('collapsed ? "p-0" : "px-2"');
});

it("uses a tile that fits the wider rail with equal gutters", () => {
Expand Down
148 changes: 148 additions & 0 deletions src/test/topicIdentity.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
/**
* Topic navigation identity
* =========================
*
* Every topic rendered the same `ScrollText` glyph in the same muted grey, so the
* icon carried no information and the list read as one flat block. Long titles
* then wrapped and pushed the mastery percentage onto a second line.
*
* The properties that matter are pinned here:
*
* - **deterministic** — the same topic always resolves to the same icon and
* accent, so the sidebar does not reshuffle on reload;
* - **distinct** — a topic that matches no rule still gets a deliberate identity
* rather than collapsing to a default;
* - **restrained** — accents are drawn from the same 400-level tones the subject
* cards already use, so navigation and dashboard read as one system.
*/

import { describe, expect, it } from "vitest";
import {
Atom,
BookOpen,
Boxes,
Brain,
Briefcase,
Cpu,
Database,
GitBranch,
Network,
Sigma,
ShoppingBag,
Users,
} from "lucide-react";
import { topicIdentity } from "@/lib/topicIdentity";

describe("identity is deterministic", () => {
const topics = [
"Operating Systems",
"AI/ML Practice",
"Internship Report",
"Customer Churn",
"Smart Retail Project",
"Computer Networks",
];

it.each(topics)("%s resolves the same way every time", (title) => {
const first = topicIdentity(title);
for (let i = 0; i < 5; i += 1) {
expect(topicIdentity(title)).toEqual(first);
}
});

it("gives different topics different accents", () => {
// The screenshot's list, which previously looked identical throughout.
const identities = topics.map((t) => topicIdentity(t));
const accents = identities.map((i) => i.accent);

expect(new Set(accents).size).toBeGreaterThan(1);
});
});

describe("topics are matched by subject, not by position", () => {
const cases: Array<[string, unknown]> = [
["Operating Systems", Cpu],
["Data Structures & Algorithms", GitBranch],
["DBMS", Database],
["Computer Networks", Network],
["Deep Learning", Brain],
["AI/ML Internship", Brain],
["Customer Churn Prediction", Users],
["Smart Retail", ShoppingBag],
["Internship Report", Briefcase],
["Quantum Physics", Atom],
];

it.each(cases)("%s gets a subject-appropriate icon", (title, expected) => {
expect(topicIdentity(title).Icon).toBe(expected);
});

it("does not let a broad word win over a specific one", () => {
// "report" and "project" both match the documentation rule, but "internship"
// is checked first, so this must resolve to the briefcase rather than a book.
expect(topicIdentity("Internship Report").Icon).toBe(Briefcase);
});
});

describe("unknown topics still get a deliberate identity", () => {
const unknowns = [
"Underwater Basket Weaving",
"Quantum Chromodynamics",
"Postcolonial Cartography",
"Medieval Cipher Studies",
"Volcanic Petrology",
];

it.each(unknowns)("%s falls back rather than erroring", (title) => {
const identity = topicIdentity(title);
expect(identity.Icon).toBeDefined();
expect(identity.accent).toMatch(/^text-/);
expect(identity.chip).toMatch(/^bg-/);
});

it("does not collapse every unknown onto one icon", () => {
const icons = unknowns.map((t) => topicIdentity(t).Icon);
expect(new Set(icons).size).toBeGreaterThan(1);
});

it("handles an empty title", () => {
expect(() => topicIdentity("")).not.toThrow();
expect(topicIdentity("").Icon).toBeDefined();
});
});

describe("accents stay inside the product palette", () => {
it("uses 300/400-level tones, matching the subject cards", () => {
const all = [
...["Operating Systems", "DBMS", "Deep Learning", "Smart Retail", "Quantum Physics"],
"Underwater Basket Weaving",
];

for (const title of all) {
const { accent, chip } = topicIdentity(title);
expect(accent).toMatch(/^text-[a-z]+-(300|400)$/);
expect(chip).toMatch(/^bg-[a-z]+-(300|400)\/10$/);
}
});

it("pairs an accent with a matching chip", () => {
for (const title of ["Operating Systems", "Smart Retail", "Internship Report"]) {
const { accent, chip } = topicIdentity(title);
const accentColour = accent.replace("text-", "").replace(/-(300|400)$/, "");
const chipColour = chip.replace("bg-", "").replace(/-(300|400)\/10$/, "");
expect(accentColour).toBe(chipColour);
}
});
});

describe("the known-icon palette is real", () => {
it("resolves icons that exist in the installed library", () => {
// Guards against a typo'd import silently rendering nothing.
expect(topicIdentity("Operating Systems").Icon).toBe(Cpu);
expect(topicIdentity("Internship Report").Icon).toBe(Briefcase);
expect(topicIdentity("Some Unmatched Topic").Icon).toBeDefined();
expect([BookOpen, Boxes, Atom, Sigma]).toContain(
topicIdentity("Some Unmatched Topic").Icon,
);
});
});
Loading
Loading