2023-10-24 14:57:37 -05:00
|
|
|
import FilterSearchDropdown from "@/components/FilterSearchDropdown";
|
|
|
|
import SortDropdown from "@/components/SortDropdown";
|
|
|
|
import useLinks from "@/hooks/useLinks";
|
|
|
|
import MainLayout from "@/layouts/MainLayout";
|
|
|
|
import useLinkStore from "@/store/links";
|
2023-12-17 00:25:46 -06:00
|
|
|
import { Sort, ViewMode } from "@/types/global";
|
2023-06-05 11:18:54 -05:00
|
|
|
import { useRouter } from "next/router";
|
2023-12-17 02:57:05 -06:00
|
|
|
import React, { useState } from "react";
|
2023-12-17 00:25:46 -06:00
|
|
|
import ViewDropdown from "@/components/ViewDropdown";
|
2023-12-21 04:08:56 -06:00
|
|
|
import CardView from "@/components/LinkViews/Layouts/CardView";
|
|
|
|
import GridView from "@/components/LinkViews/Layouts/GridView";
|
|
|
|
import ListView from "@/components/LinkViews/Layouts/ListView";
|
2023-12-17 02:57:05 -06:00
|
|
|
import PageHeader from "@/components/PageHeader";
|
2023-10-24 14:57:37 -05:00
|
|
|
|
|
|
|
export default function Search() {
|
|
|
|
const { links } = useLinkStore();
|
2023-05-08 09:35:39 -05:00
|
|
|
|
2023-06-05 11:18:54 -05:00
|
|
|
const router = useRouter();
|
2023-05-08 09:35:39 -05:00
|
|
|
|
2023-10-24 14:57:37 -05:00
|
|
|
const [searchFilter, setSearchFilter] = useState({
|
|
|
|
name: true,
|
|
|
|
url: true,
|
|
|
|
description: true,
|
2023-11-01 05:01:26 -05:00
|
|
|
textContent: true,
|
2023-10-24 14:57:37 -05:00
|
|
|
tags: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
const [filterDropdown, setFilterDropdown] = useState(false);
|
2023-12-17 00:25:46 -06:00
|
|
|
|
|
|
|
const [viewMode, setViewMode] = useState<string>(
|
|
|
|
localStorage.getItem("viewMode") || ViewMode.Default
|
|
|
|
);
|
2023-10-24 14:57:37 -05:00
|
|
|
const [sortBy, setSortBy] = useState<Sort>(Sort.DateNewestFirst);
|
|
|
|
|
|
|
|
useLinks({
|
|
|
|
sort: sortBy,
|
|
|
|
searchQueryString: decodeURIComponent(router.query.q as string),
|
|
|
|
searchByName: searchFilter.name,
|
|
|
|
searchByUrl: searchFilter.url,
|
|
|
|
searchByDescription: searchFilter.description,
|
2023-11-01 05:01:26 -05:00
|
|
|
searchByTextContent: searchFilter.textContent,
|
2023-10-24 14:57:37 -05:00
|
|
|
searchByTags: searchFilter.tags,
|
|
|
|
});
|
|
|
|
|
2023-12-17 00:25:46 -06:00
|
|
|
const linkView = {
|
2023-12-21 04:08:56 -06:00
|
|
|
[ViewMode.Default]: CardView,
|
2023-12-17 00:25:46 -06:00
|
|
|
// [ViewMode.Grid]: GridView,
|
|
|
|
[ViewMode.List]: ListView,
|
|
|
|
};
|
|
|
|
|
|
|
|
// @ts-ignore
|
|
|
|
const LinkComponent = linkView[viewMode];
|
|
|
|
|
2023-10-24 14:57:37 -05:00
|
|
|
return (
|
|
|
|
<MainLayout>
|
|
|
|
<div className="p-5 flex flex-col gap-5 w-full">
|
2023-12-17 22:32:33 -06:00
|
|
|
<div className="flex justify-between">
|
|
|
|
<PageHeader icon={"bi-search"} title={"Search Results"} />
|
2023-10-24 14:57:37 -05:00
|
|
|
|
2023-12-17 22:32:33 -06:00
|
|
|
<div className="flex gap-3 items-center justify-end">
|
|
|
|
<div className="flex gap-2 items-center mt-2">
|
|
|
|
<FilterSearchDropdown
|
|
|
|
searchFilter={searchFilter}
|
|
|
|
setSearchFilter={setSearchFilter}
|
|
|
|
/>
|
|
|
|
<SortDropdown sortBy={sortBy} setSort={setSortBy} />
|
|
|
|
<ViewDropdown viewMode={viewMode} setViewMode={setViewMode} />
|
|
|
|
</div>
|
2023-10-24 14:57:37 -05:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-12-17 22:32:33 -06:00
|
|
|
|
2023-10-24 14:57:37 -05:00
|
|
|
{links[0] ? (
|
2023-12-17 00:25:46 -06:00
|
|
|
<LinkComponent links={links} />
|
2023-10-24 14:57:37 -05:00
|
|
|
) : (
|
2023-11-24 07:39:55 -06:00
|
|
|
<p>
|
2023-10-24 14:57:37 -05:00
|
|
|
Nothing found.{" "}
|
|
|
|
<span className="font-bold text-xl" title="Shruggie">
|
|
|
|
¯\_(ツ)_/¯
|
|
|
|
</span>
|
|
|
|
</p>
|
|
|
|
)}
|
|
|
|
</div>
|
|
|
|
</MainLayout>
|
|
|
|
);
|
2023-05-08 09:35:39 -05:00
|
|
|
}
|