"use client" import { usePathname, useRouter, useSearchParams } from "next/navigation" import React, { FormEvent, useState } from "react" import { Select, SelectContent, SelectTrigger, SelectItem } from "./ui/select" import { subDays, subMonths, subYears } from "date-fns" type Props = { value: string placeholder?: string className?: string filters?: { sites: {value: string, label:string}[] } } export const TIME_FILTER_OPTIONS = [ { value: subDays(new Date(), 1), label: '1d ago' }, { value: subDays(new Date(), 7), label: '7d ago' }, { value: subDays(new Date(), 15), label: '15d ago' }, { value: subMonths(new Date(), 1), label: '1m ago' }, { value: subMonths(new Date(), 6), label: '6m ago' }, { value: subYears(new Date(), 1), label: '1y ago' }, ]; const SimplifiedSearchBar = ({ value: initialValue, placeholder, filters, className }: Props) => { const searchParams = useSearchParams(); const pathname = usePathname(); const router = useRouter(); const [value, setValue] = useState(initialValue) const handleSearch = (event: FormEvent) => { event.preventDefault(); const newSearchParams = new URLSearchParams(searchParams) if(value) { newSearchParams.set('q', value) } else { newSearchParams.delete('q') } router.push(`${pathname}?${newSearchParams}`) } return (
results:
setValue(e.target.value)} size={value.length} />
) } export default SimplifiedSearchBar