import { FC, useCallback, useEffect, useState } from 'react'; import { FaSearch } from 'react-icons/fa'; import { Column, Text } from '../../../common'; import { LayoutFurniIconImageView } from '../../../common/layout/LayoutFurniIconImageView'; import { FurniItem } from '../../../hooks/furni-editor'; interface FurniEditorSearchViewProps { items: FurniItem[]; total: number; page: number; loading: boolean; onSearch: (query: string, type: string, page: number) => void; onSelect: (id: number) => void; } const inputClass = 'text-[14px] border border-[#c5cdd6] rounded px-2 py-1.5 bg-white focus:outline-none focus:border-[#1e7295] transition-colors w-full'; export const FurniEditorSearchView: FC = props => { const { items, total, page, loading, onSearch, onSelect } = props; const [ query, setQuery ] = useState(''); const [ typeFilter, setTypeFilter ] = useState(''); useEffect(() => { onSearch('', '', 1); }, []); const handleSearch = useCallback(() => { onSearch(query, typeFilter, 1); }, [ query, typeFilter, onSearch ]); const handleKeyDown = useCallback((e: React.KeyboardEvent) => { if(e.key === 'Enter') handleSearch(); }, [ handleSearch ]); const totalPages = Math.ceil(total / 20); return ( { /* Search Bar */ }
setQuery(e.target.value) } onKeyDown={ handleKeyDown } />
{ /* Results counter */ } { total > 0 &&
{ total } items found { totalPages > 1 && - Page { page }/{ totalPages } }
} { /* Results Table */ }
{ loading &&
Loading...
} { !loading && items.length === 0 &&
No items found
} { !loading && items.length > 0 && { items.map(item => ( onSelect(item.id) } > )) }
ID Sprite Name Public Name Type Interaction
{ item.id } { item.spriteId } { item.itemName } { item.publicName } { item.type === 's' ? 'Floor' : 'Wall' } { item.interactionType || '-' }
}
{ /* Pagination */ } { totalPages > 1 &&
Page { page } of { totalPages }
}
); };