Implement ProgCode identity and real shared reading UI kit
Build and deploy / deploy (push) Successful in 2m39s
Build and deploy / deploy (push) Successful in 2m39s
This commit is contained in:
1 parent
99c848189e
commit
12562baeb5
2040 files changed
+184656
-181
No files matched your search
@@ -0,0 +1 @@
|
||||
export {JournalSearch} from './ui/JournalSearch';
|
||||
@@ -0,0 +1,16 @@
|
||||
"use client";
|
||||
import {useEffect,useState} from 'react';
|
||||
import {Button,Field,StatusMessage} from '../../../shared/ui';
|
||||
import {ArticleListItem} from '../../../entities/article';
|
||||
export function JournalSearch({articles,onResultSelect,onZeroResults}){
|
||||
const [q,setQ]=useState(''),[topic,setTopic]=useState('Все');
|
||||
const topics=['Все',...new Set(articles.flatMap(article=>article.categories))];
|
||||
const shown=articles.filter(article=>(topic==='Все'||article.categories.includes(topic))&&(article.title+' '+article.excerpt+' '+article.categories.join(' ')).toLocaleLowerCase('ru').includes(q.toLocaleLowerCase('ru')));
|
||||
useEffect(()=>{
|
||||
if(!q.trim()||shown.length)return;
|
||||
const timer=setTimeout(()=>onZeroResults?.(),500);
|
||||
return()=>clearTimeout(timer);
|
||||
},[q,shown.length,onZeroResults]);
|
||||
function reset(){setQ('');setTopic('Все');}
|
||||
return <section id="journal" className="journal"><div className="journal-heading"><div><p className="kicker">ПОЛНЫЙ ИНДЕКС</p><h2>Статьи и заметки</h2></div><span>{articles.length} материалов</span></div><div className="catalog-controls"><Field id="search" label="Найти в журнале" type="search" value={q} onChange={event=>setQ(event.target.value)} placeholder="Тема, язык или задача"/><div className="topic-tabs" aria-label="Темы">{topics.map(value=><Button variant="secondary" aria-pressed={topic===value} key={value} onClick={()=>setTopic(value)}>{value}</Button>)}</div></div><StatusMessage className="search-status">{shown.length?`Найдено материалов: ${shown.length}`:'По этому запросу ничего нет. Попробуйте другое слово или сбросьте тему.'}</StatusMessage><div className="journal-list">{shown.map(article=><ArticleListItem key={article.slug} article={article} onSelect={event=>{if(event.isTrusted&&q.trim())onResultSelect?.();}}/>)}</div>{!shown.length&&<Button variant="secondary" onClick={reset}>Сбросить поиск</Button>}</section>;
|
||||
}
|
||||
Reference in new issue
Block a user