el.xwx.moe/components/FilterSearchDropdown.tsx

148 lines
4.6 KiB
TypeScript
Raw Normal View History

2024-01-14 09:09:09 -06:00
import { dropdownTriggerer } from "@/lib/client/utils";
2024-08-16 12:42:55 -05:00
import React, { useEffect } from "react";
2024-06-09 08:27:16 -05:00
import { useTranslation } from "next-i18next";
2024-08-16 12:42:55 -05:00
import { resetInfiniteQueryPagination } from "@/hooks/store/links";
import { useQueryClient } from "@tanstack/react-query";
2023-06-05 04:54:43 -05:00
type Props = {
2023-06-05 11:18:54 -05:00
setSearchFilter: Function;
2023-10-26 17:49:46 -05:00
searchFilter: {
name: boolean;
url: boolean;
description: boolean;
2023-11-01 05:01:26 -05:00
textContent: boolean;
2023-10-26 17:49:46 -05:00
tags: boolean;
};
2023-06-05 04:54:43 -05:00
};
export default function FilterSearchDropdown({
2023-06-05 11:18:54 -05:00
setSearchFilter,
searchFilter,
2023-06-05 04:54:43 -05:00
}: Props) {
2024-06-09 08:27:16 -05:00
const { t } = useTranslation();
2024-08-16 12:42:55 -05:00
const queryClient = useQueryClient();
2024-06-09 08:27:16 -05:00
2023-06-05 04:54:43 -05:00
return (
<div className="dropdown dropdown-bottom dropdown-end">
<div
tabIndex={0}
role="button"
2024-01-14 09:09:09 -06:00
onMouseDown={dropdownTriggerer}
className="btn btn-sm btn-square btn-ghost"
>
2023-12-29 11:21:22 -06:00
<i className="bi-funnel text-neutral text-2xl"></i>
2023-06-05 04:54:43 -05:00
</div>
<ul className="dropdown-content z-[30] menu shadow bg-base-200 border border-neutral-content rounded-box mt-1">
<li>
<label
className="label cursor-pointer flex justify-start"
tabIndex={0}
role="button"
>
<input
type="checkbox"
name="search-filter-checkbox"
className="checkbox checkbox-primary"
checked={searchFilter.name}
2024-08-16 12:42:55 -05:00
onChange={() => {
resetInfiniteQueryPagination(queryClient, ["links"]);
setSearchFilter({ ...searchFilter, name: !searchFilter.name });
}}
/>
<span className="label-text whitespace-nowrap">{t("name")}</span>
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
tabIndex={0}
role="button"
>
<input
type="checkbox"
name="search-filter-checkbox"
className="checkbox checkbox-primary"
checked={searchFilter.url}
2024-08-16 12:42:55 -05:00
onChange={() => {
resetInfiniteQueryPagination(queryClient, ["links"]);
setSearchFilter({ ...searchFilter, url: !searchFilter.url });
}}
/>
<span className="label-text whitespace-nowrap">{t("link")}</span>
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
tabIndex={0}
role="button"
>
<input
type="checkbox"
name="search-filter-checkbox"
className="checkbox checkbox-primary"
checked={searchFilter.description}
2024-08-16 12:42:55 -05:00
onChange={() => {
resetInfiniteQueryPagination(queryClient, ["links"]);
setSearchFilter({
...searchFilter,
description: !searchFilter.description,
2024-08-16 12:42:55 -05:00
});
}}
/>
<span className="label-text whitespace-nowrap">
{t("description")}
</span>
</label>
</li>
<li>
<label
className="label cursor-pointer flex justify-start"
tabIndex={0}
role="button"
>
<input
type="checkbox"
name="search-filter-checkbox"
className="checkbox checkbox-primary"
2024-03-10 05:08:28 -05:00
checked={searchFilter.tags}
2024-08-16 12:42:55 -05:00
onChange={() => {
resetInfiniteQueryPagination(queryClient, ["links"]);
setSearchFilter({ ...searchFilter, tags: !searchFilter.tags });
}}
/>
<span className="label-text whitespace-nowrap">{t("tags")}</span>
</label>
</li>
<li>
<label
2024-03-10 05:08:28 -05:00
className="label cursor-pointer flex justify-between"
tabIndex={0}
role="button"
>
<input
type="checkbox"
name="search-filter-checkbox"
className="checkbox checkbox-primary"
2024-03-10 05:08:28 -05:00
checked={searchFilter.textContent}
2024-08-16 12:42:55 -05:00
onChange={() => {
resetInfiniteQueryPagination(queryClient, ["links"]);
setSearchFilter({
...searchFilter,
2024-03-10 05:08:28 -05:00
textContent: !searchFilter.textContent,
2024-08-16 12:42:55 -05:00
});
}}
/>
<span className="label-text whitespace-nowrap">
{t("full_content")}
</span>
<div className="ml-auto badge badge-sm badge-neutral whitespace-nowrap">
2024-06-09 08:27:16 -05:00
{t("slower")}
</div>
</label>
</li>
</ul>
</div>
2023-06-05 04:54:43 -05:00
);
}