import React, { useState } from 'react'; import Icon from '../common/Icon'; import SelectField, { SelectionOption } from '../common/SelectField'; type IdeasFilterProps = { allTags: string[], filterParams: KeywordFilters, filterKeywords: Function, keywords: IdeaKeyword[], favorites: IdeaKeyword[], updateSort: Function, showFavorites: Function, sortBy: string, } const IdeasFilters = (props: IdeasFilterProps) => { const { filterKeywords, allTags = [], updateSort, showFavorites, sortBy, filterParams, keywords = [], favorites = [] } = props; const [keywordType, setKeywordType] = useState<'all'|'favorites'>('all'); const [sortOptions, showSortOptions] = useState(false); const [filterOptions, showFilterOptions] = useState(false); const filterTags = (tags:string[]) => filterKeywords({ ...filterParams, tags }); const searchKeywords = (event:React.FormEvent) => { const filtered = filterKeywords({ ...filterParams, search: event.currentTarget.value }); return filtered; }; const sortOptionChoices: SelectionOption[] = [ { value: 'alpha_asc', label: 'Alphabetically(A-Z)' }, { value: 'alpha_desc', label: 'Alphabetically(Z-A)' }, { value: 'vol_asc', label: 'Lowest Search Volume' }, { value: 'vol_desc', label: 'Highest Search Volume' }, { value: 'competition_asc', label: 'High Competition' }, { value: 'competition_desc', label: 'Low Competition' }, ]; const sortItemStyle = (sortType:string) => { return `cursor-pointer py-2 px-3 hover:bg-[#FCFCFF] ${sortBy === sortType ? 'bg-indigo-50 text-indigo-600 hover:bg-indigo-50' : ''}`; }; const deviceTabStyle = 'select-none cursor-pointer px-3 py-2 rounded-3xl mr-2'; const deviceTabCountStyle = 'px-2 py-0 rounded-3xl bg-[#DEE1FC] text-[0.7rem] font-bold ml-1'; const mobileFilterOptionsStyle = 'visible mt-8 border absolute min-w-[0] rounded-lg max-h-96 bg-white z-50 w-52 right-2 p-4'; return (
  • { setKeywordType('all'); showFavorites(false); }}> All Keywords {keywords.length}
  • { setKeywordType('favorites'); showFavorites(true); }}> Favorites {favorites.length}
{keywordType === 'all' && (
({ label: tag, value: tag }))} defaultLabel={`All Groups (${allTags.length})`} updateField={(updated:string[]) => filterTags(updated)} emptyMsg="No Groups Found for this Domain" minWidth={270} />
)}
{sortOptions && (
    {sortOptionChoices.map((sortOption) => { return
  • { updateSort(sortOption.value); showSortOptions(false); }}> {sortOption.label}
  • ; })}
)}
); }; export default IdeasFilters;