-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Andrei/agora 1572 proposal filtering on index page (#128)
* Misc constant ref * WIP implemeting sort logic * implemented ui * Implementing ui * Misc * Refreshing filter list * Sort refresh and query update * Const reference * misc types updates * Minor component optimization * Type defs and cleanup * Proposal filter debug + optimization * Misc * Pagination fix * Remove unnused page var * JS nested els warning
- Loading branch information
Showing
10 changed files
with
172 additions
and
68 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
import { | ||
getProposalsForNamespace, | ||
getProposalForNamespace, | ||
getProposalTypesForNamespace, | ||
getProposalsForNamespace, | ||
} from "../common/proposals/getProposals"; | ||
import { ProposalFilter } from "@/app/api/proposals/proposal"; | ||
|
||
export const getProposals = ({ page = 1 }: { page: number }) => | ||
getProposalsForNamespace({ page, namespace: "optimism" }); | ||
export const getProposals = (params: { | ||
page: number; | ||
filter: ProposalFilter; | ||
}) => getProposalsForNamespace({ ...params, namespace: "optimism" }); | ||
|
||
export const getProposal = ({ proposal_id }: { proposal_id: string }) => | ||
getProposalForNamespace({ proposal_id, namespace: "optimism" }); | ||
export const getProposal = (params: { proposal_id: string }) => | ||
getProposalForNamespace({ ...params, namespace: "optimism" }); | ||
|
||
export const getProposalTypes = () => | ||
getProposalTypesForNamespace({ namespace: "optimism" }); |
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 @@ | ||
export type ProposalFilter = "relevant" | "everything"; |
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
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
56 changes: 56 additions & 0 deletions
56
src/components/Proposals/ProposalsFilter/ProposalsFilter.tsx
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,56 @@ | ||
"use client"; | ||
|
||
import { useRouter, useSearchParams } from "next/navigation"; | ||
import { proposalsFilterOptions } from "@/lib/constants"; | ||
import { Listbox } from "@headlessui/react"; | ||
import { Fragment, useEffect, useState } from "react"; | ||
import { ChevronDown } from "lucide-react"; | ||
|
||
export default function ProposalsFilter() { | ||
const router = useRouter(); | ||
const searchParams = useSearchParams(); | ||
const filterParam = searchParams?.get("filter"); | ||
const [selected, setSelected] = useState( | ||
filterParam || proposalsFilterOptions.relevant.filter | ||
); | ||
|
||
const isRecentFilter = selected === proposalsFilterOptions.relevant.filter; | ||
|
||
useEffect(() => { | ||
const handleChanges = (value: string) => { | ||
isRecentFilter ? router.push("/") : router.push(`/?filter=${value}`); | ||
}; | ||
|
||
handleChanges(selected); | ||
}, [router, selected]); | ||
|
||
return ( | ||
<div className="relative"> | ||
<Listbox value={selected} onChange={setSelected}> | ||
<Listbox.Button className="w-full md:w-fit bg-[#F7F7F7] text-base font-medium border-none rounded-full py-2 px-4 flex items-center"> | ||
{selected === proposalsFilterOptions.relevant.filter | ||
? proposalsFilterOptions.relevant.value | ||
: proposalsFilterOptions.everything.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"> | ||
{Object.values(proposalsFilterOptions).map((option) => ( | ||
<Listbox.Option key={option.filter} value={option.filter}> | ||
{({ selected }) => ( | ||
<div | ||
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" | ||
}`} | ||
> | ||
{option.value} | ||
</div> | ||
)} | ||
</Listbox.Option> | ||
))} | ||
</Listbox.Options> | ||
</Listbox> | ||
</div> | ||
); | ||
} |
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