Repository Public
1/**2 * =============================================================================3 * SP BOUCHER | SOFTWARE & RESEARCH4 * ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project : Music SP8 * File : src/app/(app)/recherche/page.tsx9 * Module : app10 * Repository : https://git.spboucher.ai/sp-music11 * Project Website : https://music.spboucher.ai12 * Created : 2026-11-1713 * Last Modified : 2026-11-1714 *15 * Author : Simon-Pierre Boucher16 * Position : Professor of Finance17 * Institution : Université du Québec en Outaouais (UQO)18 * Organization : SP Boucher19 * Website : https://spboucher.ai20 * Git : https://git.spboucher.ai21 *22 * Preferred Contact: support@spboucher.ai23 * Development : dev@spboucher.ai24 * Support : support@spboucher.ai25 * Security/Admin : admin@spboucher.ai26 *27 * Copyright (c) 202628 * Simon-Pierre Boucher29 * All rights reserved where applicable. This file is governed by the30 * applicable project license, copyright notices and relevant law.31 * Existing third-party rights and notices remain unaffected.32 *33 * License : None specified (no license file in this repository)34 *35 * Do not embed credentials, private keys, access tokens,36 * certificates or confidential personal information.37 *38 * =============================================================================39 * END OF SP BOUCHER SOURCE HEADER40 * =============================================================================41 */4243"use client";44import { useEffect, useState } from "react";45import type { Album, Artist, Track } from "@/lib/types";46import { useT } from "@/i18n";47import { AlbumCard, ArtistCard, Async, Empty, PageHeader, Section, TrackList, useApi } from "@/components/ui";48import { IClose, ISearch } from "@/components/icons";4950export default function SearchPage() {51 const t = useT();52 const [q, setQ] = useState("");53 const [debounced, setDebounced] = useState("");54 useEffect(() => { const id = setTimeout(() => setDebounced(q.trim()), 220); return () => clearTimeout(id); }, [q]);55 const res = useApi<{ artists: Artist[]; albums: Album[]; tracks: Track[] }>(debounced ? `/api/v1/library/search?q=${encodeURIComponent(debounced)}` : null);56 return (57 <>58 <PageHeader title={t("search.title")} />59 <form role="search" className="relative mb-6 max-w-xl" onSubmit={(e) => e.preventDefault()}>60 <label htmlFor="q" className="sr-only">{t("search.placeholder")}</label>61 <ISearch size={18} className="pointer-events-none absolute left-3.5 top-1/2 -translate-y-1/2 text-faint" />62 <input id="q" type="search" className="input !rounded-full !pl-10 !pr-10" placeholder={t("search.placeholder")} value={q} onChange={(e) => setQ(e.target.value)} autoComplete="off" autoCorrect="off" enterKeyHint="search" autoFocus />63 {q && <button type="button" className="icon-btn absolute right-0.5 top-1/2 !h-9 !w-9 -translate-y-1/2 text-muted" onClick={() => setQ("")} aria-label={t("search.clear")}><IClose size={16} /></button>}64 </form>65 {!debounced ? <Empty icon={<ISearch size={28} />} title={t("search.hintTitle")} body={t("search.hintBody")} /> : (66 <Async res={res}>{(d) => d.artists.length + d.albums.length + d.tracks.length === 0 ? <Empty icon={<ISearch size={28} />} title={t("search.noneTitle", { q: debounced })} body={t("search.noneBody")} /> : (67 <div aria-live="polite">68 {d.artists.length > 0 && <Section title={t("lib.artists")}><div className="scroll-x -mx-4 px-4 sm:mx-0 sm:px-0">{d.artists.map((a) => <ArtistCard key={a.id} artist={a} className="w-28 sm:w-36" />)}</div></Section>}69 {d.albums.length > 0 && <Section title={t("lib.albums")}><div className="scroll-x -mx-4 px-4 sm:mx-0 sm:px-0">{d.albums.map((a) => <AlbumCard key={a.id} album={a} className="w-36 sm:w-44" />)}</div></Section>}70 {d.tracks.length > 0 && <Section title={t("lib.tracks")}><TrackList tracks={d.tracks} /></Section>}71 </div>)}</Async>72 )}73 </>74 );75}76