Skip to content

Commit

Permalink
Sort proposals by creation date second to the user define order
Browse files Browse the repository at this point in the history
  • Loading branch information
thesan committed Feb 29, 2024
1 parent 122e9f0 commit 7eb5b3d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
10 changes: 7 additions & 3 deletions packages/ui/src/common/hooks/useSort.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,14 @@ export interface SortOrder<Order extends BaseSortKey> {
isDescending: boolean
}

export function toQueryOrderByInput<Order extends BaseSortKey>(order: SortOrder<Order>) {
const value = order.isDescending ? `${order.orderKey}_DESC` : `${order.orderKey}_ASC`
export function toQueryOrderByInput<Order extends BaseSortKey>(...orders: (SortOrder<Order> | undefined)[]): Order[] {
return orders.flatMap((order) => {
if (!order) return []

return value as Order
const value = order.isDescending ? `${order.orderKey}_DESC` : `${order.orderKey}_ASC`

return value as Order
})
}

export type GetSortProps<Order extends BaseSortKey> = (key: OrderKey<Order>) => {
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/src/proposals/hooks/useProposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export const useProposals = ({
perPage = 10,
fetchAll = false,
}: UseProposalsProps): UseProposals => {
const orderBy = order ? toQueryOrderByInput<ProposalOrderByInput>(order) : ProposalOrderByInput.CreatedAtDesc
const orderBy = toQueryOrderByInput<ProposalOrderByInput>(order, {
orderKey: 'createdAt',
isDescending: order?.isDescending ?? false,
})

const where = useMemo(() => {
const where: ProposalWhereInput = filters?.stage
Expand Down

0 comments on commit 7eb5b3d

Please sign in to comment.