import { FC, useCallback, useEffect, useState } from 'react'; import { Button, Column, Flex, Text } from '../../../common'; 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; } 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 setQuery(e.target.value) } onKeyDown={ handleKeyDown } /> Type { items.map(item => ( onSelect(item.id) } > )) } { items.length === 0 && !loading && }
ID Sprite Name Public Name Type Interaction
{ item.id } { item.spriteId } { item.itemName } { item.publicName } { item.type === 's' ? 'Floor' : 'Wall' } { item.interactionType || '-' }
No items found
{ totalPages > 1 && { total } items - Page { page }/{ totalPages } }
); };