mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-26 03:33:58 -05:00
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:
parent
a064d57387
commit
761f112491
1 changed files with 15 additions and 8 deletions
|
@ -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 (
|
||||
|
|
Loading…
Reference in a new issue