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

114 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
collection: true,
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-06-05 10:13:04 -05:00
className="sm:w-8 sm:h-8 w-6 h-6 mt-2 text-sky-500 drop-shadow"
2023-06-05 05:16:04 -05:00
/>
<p className="sm:text-4xl text-3xl capitalize bg-gradient-to-tr from-sky-500 to-slate-400 bg-clip-text text-transparent font-bold">
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-05-31 13:33:01 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1"
2023-05-15 21:13:59 -05:00
>
<FontAwesomeIcon
icon={faFilter}
id="filter-dropdown"
className="w-5 h-5 text-gray-500"
/>
</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-05-31 13:33:01 -05:00
className="inline-flex rounded-md cursor-pointer hover:bg-slate-200 duration-100 p-1"
2023-05-15 21:13:59 -05:00
>
<FontAwesomeIcon
icon={faSort}
id="sort-dropdown"
className="w-5 h-5 text-gray-500"
/>
</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} />;
})
) : (
<p className="text-sky-900">
Nothing found.{" "}
<span className="text-sky-500 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
);
}