import { SortOption } from '../types/SortOption'; import { ViewTypes } from '../types/ViewTypes'; import React, { useEffect, useState } from 'react'; import { TextInput, Inline, Select, Flex, Switch, Label } from '@sanity/ui'; import { SearchIcon, UlistIcon } from '@sanity/icons'; import { useDebounce } from '../hooks/useDebounce'; interface Props { onSortChange: (value: SortOption) => void; setSearchQuery: (value: string) => void; setViewType: (type: ViewTypes) => void; viewType: ViewTypes; } export const TopBar = ({ onSortChange, setSearchQuery, setViewType, viewType }: Props) => { const [query, setQuery] = useState(''); const debouncedSearchQuery = useDebounce(query, 250); useEffect(() => { setSearchQuery(debouncedSearchQuery); }, [debouncedSearchQuery]); return ( setViewType(viewType === 'grid' ? 'list' : 'grid')} checked={viewType === 'list'} /> setQuery(e.currentTarget.value)} /> ); };