From 3512f0cbaa0a92b8fe0585dfe096e0d5c724baf8 Mon Sep 17 00:00:00 2001 From: tgiachi Date: Sun, 15 Nov 2026 15:05:17 +0100 Subject: [PATCH] feat(web): an icon next to each link in the side menu - each link has a lucide icon in place of the dot; the icon of the open page is the colour of this server, Friends keeps the friend colour - the group headings line up with the words again - tests: every link has a decorative icon, no two pages share one --- web/src/components/layout/Sidebar.test.tsx | 40 +++++++++++++----- web/src/components/layout/Sidebar.tsx | 49 ++++++++++++---------- 2 files changed, 56 insertions(+), 33 deletions(-) diff --git a/web/src/components/layout/Sidebar.test.tsx b/web/src/components/layout/Sidebar.test.tsx index 43d52b1..768cbae 100644 --- a/web/src/components/layout/Sidebar.test.tsx +++ b/web/src/components/layout/Sidebar.test.tsx @@ -25,15 +25,13 @@ function renderSidebar(friends: { id: number; name: string }[] = [], path = '/al return screen.getByRole('navigation', { name: 'Main' }) } -test('the menu is words, one for each page, and the page that is open is the current one', () => { +test('the menu has a link for each page, and the page that is open is the current one', () => { const nav = renderSidebar() for (const name of ['Home', 'Search', 'Discover', 'Artists', 'Albums', 'Songs', 'Mixes', 'Playlists', 'Smart playlists', 'History', 'Import', 'Admin', 'Settings']) { expect(within(nav).getByRole('link', { name })).toBeInTheDocument() } expect(within(nav).getByRole('link', { name: 'Albums' })).toHaveAttribute('aria-current', 'page') expect(within(nav).getByRole('link', { name: 'Artists' })).not.toHaveAttribute('aria-current') - // No icons, the words are enough: the only drawing in the menu is the logo. - expect([...nav.querySelectorAll('svg')].filter((svg) => svg.getAttribute('role') !== 'img')).toHaveLength(0) }) test('there is nothing to fold: the menu always shows its words', () => { @@ -42,11 +40,31 @@ test('there is nothing to fold: the menu always shows its words', () => { expect(within(nav).queryByRole('button')).not.toBeInTheDocument() }) -test('a dot marks the page that is open, in the colour of this server', () => { +test('every link has an icon, and the words stay: the icon is decoration, not the name', () => { const nav = renderSidebar() - const dot = (name: string) => within(nav).getByRole('link', { name }).querySelector('[data-dot]') - expect(dot('Albums')).toHaveClass('bg-primary') - expect(dot('Artists')).toHaveClass('bg-transparent') + const links = within(nav).getAllByRole('link') + expect(links.length).toBeGreaterThan(10) + for (const link of links) { + const icon = link.querySelector('[data-icon]') + expect(icon, link.textContent ?? '').toBeInTheDocument() + expect(icon).toHaveAttribute('aria-hidden', 'true') + expect(link.textContent?.trim()).not.toBe('') + } +}) + +test('no two pages share an icon', () => { + const nav = renderSidebar() + const kinds = within(nav) + .getAllByRole('link') + .map((a) => a.querySelector('[data-icon]')?.getAttribute('class')?.match(/lucide-[\w-]+/)?.[0]) + expect(new Set(kinds).size).toBe(kinds.length) +}) + +test('the icon of the page that is open is in the colour of this server', () => { + const nav = renderSidebar() + const icon = (name: string) => within(nav).getByRole('link', { name }).querySelector('[data-icon]') + expect(icon('Albums')).toHaveClass('text-primary') + expect(icon('Artists')).not.toHaveClass('text-primary') }) test('the Sonda logo is the name of the app', () => { @@ -66,18 +84,18 @@ test('Friends is in the menu only when there is a friend to browse', async () => expect(within(none).queryByRole('link', { name: 'Friends' })).not.toBeInTheDocument() }) -test('with a friend the menu has a Friends link, with the dot of what comes from elsewhere', async () => { +test('with a friend the menu has a Friends link, with the icon of what comes from elsewhere', async () => { const nav = renderSidebar([{ id: 3, name: 'Anna' }]) const link = await within(nav).findByRole('link', { name: 'Friends' }) expect(link).toHaveAttribute('href', '/friends') - expect(link.querySelector('[data-dot]')).toHaveClass('bg-friend') + expect(link.querySelector('[data-icon]')).toHaveClass('text-friend') }) -test('the dot of Friends is the friend colour also when it is the page that is open', async () => { +test('the icon of Friends is the friend colour also when it is the page that is open', async () => { const nav = renderSidebar([{ id: 3, name: 'Anna' }], '/friends/3') const link = await within(nav).findByRole('link', { name: 'Friends' }) expect(link).toHaveAttribute('aria-current', 'page') - expect(link.querySelector('[data-dot]')).toHaveClass('bg-friend') + expect(link.querySelector('[data-icon]')).toHaveClass('text-friend') }) test('on a phone the links are left to the bar of tabs: only the logo stays', () => { diff --git a/web/src/components/layout/Sidebar.tsx b/web/src/components/layout/Sidebar.tsx index 99f44d5..45d014a 100644 --- a/web/src/components/layout/Sidebar.tsx +++ b/web/src/components/layout/Sidebar.tsx @@ -1,3 +1,5 @@ +import { Blend, Compass, Disc3, History, House, Inbox, ListMusic, MicVocal, Music, Search, Settings, ShieldCheck, Upload, Users, WandSparkles } from 'lucide-react' +import type { LucideIcon } from 'lucide-react' import { NavLink } from 'react-router-dom' import { useTranslation } from 'react-i18next' import { useFriends } from '@/api/friends' @@ -8,6 +10,7 @@ import { cn } from '@/lib/utils' interface Item { to: string key: string + icon: LucideIcon end?: boolean adminOnly?: boolean friends?: boolean @@ -26,40 +29,41 @@ interface Group { const GROUPS: Group[] = [ { items: [ - { to: '/', key: 'nav.home', end: true }, - { to: '/search', key: 'nav.search' }, - { to: '/discover', key: 'nav.discover' }, - { to: '/requests', key: 'nav.requests', adminOnly: true }, + { to: '/', key: 'nav.home', icon: House, end: true }, + { to: '/search', key: 'nav.search', icon: Search }, + { to: '/discover', key: 'nav.discover', icon: Compass }, + { to: '/requests', key: 'nav.requests', icon: Inbox, adminOnly: true }, ], }, { heading: 'nav.library', items: [ - { to: '/artists', key: 'nav.artists' }, - { to: '/albums', key: 'nav.albums' }, - { to: '/songs', key: 'nav.songs' }, - { to: '/playlists', key: 'nav.playlists' }, - { to: '/smart-playlists', key: 'nav.smartPlaylists' }, - { to: '/mixes', key: 'nav.mixes' }, + { to: '/artists', key: 'nav.artists', icon: MicVocal }, + { to: '/albums', key: 'nav.albums', icon: Disc3 }, + { to: '/songs', key: 'nav.songs', icon: Music }, + { to: '/playlists', key: 'nav.playlists', icon: ListMusic }, + { to: '/smart-playlists', key: 'nav.smartPlaylists', icon: WandSparkles }, + { to: '/mixes', key: 'nav.mixes', icon: Blend }, ], }, { heading: 'nav.listening', items: [ - { to: '/history', key: 'nav.history' }, - { to: '/import', key: 'nav.import' }, + { to: '/history', key: 'nav.history', icon: History }, + { to: '/import', key: 'nav.import', icon: Upload }, ], }, - { items: [{ to: '/friends', key: 'nav.friends', friends: true }] }, + { items: [{ to: '/friends', key: 'nav.friends', icon: Users, friends: true }] }, ] const FOOT: Item[] = [ - { to: '/settings', key: 'nav.settings' }, - { to: '/admin', key: 'nav.admin', adminOnly: true }, + { to: '/settings', key: 'nav.settings', icon: Settings }, + { to: '/admin', key: 'nav.admin', icon: ShieldCheck, adminOnly: true }, ] function Row({ item }: { item: Item }) { const { t } = useTranslation() + const Icon = item.icon return (
  • {({ isActive }) => ( <> -