fix: get search results working

This commit is contained in:
Derrick Hammer 2023-12-22 04:42:21 -05:00
parent 7251656bef
commit 369996ff2c
Signed by: pcfreak30
GPG Key ID: C997C339BE476FF2
4 changed files with 27 additions and 7 deletions

View File

@ -9,6 +9,7 @@ import {
} from "./ui/select"; } from "./ui/select";
import { SitesCombobox } from "./SitesCombobox"; import { SitesCombobox } from "./SitesCombobox";
import { FILTER_TIMES } from "@/utils"; import { FILTER_TIMES } from "@/utils";
import { SiteList } from "@/types.js";
type Props = { type Props = {
value: string; value: string;
@ -17,6 +18,7 @@ type Props = {
filters?: { filters?: {
sites: { value: string; label: string }[]; sites: { value: string; label: string }[];
}; };
sites: SiteList;
}; };
const SimplifiedSearchBar = ({ const SimplifiedSearchBar = ({
@ -24,6 +26,7 @@ const SimplifiedSearchBar = ({
placeholder, placeholder,
filters, filters,
className, className,
sites,
}: Props) => { }: Props) => {
let navigate = useNavigate(); let navigate = useNavigate();
let location = useLocation(); let location = useLocation();
@ -69,7 +72,7 @@ const SimplifiedSearchBar = ({
</div> </div>
<div className="w-56 flex gap-2"> <div className="w-56 flex gap-2">
{/* Dropdown component should be here */} {/* Dropdown component should be here */}
<SitesCombobox /> <SitesCombobox siteList={sites} />
{/* Dropdown component should be here */} {/* Dropdown component should be here */}
<Select defaultValue={"0"}> <Select defaultValue={"0"}>
<SelectTrigger className="hover:bg-muted w-auto"> <SelectTrigger className="hover:bg-muted w-auto">

View File

@ -15,7 +15,6 @@ import {
PopoverTrigger, PopoverTrigger,
} from "@/components/ui/popover"; } from "@/components/ui/popover";
import { ChevronDownIcon } from "@heroicons/react/24/solid"; import { ChevronDownIcon } from "@heroicons/react/24/solid";
import { getAvailableSites } from "@/utils";
import { SelectOptions, SiteList } from "@/types.js"; import { SelectOptions, SiteList } from "@/types.js";
import slugify from "slugify"; import slugify from "slugify";

View File

@ -1,14 +1,30 @@
import React from "react"; import React from "react";
import { ArrowLeftIcon } from "@heroicons/react/24/outline"; import { ArrowLeftIcon } from "@heroicons/react/24/outline";
import { formatDate, getResults } from "@/utils"; import { formatDate, getAvailableSites, getResults } from "@/utils";
import SimplifiedSearchBar from "@/components/SimplifiedSearchBar"; import SimplifiedSearchBar from "@/components/SimplifiedSearchBar";
import { Link, useSearchParams } from "@remix-run/react"; import { Link, useLoaderData, useSearchParams } from "@remix-run/react";
import { json, LoaderFunction } from "@remix-run/node";
import type { SearchResult, SiteList } from "@/types.js";
const Page = async () => { type LoaderData = {
const [searchParams] = useSearchParams(); sites: SiteList;
const query = searchParams.get("q") ?? ""; results: SearchResult[];
query: string;
};
export let loader: LoaderFunction = async ({ request }) => {
const sites = getAvailableSites();
const search = new URL(request.url).searchParams;
const query = search.get("q") ?? "";
const results = await getResults({ query: query }); const results = await getResults({ query: query });
// Return the fetched data as JSON
return json({ sites, results, query });
};
const Page = () => {
const { sites, results, query } = useLoaderData<LoaderData>();
return ( return (
<div className="w-full items-center text-lg"> <div className="w-full items-center text-lg">
<SimplifiedSearchBar <SimplifiedSearchBar
@ -16,6 +32,7 @@ const Page = async () => {
placeholder={ placeholder={
query ? undefined : "Search for web3 news from the community" query ? undefined : "Search for web3 news from the community"
} }
sites={sites}
/> />
<Link to="/"> <Link to="/">

View File

@ -5,4 +5,5 @@ export default {
// assetsBuildDirectory: "public/build", // assetsBuildDirectory: "public/build",
// publicPath: "/build/", // publicPath: "/build/",
// serverBuildPath: "build/index.js", // serverBuildPath: "build/index.js",
browserNodeBuiltinsPolyfill: { modules: { fs: true } },
}; };