feat(catalog): catalog polish CT1–CT3
- CT1: chip rows scroll without a visible scrollbar; a faded edge hints there's more (also applies to the category chips on home) - CT2: search filters on every keystroke (no 300ms debounce) and gets a search icon, a clear button and Escape-to-clear - CT3: "Taught in" filter next to the result count, listing only languages the visible courses are taught in; the empty state offers "Clear filters" - i18n: catalog.clearSearch, taughtIn, anyLanguage, clearFilters, emptyLanguage (om/ti drafts)
This commit is contained in:
parent
529f35cdf6
commit
fd382359c0
|
|
@ -519,27 +519,43 @@ function Catalog({ categorySlug }: { categorySlug?: string }) {
|
|||
const { categories, locale, nav, catalogLoaded } = useApp();
|
||||
const { visible, catName } = useCatalog();
|
||||
const [q, setQ] = useState('');
|
||||
const [dq, setDq] = useState('');
|
||||
useEffect(() => { const id = setTimeout(() => setDq(q.trim().toLowerCase()), 300); return () => clearTimeout(id); }, [q]);
|
||||
const [lang, setLang] = useState(''); // '' = any language the course is taught in (CT3)
|
||||
const searchRef = useRef<HTMLInputElement>(null);
|
||||
const dq = q.trim().toLowerCase(); // the list is in memory: filter on every keystroke, no debounce (CT2)
|
||||
const cat = categories.find((c) => c.slug === categorySlug);
|
||||
const list = visible.filter((c) => (!cat || c.categoryId === cat.id) && (!dq || [
|
||||
const langs = [...new Set(visible.map((c) => c.instructionLocale))];
|
||||
const list = visible.filter((c) => (!cat || c.categoryId === cat.id) && (!lang || c.instructionLocale === lang) && (!dq || [
|
||||
...Object.values(c.translations).map((x) => x?.title ?? ''), c.instructorName,
|
||||
...Object.values(categories.find((k) => k.id === c.categoryId)?.translations ?? {}).map((x) => x?.name ?? ''),
|
||||
].some((s) => s.toLowerCase().includes(dq))));
|
||||
const clear = () => { setQ(''); searchRef.current?.focus(); };
|
||||
return (
|
||||
<section className="stack">
|
||||
<h1 style={{ fontSize: 'var(--fs-2xl)' }}>{cat ? catName(cat.id) : t('catalog.title')}</h1>
|
||||
<label className="field"><span className="sr-only">{t('catalog.search')}</span>
|
||||
<input id="search" className="input" type="search" placeholder={t('catalog.search')} value={q} onChange={(e) => setQ(e.target.value)} />
|
||||
<label className="search">
|
||||
<span className="sr-only">{t('catalog.search')}</span>
|
||||
<Icon name="search" size={18} />
|
||||
<input ref={searchRef} id="search" className="input" type="search" placeholder={t('catalog.search')} value={q} onChange={(e) => setQ(e.target.value)} onKeyDown={(e) => { if (e.key === 'Escape' && q) clear(); }} />
|
||||
{q && <button type="button" className="search-clear" onClick={clear} aria-label={t('catalog.clearSearch')}><Icon name="x" size={16} /></button>}
|
||||
</label>
|
||||
<div className="chips" role="group">
|
||||
<button className="chip" aria-pressed={!cat} onClick={() => nav(`/${locale}/courses`)}>{t('catalog.all')}</button>
|
||||
{categories.filter((c) => c.isActive).map((c) => <button key={c.id} className="chip" aria-pressed={cat?.id === c.id} onClick={() => nav(`/${locale}/courses/${c.slug}`)}>{tr(c.translations, locale)?.name}</button>)}
|
||||
</div>
|
||||
{!catalogLoaded ? <Skeleton h={220} n={2} /> : list.length ? <>
|
||||
<p className="muted small" aria-live="polite">{t('catalog.count', { n: list.length })}</p>
|
||||
<div className="grid-cards">{list.map((c) => <CourseCard key={c.id} c={c} />)}</div>
|
||||
</> : <Empty action={dq ? <button className="btn btn-ghost" onClick={() => setQ('')}>{t('catalog.all')}</button> : undefined}>{dq ? t('catalog.empty', { q }) : t('catalog.emptyCategory')}</Empty>}
|
||||
{!catalogLoaded ? <Skeleton h={220} n={2} /> : <>
|
||||
<div className="catalog-bar">
|
||||
<p className="muted small" aria-live="polite">{t('catalog.count', { n: list.length })}</p>
|
||||
{langs.length > 1 && <label className="catalog-lang">
|
||||
<span>{t('catalog.taughtIn')}</span>
|
||||
<select id="catalog-lang" value={lang} onChange={(e) => setLang(e.target.value)}>
|
||||
<option value="">{t('catalog.anyLanguage')}</option>
|
||||
{langs.map((l) => <option key={l} value={l}>{LOCALE_NAMES[l]}</option>)}
|
||||
</select>
|
||||
</label>}
|
||||
</div>
|
||||
{list.length ? <div className="grid-cards">{list.map((c) => <CourseCard key={c.id} c={c} />)}</div>
|
||||
: <Empty action={dq || lang ? <button className="btn btn-ghost" onClick={() => { setQ(''); setLang(''); }}>{t('catalog.clearFilters')}</button> : undefined}>{dq ? t('catalog.empty', { q }) : lang ? t('catalog.emptyLanguage') : t('catalog.emptyCategory')}</Empty>}
|
||||
</>}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -189,7 +189,22 @@ textarea.input { min-height: 110px; resize: vertical; }
|
|||
.continue-body { justify-content: center; padding: 24px 28px; }
|
||||
.continue-body .btn { align-self: flex-start; width: auto; }
|
||||
}
|
||||
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
|
||||
/* CT1: chip rows scroll without a visible scrollbar; the faded edge says there's more */
|
||||
.chips { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; scrollbar-width: none; mask-image: linear-gradient(to right, #000 calc(100% - 28px), transparent); }
|
||||
.chips::-webkit-scrollbar { display: none; }
|
||||
@media (max-width: 599px) { .chips { margin-inline: -16px; padding-inline: 16px; scroll-padding-inline: 16px; mask-image: linear-gradient(to right, transparent, #000 16px, #000 calc(100% - 32px), transparent); } }
|
||||
/* CT2: search with an icon and a clear button (the browser's own cancel glyph is hidden so there's only one) */
|
||||
.search { position: relative; display: block; }
|
||||
.search > svg { position: absolute; left: 14px; top: 50%; translate: 0 -50%; color: var(--ink-3); pointer-events: none; }
|
||||
.search .input { min-height: 48px; padding-inline: 42px 46px; border-radius: 14px; }
|
||||
.search .input::-webkit-search-cancel-button { -webkit-appearance: none; appearance: none; }
|
||||
.search-clear { position: absolute; right: 4px; top: 50%; translate: 0 -50%; width: 40px; height: 40px; display: grid; place-items: center; border: 0; border-radius: 50%; background: none; color: var(--ink-3); cursor: pointer; }
|
||||
@media (hover: hover) and (pointer: fine) { .search-clear:hover { color: var(--ink); background: var(--mist); } }
|
||||
/* CT3: result count with the "taught in" filter beside it */
|
||||
.catalog-bar { display: flex; align-items: center; justify-content: space-between; gap: 8px 12px; flex-wrap: wrap; }
|
||||
.catalog-lang { display: inline-flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--ink-3); }
|
||||
.catalog-lang select { min-height: 40px; padding: 6px 10px; border-radius: 12px; border: 1px solid var(--line); background: var(--paper); color: var(--ink); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; }
|
||||
@media (pointer: coarse) { .catalog-lang select { font-size: 16px; } } /* iOS zooms into anything smaller */
|
||||
.chip { flex: none; border: 1px solid var(--line); background: var(--paper); padding: 8px 14px; border-radius: var(--r-pill); cursor: pointer; font-weight: 700; color: var(--ink-2); }
|
||||
.chip[aria-pressed="true"] { background: var(--ink); color: var(--on-ink); border-color: var(--ink); }
|
||||
|
||||
|
|
|
|||
|
|
@ -124,7 +124,12 @@
|
|||
"all": "ሁሉም",
|
||||
"count": "{n} ኮርሶች",
|
||||
"empty": "ከ«{q}» ጋር የሚዛመድ ኮርስ የለም። አጠር ያለ ቃል ይሞክሩ።",
|
||||
"emptyCategory": "በዚህ ምድብ እስካሁን ኮርስ የለም።"
|
||||
"emptyCategory": "በዚህ ምድብ እስካሁን ኮርስ የለም።",
|
||||
"clearSearch": "ፍለጋውን አጽዳ",
|
||||
"taughtIn": "የማስተማሪያ ቋንቋ",
|
||||
"anyLanguage": "ማንኛውም ቋንቋ",
|
||||
"clearFilters": "ማጣሪያዎችን አጽዳ",
|
||||
"emptyLanguage": "በዚህ ቋንቋ እስካሁን ኮርስ የለም።"
|
||||
},
|
||||
"course": {
|
||||
"buyShort": "ኮርሱን ይግዙ",
|
||||
|
|
|
|||
|
|
@ -124,7 +124,12 @@
|
|||
"all": "All",
|
||||
"count": "{n, plural, one {# course} other {# courses}}",
|
||||
"empty": "No courses match “{q}”. Try a shorter word.",
|
||||
"emptyCategory": "No courses in this category yet."
|
||||
"emptyCategory": "No courses in this category yet.",
|
||||
"clearSearch": "Clear search",
|
||||
"taughtIn": "Taught in",
|
||||
"anyLanguage": "Any language",
|
||||
"clearFilters": "Clear filters",
|
||||
"emptyLanguage": "No courses in this language here yet."
|
||||
},
|
||||
"course": {
|
||||
"buyShort": "Buy course",
|
||||
|
|
|
|||
|
|
@ -124,7 +124,12 @@
|
|||
"all": "Hunda",
|
||||
"count": "Koorsii {n}",
|
||||
"empty": "Koorsiin “{q}” wajjin walsimu hin jiru. Jecha gabaabaa yaali.",
|
||||
"emptyCategory": "Ramaddii kana keessa ammatti koorsiin hin jiru."
|
||||
"emptyCategory": "Ramaddii kana keessa ammatti koorsiin hin jiru.",
|
||||
"clearSearch": "Barbaacha haqi",
|
||||
"taughtIn": "Afaan barsiisaa",
|
||||
"anyLanguage": "Afaan kamiyyuu",
|
||||
"clearFilters": "Calaltuu haqi",
|
||||
"emptyLanguage": "Afaan kanaan koorsiin ammaaf hin jiru."
|
||||
},
|
||||
"course": {
|
||||
"buyShort": "Koorsii bitadhu",
|
||||
|
|
|
|||
|
|
@ -124,7 +124,12 @@
|
|||
"all": "ኩሉ",
|
||||
"count": "{n} ኮርሳት",
|
||||
"empty": "ምስ «{q}» ዝሰማማዕ ኮርስ የለን። ሓጺር ቃል ፈትን።",
|
||||
"emptyCategory": "ኣብዚ ምድብ ክሳብ ሕጂ ኮርስ የለን።"
|
||||
"emptyCategory": "ኣብዚ ምድብ ክሳብ ሕጂ ኮርስ የለን።",
|
||||
"clearSearch": "ምድላይ ኣጽሪ",
|
||||
"taughtIn": "ቋንቋ ምምሃር",
|
||||
"anyLanguage": "ዝኾነ ቋንቋ",
|
||||
"clearFilters": "መጻረዪታት ኣጽሪ",
|
||||
"emptyLanguage": "ብዚ ቋንቋ ክሳብ ሕጂ ኮርስ የለን።"
|
||||
},
|
||||
"course": {
|
||||
"buyShort": "ኮርስ ግዝእ",
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user