-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Andrei/agora 2296 endorsed delegates (#407)
* Merge * Filtering endorsed delegates * Misc * Removed endorsed filter toggle * build * Code review comments * Hotfix --------- Co-authored-by: Andrei Taraschuk <andrei@Andreis-MacBook-Pro.local>
- Loading branch information
Showing
13 changed files
with
227 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
"use client"; | ||
|
||
import { useRouter, useSearchParams } from "next/navigation"; | ||
import { Listbox } from "@headlessui/react"; | ||
import { Fragment } from "react"; | ||
import { ChevronDown } from "lucide-react"; | ||
import { useAddSearchParam, useDeleteSearchParam } from "@/hooks"; | ||
import { useAgoraContext } from "@/contexts/AgoraContext"; | ||
|
||
const FILTER_PARAM = "endorsedFilter"; | ||
const DEFAULT_FILTER = "all"; | ||
|
||
export default function EndorsedFilter() { | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
const addSearchParam = useAddSearchParam(); | ||
const deleteSearchParam = useDeleteSearchParam(); | ||
const filterParam = searchParams?.get(FILTER_PARAM) || "all"; | ||
const { setIsDelegatesFiltering } = useAgoraContext(); | ||
|
||
let endorsedFilterOptions: any = { | ||
all: { | ||
value: "All Delegates", | ||
sort: "all", | ||
}, | ||
true: { | ||
value: "Endorsed Delegates", | ||
sort: "true", | ||
}, | ||
}; | ||
|
||
const handleChange = (value: string) => { | ||
setIsDelegatesFiltering(true); | ||
router.push( | ||
value === DEFAULT_FILTER | ||
? deleteSearchParam({ name: FILTER_PARAM }) | ||
: addSearchParam({ name: FILTER_PARAM, value }), | ||
{ scroll: false } | ||
); | ||
}; | ||
|
||
return ( | ||
<Listbox | ||
as="div" | ||
value={filterParam || endorsedFilterOptions.all.value} | ||
onChange={(value) => handleChange(value)} | ||
> | ||
{() => ( | ||
<> | ||
<Listbox.Button className="w-full sm:w-fit bg-[#F7F7F7] text-base font-medium border-none rounded-full py-2 px-4 flex items-center"> | ||
{endorsedFilterOptions[filterParam]?.value || | ||
endorsedFilterOptions.all.value} | ||
<ChevronDown className="h-4 w-4 ml-[2px] opacity-30 hover:opacity-100" /> | ||
</Listbox.Button> | ||
<Listbox.Options className="mt-3 absolute bg-[#F7F7F7] border border-[#ebebeb] p-2 rounded-2xl flex flex-col gap-1 z-20 w-max"> | ||
{Object.keys(endorsedFilterOptions).map((key) => ( | ||
<Listbox.Option key={key} value={key} as={Fragment}> | ||
{({ selected }) => { | ||
return ( | ||
<li | ||
className={`cursor-pointer text-base py-2 px-3 border rounded-xl font-medium ${ | ||
selected | ||
? "text-black bg-white border-[#ebebeb]" | ||
: "text-[#66676b] border-transparent" | ||
}`} | ||
> | ||
{endorsedFilterOptions[key].value} | ||
</li> | ||
); | ||
}} | ||
</Listbox.Option> | ||
))} | ||
</Listbox.Options> | ||
</> | ||
)} | ||
</Listbox> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.