Skip to content

Commit

Permalink
chore(boards): sort on multiple fields for organization
Browse files Browse the repository at this point in the history
  • Loading branch information
emilielr committed Jun 14, 2024
1 parent 8bfc006 commit 5855372
Showing 1 changed file with 25 additions and 7 deletions.
32 changes: 25 additions & 7 deletions next-tavla/app/(admin)/boards/hooks/useSortBoardFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,17 @@ function useSortBoardFunction() {
column: sortParams?.[0] as TBoardsColumn,
type: sortParams?.[1] as TSort,
}

const compareTitle = () => {
const titleA =
boardA?.board.meta?.title?.toLowerCase() ??
DEFAULT_BOARD_NAME
const titleB =
boardB?.board.meta?.title?.toLowerCase() ??
DEFAULT_BOARD_NAME
return titleB.localeCompare(titleA)
}

switch (sort.column) {
case 'lastModified':
sortFunc = () => {
Expand All @@ -24,16 +35,23 @@ function useSortBoardFunction() {
}
break
case 'organization':
sortFunc = () => {
const orgNameA =
boardA.organization?.name?.toLowerCase() ?? 'Privat'
const orgNameB =
boardB.organization?.name?.toLowerCase() ?? 'Privat'

if (orgNameA == orgNameB) {
return sort.type == 'ascending'
? compareTitle()
: -compareTitle()
}
return orgNameB.localeCompare(orgNameA)
}
break
default:
sortFunc = () => {
const titleA =
boardA?.board.meta?.title?.toLowerCase() ??
DEFAULT_BOARD_NAME
const titleB =
boardB?.board.meta?.title?.toLowerCase() ??
DEFAULT_BOARD_NAME
return titleB.localeCompare(titleA)
return compareTitle()
}
break
}
Expand Down

0 comments on commit 5855372

Please sign in to comment.