From 7eb5b3dfa77f8870fc6710e584d57eb2771ff291 Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Thu, 29 Feb 2024 11:23:02 +0100 Subject: [PATCH 1/2] Sort proposals by creation date second to the user define order --- packages/ui/src/common/hooks/useSort.ts | 10 +++++++--- packages/ui/src/proposals/hooks/useProposals.ts | 5 ++++- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/packages/ui/src/common/hooks/useSort.ts b/packages/ui/src/common/hooks/useSort.ts index 7342e5c69c..742a745bfc 100644 --- a/packages/ui/src/common/hooks/useSort.ts +++ b/packages/ui/src/common/hooks/useSort.ts @@ -13,10 +13,14 @@ export interface SortOrder { isDescending: boolean } -export function toQueryOrderByInput(order: SortOrder) { - const value = order.isDescending ? `${order.orderKey}_DESC` : `${order.orderKey}_ASC` +export function toQueryOrderByInput(...orders: (SortOrder | 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 = (key: OrderKey) => { diff --git a/packages/ui/src/proposals/hooks/useProposals.ts b/packages/ui/src/proposals/hooks/useProposals.ts index 3961ecd630..5168d981bb 100644 --- a/packages/ui/src/proposals/hooks/useProposals.ts +++ b/packages/ui/src/proposals/hooks/useProposals.ts @@ -33,7 +33,10 @@ export const useProposals = ({ perPage = 10, fetchAll = false, }: UseProposalsProps): UseProposals => { - const orderBy = order ? toQueryOrderByInput(order) : ProposalOrderByInput.CreatedAtDesc + const orderBy = toQueryOrderByInput(order, { + orderKey: 'createdAt', + isDescending: order?.isDescending ?? false, + }) const where = useMemo(() => { const where: ProposalWhereInput = filters?.stage From c4449efdbf32c159ee283976f37dd6456e1047ce Mon Sep 17 00:00:00 2001 From: Theophile Sandoz Date: Thu, 29 Feb 2024 11:57:02 +0100 Subject: [PATCH 2/2] Fix types --- packages/ui/src/council/hooks/useMyPastVotes.ts | 2 +- packages/ui/src/council/hooks/usePastElections.ts | 2 +- packages/ui/src/forum/hooks/useForumCategoryThreads.ts | 2 +- packages/ui/src/forum/hooks/useMyThreads.ts | 2 +- .../ui/src/working-groups/hooks/usePastWorkersPagination.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/ui/src/council/hooks/useMyPastVotes.ts b/packages/ui/src/council/hooks/useMyPastVotes.ts index 229c60595d..9d576210f2 100644 --- a/packages/ui/src/council/hooks/useMyPastVotes.ts +++ b/packages/ui/src/council/hooks/useMyPastVotes.ts @@ -25,7 +25,7 @@ export const useMyPastVotes = ({ order, perPage = 5 }: UseMyPastVotesProps) => { const variables = { where, - orderBy: [toQueryOrderByInput(order)], + orderBy: toQueryOrderByInput(order), limit: perPage, offset, } diff --git a/packages/ui/src/council/hooks/usePastElections.ts b/packages/ui/src/council/hooks/usePastElections.ts index 1fe3d7dd42..b715858fb9 100644 --- a/packages/ui/src/council/hooks/usePastElections.ts +++ b/packages/ui/src/council/hooks/usePastElections.ts @@ -15,7 +15,7 @@ interface UsePastElectionsProps { export const usePastElections = ({ page = 1, order }: UsePastElectionsProps) => { const variables = { - orderBy: [toQueryOrderByInput(order)], + orderBy: toQueryOrderByInput(order), limit: ELECTION_PER_PAGE, offset: (page - 1) * ELECTION_PER_PAGE, } diff --git a/packages/ui/src/forum/hooks/useForumCategoryThreads.ts b/packages/ui/src/forum/hooks/useForumCategoryThreads.ts index 49ccb05bc9..ead00bc13c 100644 --- a/packages/ui/src/forum/hooks/useForumCategoryThreads.ts +++ b/packages/ui/src/forum/hooks/useForumCategoryThreads.ts @@ -35,7 +35,7 @@ export const useForumCategoryThreads = ( const { data: threadsData } = useGetForumThreadsQuery({ variables: { where: where(filters, categoryId, isArchive), - orderBy: [ForumThreadOrderByInput.IsStickyDesc, toQueryOrderByInput(options.order)], + orderBy: [ForumThreadOrderByInput.IsStickyDesc, ...toQueryOrderByInput(options.order)], ...(!pagination ? { limit: 30 } : { diff --git a/packages/ui/src/forum/hooks/useMyThreads.ts b/packages/ui/src/forum/hooks/useMyThreads.ts index 096d2d3754..28995f1df8 100644 --- a/packages/ui/src/forum/hooks/useMyThreads.ts +++ b/packages/ui/src/forum/hooks/useMyThreads.ts @@ -31,7 +31,7 @@ export const useMyThreads = ({ page, threadsPerPage = 5, order }: UseMyThreadsPr }, limit: threadsPerPage, offset: (page - 1) * threadsPerPage, - orderBy: [ForumThreadOrderByInput.IsStickyDesc, toQueryOrderByInput(order)], + orderBy: [ForumThreadOrderByInput.IsStickyDesc, ...toQueryOrderByInput(order)], } const { loading: loadingPosts, data: threadsData } = useGetForumThreadsQuery({ variables }) const { loading: loadingCount, data: countData } = useGetForumThreadsCountQuery({ diff --git a/packages/ui/src/working-groups/hooks/usePastWorkersPagination.ts b/packages/ui/src/working-groups/hooks/usePastWorkersPagination.ts index 8dcb9193b9..b2f17e338e 100644 --- a/packages/ui/src/working-groups/hooks/usePastWorkersPagination.ts +++ b/packages/ui/src/working-groups/hooks/usePastWorkersPagination.ts @@ -24,7 +24,7 @@ export const usePastWorkersPagination = ({ group: { id_eq: group_eq }, status_json: { isTypeOf_not: 'WorkerStatusActive' }, }, - orderBy: [toQueryOrderByInput(order)], + orderBy: toQueryOrderByInput(order), } const { loading: loadingCount, data: countData } = useGetWorkersCountQuery({ variables })