diff --git a/src/components/SearchBar.tsx b/src/components/SearchBar.tsx index abdf799..80197cf 100644 --- a/src/components/SearchBar.tsx +++ b/src/components/SearchBar.tsx @@ -11,7 +11,7 @@ import { ChevronDownIcon, ChevronRightIcon } from "@heroicons/react/24/outline" import { flushSync } from "react-dom" import Link from "next/link" import { usePathname, useSearchParams, useRouter } from "next/navigation" -import { formatDate, getResults } from "@/utils" +import { FILTER_TIMES, formatDate, getResults } from "@/utils" import { Select, SelectContent, @@ -198,29 +198,6 @@ const SearchBar = ({}: Props) => { ) } -const FILTER_TIMES = [ - { - label: "All Times", - value: 0, - }, - { - label: "1d ago", - value: 1 - }, - { - label: "7d ago", - value: 7 - }, - { - label: "15d ago", - value: 15 - }, - { - label: "1m ago", - value: 30 - } -] - // Placeholder components for Shadcn const LoadingComponent = () => { // Replace with actual Shadcn Loading component diff --git a/src/components/SimplifiedSearchBar.tsx b/src/components/SimplifiedSearchBar.tsx index b2dea55..ac13de0 100644 --- a/src/components/SimplifiedSearchBar.tsx +++ b/src/components/SimplifiedSearchBar.tsx @@ -2,46 +2,37 @@ 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" +import { Select, SelectContent, SelectTrigger, SelectItem, SelectValue } from "./ui/select" +import { SitesCombobox } from "./SitesCombobox" +import { FILTER_TIMES } from "@/utils" type Props = { value: string placeholder?: string className?: string filters?: { - sites: {value: string, label:string}[] + 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 searchParams = useSearchParams() + const pathname = usePathname() + const router = useRouter() const [value, setValue] = useState(initialValue) const handleSearch = (event: FormEvent) => { - event.preventDefault(); - const newSearchParams = new URLSearchParams(searchParams) + event.preventDefault() + const newSearchParams = new URLSearchParams(searchParams ?? undefined) - if(value) { - newSearchParams.set('q', value) + if (value) { + newSearchParams.set("q", value) } else { - newSearchParams.delete('q') + newSearchParams.delete("q") } router.push(`${pathname}?${newSearchParams}`) @@ -54,10 +45,16 @@ const SimplifiedSearchBar = ({
results:
setValue(e.target.value)} @@ -65,24 +62,26 @@ const SimplifiedSearchBar = ({ />
-
- - -
+
+ {/* Dropdown component should be here */} + + {/* Dropdown component should be here */} + +
) } diff --git a/src/utils.ts b/src/utils.ts index f4129b8..353a00a 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,4 +1,4 @@ -import { formatDistanceToNow } from "date-fns" +import { formatDistanceToNow, subDays, subMonths, subYears } from "date-fns" import { clsx, type ClassValue } from "clsx" import { twMerge } from "tailwind-merge" @@ -70,4 +70,14 @@ export async function getAvailableSites() { return statuses; -} \ No newline at end of file +} + +export const FILTER_TIMES = [ + { value: 0, label: "All Times" }, + { 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" } +] \ No newline at end of file