Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🧮 Sort proposals by creation date second to the user define order #4793

Merged
merged 2 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 1 addition & 1 deletion packages/ui/src/council/hooks/useMyPastVotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const useMyPastVotes = ({ order, perPage = 5 }: UseMyPastVotesProps) => {

const variables = {
where,
orderBy: [toQueryOrderByInput<CastVoteOrderByInput>(order)],
orderBy: toQueryOrderByInput<CastVoteOrderByInput>(order),
limit: perPage,
offset,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/council/hooks/usePastElections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ interface UsePastElectionsProps {

export const usePastElections = ({ page = 1, order }: UsePastElectionsProps) => {
const variables = {
orderBy: [toQueryOrderByInput<ElectionRoundOrderByInput>(order)],
orderBy: toQueryOrderByInput<ElectionRoundOrderByInput>(order),
limit: ELECTION_PER_PAGE,
offset: (page - 1) * ELECTION_PER_PAGE,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/forum/hooks/useForumCategoryThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useForumCategoryThreads = (
const { data: threadsData } = useGetForumThreadsQuery({
variables: {
where: where(filters, categoryId, isArchive),
orderBy: [ForumThreadOrderByInput.IsStickyDesc, toQueryOrderByInput<ForumThreadOrderByInput>(options.order)],
orderBy: [ForumThreadOrderByInput.IsStickyDesc, ...toQueryOrderByInput<ForumThreadOrderByInput>(options.order)],
...(!pagination
? { limit: 30 }
: {
Expand Down
2 changes: 1 addition & 1 deletion packages/ui/src/forum/hooks/useMyThreads.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const useMyThreads = ({ page, threadsPerPage = 5, order }: UseMyThreadsPr
},
limit: threadsPerPage,
offset: (page - 1) * threadsPerPage,
orderBy: [ForumThreadOrderByInput.IsStickyDesc, toQueryOrderByInput<ForumThreadOrderByInput>(order)],
orderBy: [ForumThreadOrderByInput.IsStickyDesc, ...toQueryOrderByInput<ForumThreadOrderByInput>(order)],
}
const { loading: loadingPosts, data: threadsData } = useGetForumThreadsQuery({ variables })
const { loading: loadingCount, data: countData } = useGetForumThreadsCountQuery({
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const usePastWorkersPagination = ({
group: { id_eq: group_eq },
status_json: { isTypeOf_not: 'WorkerStatusActive' },
},
orderBy: [toQueryOrderByInput<WorkerOrderByInput>(order)],
orderBy: toQueryOrderByInput<WorkerOrderByInput>(order),
}

const { loading: loadingCount, data: countData } = useGetWorkersCountQuery({ variables })
Expand Down
Loading