fix(revisions): Sort revisions by newest descending

Users probably expect the revision list to be sorted with the newest revision being the first one in the list.
This change sorts the revisions by their timestamp descending.

Signed-off-by: Erik Michelson <github@erik.michelson.eu>
This commit is contained in:
Erik Michelson 2022-08-14 22:25:57 +02:00
parent a064d57387
commit 761f112491

View file

@ -11,6 +11,7 @@ import { getAllRevisions } from '../../../../api/revisions'
import { useApplicationState } from '../../../../hooks/common/use-application-state'
import { ListGroup } from 'react-bootstrap'
import { AsyncLoadingBoundary } from '../../../common/async-loading-boundary'
import { DateTime } from 'luxon'
export interface RevisionListProps {
selectedRevisionId?: number
@ -38,14 +39,20 @@ export const RevisionList: React.FC<RevisionListProps> = ({ selectedRevisionId,
if (loading || !revisions) {
return null
}
return revisions.map((revisionListEntry) => (
<RevisionListEntry
active={selectedRevisionId === revisionListEntry.id}
onSelect={() => onRevisionSelect(revisionListEntry.id)}
revision={revisionListEntry}
key={revisionListEntry.id}
/>
))
return revisions
.sort((a, b) => {
const timestampA = DateTime.fromISO(a.createdAt).toSeconds()
const timestampB = DateTime.fromISO(b.createdAt).toSeconds()
return timestampB - timestampA
})
.map((revisionListEntry) => (
<RevisionListEntry
active={selectedRevisionId === revisionListEntry.id}
onSelect={() => onRevisionSelect(revisionListEntry.id)}
revision={revisionListEntry}
key={revisionListEntry.id}
/>
))
}, [loading, onRevisionSelect, revisions, selectedRevisionId])
return (