el.xwx.moe/pages/search/[query].tsx

113 lines
3.7 KiB
TypeScript
Raw Normal View History

2023-06-05 04:54:43 -05:00
import FilterSearchDropdown from "@/components/FilterSearchDropdown";
2023-06-05 15:47:01 -05:00
import LinkCard from "@/components/LinkCard";
2023-06-13 23:40:23 -05:00
import SortDropdown from "@/components/SortDropdown";
import useLinks from "@/hooks/useLinks";
import MainLayout from "@/layouts/MainLayout";
2023-05-08 09:35:39 -05:00
import useLinkStore from "@/store/links";
import { LinkSearchFilter, Sort } from "@/types/global";
2023-05-15 21:13:59 -05:00
import { faFilter, faSearch, faSort } from "@fortawesome/free-solid-svg-icons";
2023-05-08 09:35:39 -05:00
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
2023-06-05 11:18:54 -05:00
import { useRouter } from "next/router";
import { useState } from "react";
2023-06-05 11:18:54 -05:00
2023-05-08 09:35:39 -05:00
export default function Links() {
const { links } = useLinkStore();
2023-06-05 11:18:54 -05:00
const router = useRouter();
const [searchFilter, setSearchFilter] = useState<LinkSearchFilter>({
2023-06-05 11:18:54 -05:00
name: true,
url: true,
2023-06-13 23:40:23 -05:00
description: true,
2023-06-05 11:18:54 -05:00
tags: true,
});
2023-05-15 21:13:59 -05:00
const [filterDropdown, setFilterDropdown] = useState(false);
const [sortDropdown, setSortDropdown] = useState(false);
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
2023-06-13 23:40:23 -05:00
useLinks({
searchFilter: searchFilter,
searchQuery: router.query.query as string,
sort: sortBy,
});
2023-05-08 09:35:39 -05:00
return (
<MainLayout>
2023-05-08 09:35:39 -05:00
<div className="p-5 flex flex-col gap-5 w-full">
2023-05-15 21:13:59 -05:00
<div className="flex gap-3 items-center justify-between">
2023-06-05 05:16:04 -05:00
<div className="flex gap-3 items-center mb-5">
<div className="flex gap-2">
<FontAwesomeIcon
icon={faSearch}
2023-08-11 00:11:02 -05:00
className="sm:w-8 sm:h-8 w-6 h-6 mt-2 text-sky-500 dark:text-sky-300 drop-shadow"
2023-06-05 05:16:04 -05:00
/>
2023-08-14 22:25:25 -05:00
<p className="sm:text-4xl text-3xl capitalize text-black dark:text-white">
2023-06-05 05:16:04 -05:00
Search Results
</p>
</div>
2023-05-08 09:35:39 -05:00
</div>
2023-05-15 21:13:59 -05:00
<div className="flex gap-3 items-center">
<div className="relative">
<div
onClick={() => setFilterDropdown(!filterDropdown)}
id="filter-dropdown"
2023-08-14 22:25:25 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 hover:dark:bg-neutral-700 duration-100 p-1"
2023-05-15 21:13:59 -05:00
>
<FontAwesomeIcon
icon={faFilter}
id="filter-dropdown"
2023-08-22 17:34:46 -05:00
className="w-5 h-5 text-gray-500 dark:text-gray-300"
2023-05-15 21:13:59 -05:00
/>
</div>
{filterDropdown ? (
2023-06-05 04:54:43 -05:00
<FilterSearchDropdown
setFilterDropdown={setFilterDropdown}
2023-06-05 11:18:54 -05:00
searchFilter={searchFilter}
setSearchFilter={setSearchFilter}
2023-06-05 04:54:43 -05:00
/>
2023-05-15 21:13:59 -05:00
) : null}
</div>
<div className="relative">
<div
onClick={() => setSortDropdown(!sortDropdown)}
id="sort-dropdown"
2023-08-14 22:25:25 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 hover:dark:bg-neutral-700 duration-100 p-1"
2023-05-15 21:13:59 -05:00
>
<FontAwesomeIcon
icon={faSort}
id="sort-dropdown"
2023-08-22 17:34:46 -05:00
className="w-5 h-5 text-gray-500 dark:text-gray-300"
2023-05-15 21:13:59 -05:00
/>
</div>
{sortDropdown ? (
2023-06-13 23:40:23 -05:00
<SortDropdown
2023-05-31 21:43:42 -05:00
sortBy={sortBy}
2023-06-13 23:40:23 -05:00
setSort={setSortBy}
2023-05-31 21:43:42 -05:00
toggleSortDropdown={() => setSortDropdown(!sortDropdown)}
/>
2023-05-15 21:13:59 -05:00
) : null}
</div>
</div>
2023-05-08 09:35:39 -05:00
</div>
{links[0] ? (
links.map((e, i) => {
2023-06-05 15:47:01 -05:00
return <LinkCard key={i} link={e} count={i} />;
})
) : (
2023-08-11 00:11:02 -05:00
<p className="text-black dark:text-white">
Nothing found.{" "}
2023-08-11 00:11:02 -05:00
<span className="font-bold text-xl" title="Shruggie">
¯\_()_/¯
</span>
</p>
)}
2023-05-08 09:35:39 -05:00
</div>
</MainLayout>
2023-05-08 09:35:39 -05:00
);
}