"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

ПОЛНЫЙ ИНДЕКС

Статьи и заметки

{articles.length} материалов
setQ(event.target.value)} placeholder="Тема, язык или задача"/>
{topics.map(value=>)}
{shown.length?`Найдено материалов: ${shown.length}`:'По этому запросу ничего нет. Попробуйте другое слово или сбросьте тему.'}
{shown.map(article=>{if(event.isTrusted&&q.trim())onResultSelect?.();}}/>)}
{!shown.length&&}
; }