-
Notifications
You must be signed in to change notification settings - Fork 1
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
Implement sorting in admin view #1217
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import { Application } from "src/types"; | ||
|
||
interface ApplicationComparator { | ||
compare(app1: Application, app2: Application): number; | ||
description: string; | ||
} | ||
|
||
const CreatedAtComparatorDesc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
const date1 = new Date(app1.created_at); | ||
const date2 = new Date(app2.created_at); | ||
return date1.getTime() - date2.getTime(); | ||
}, | ||
description: "Dato opprettet synkende", | ||
}; | ||
|
||
const CreatedAtComparatorAsc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
const date1 = new Date(app1.created_at); | ||
const date2 = new Date(app2.created_at); | ||
return date2.getTime() - date1.getTime(); | ||
}, | ||
description: "Dato opprettet stigende", | ||
}; | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I also kind of think I would prefer to have the field sorted on and the direction of the sort as separte options. Like having one seletor for what to sort by, and one for the direction of the sort. Just makes more sense to me. But it's not important, it can be changed later on if we want it:) |
||
const UpdatedAtComparatorAsc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
const date1 = new Date(app1.updated_at); | ||
const date2 = new Date(app2.updated_at); | ||
return date1.getTime() - date2.getTime(); | ||
}, | ||
description: "Dato oppdatert stigende", | ||
}; | ||
|
||
const UpdatedAtComparatorDesc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
const date1 = new Date(app1.updated_at); | ||
const date2 = new Date(app2.updated_at); | ||
return date2.getTime() - date1.getTime(); | ||
}, | ||
description: "Dato oppdatert synkende", | ||
}; | ||
|
||
const AlphabeticalComparatorAsc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
return app2.user.full_name.localeCompare(app1.user.full_name); | ||
}, | ||
description: "Alfabetisk stigende", | ||
}; | ||
|
||
const AlphabeticalComparatorDesc: ApplicationComparator = { | ||
compare: (app1, app2) => { | ||
return app1.user.full_name.localeCompare(app2.user.full_name); | ||
}, | ||
description: "Alfabetisk synkende", | ||
}; | ||
|
||
export type { ApplicationComparator }; | ||
export { | ||
CreatedAtComparatorDesc, | ||
CreatedAtComparatorAsc, | ||
UpdatedAtComparatorAsc, | ||
UpdatedAtComparatorDesc, | ||
AlphabeticalComparatorAsc, | ||
AlphabeticalComparatorDesc, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose this should be imported as a type but oh well