From fee99dca4a15fd5816a305c93c4f0e75bb4a17bf Mon Sep 17 00:00:00 2001 From: prathamkashyap Date: Sun, 4 Oct 2026 12:28:08 +0530 Subject: [PATCH] Polish application shell and topic navigation --- src/components/AppLayout.tsx | 2 +- src/components/AppSidebar.tsx | 55 ++++++++--- src/index.css | 4 + src/lib/topicIdentity.ts | 113 +++++++++++++++++++++ src/test/sidebarProportions.test.ts | 23 ++++- src/test/topicIdentity.test.ts | 148 ++++++++++++++++++++++++++++ tailwind.config.ts | 12 +++ 7 files changed, 336 insertions(+), 21 deletions(-) create mode 100644 src/lib/topicIdentity.ts create mode 100644 src/test/topicIdentity.test.ts diff --git a/src/components/AppLayout.tsx b/src/components/AppLayout.tsx index 9665b71..e4ab0a9 100644 --- a/src/components/AppLayout.tsx +++ b/src/components/AppLayout.tsx @@ -26,7 +26,7 @@ export function AppLayout({ children }: { children: ReactNode }) {
-
+
diff --git a/src/components/AppSidebar.tsx b/src/components/AppSidebar.tsx index f252004..f12bf48 100644 --- a/src/components/AppSidebar.tsx +++ b/src/components/AppSidebar.tsx @@ -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, @@ -45,10 +46,18 @@ export function AppSidebar() { return ( - {/* 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. */} - -
+ {/* 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. */} + +
- {topics.map((t) => ( - - -
- - {t.title} -
- {t.count}% -
-
- ))} + {topics.map((t) => { + const { Icon, accent, chip } = topicIdentity(t.title); + return ( + + {/* 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. */} + + + + + {t.title} + + {t.count}% + + + + ); + })}
diff --git a/src/index.css b/src/index.css index 5593395..9202d9b 100644 --- a/src/index.css +++ b/src/index.css @@ -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 */ diff --git a/src/lib/topicIdentity.ts b/src/lib/topicIdentity.ts new file mode 100644 index 0000000..b1ba360 --- /dev/null +++ b/src/lib/topicIdentity.ts @@ -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]; +}; diff --git a/src/test/sidebarProportions.test.ts b/src/test/sidebarProportions.test.ts index fc254d6..e481e5a 100644 --- a/src/test/sidebarProportions.test.ts +++ b/src/test/sidebarProportions.test.ts @@ -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"); @@ -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", () => { diff --git a/src/test/topicIdentity.test.ts b/src/test/topicIdentity.test.ts new file mode 100644 index 0000000..b440aab --- /dev/null +++ b/src/test/topicIdentity.test.ts @@ -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, + ); + }); +}); diff --git a/tailwind.config.ts b/tailwind.config.ts index f0f632b..50c1f9f 100644 --- a/tailwind.config.ts +++ b/tailwind.config.ts @@ -14,6 +14,18 @@ export default { }, }, extend: { + // One shared header dimension. + // + // The sidebar brand header and the main topbar were each sized independently + // (h-16 = 64px against 76px expanded / 68px collapsed), so their bottom + // borders never lined up — and the sidebar's moved when the rail collapsed. + // Both now reference this single token, so they cannot drift apart again. + height: { + header: "var(--app-header-height)", + }, + spacing: { + header: "var(--app-header-height)", + }, colors: { border: "hsl(var(--border))", input: "hsl(var(--input))",