fix: session history (#1128)

This commit is contained in:
Aman Harwara
2022-06-21 16:56:33 +05:30
committed by GitHub
parent 0075fcd208
commit ee69102001
3 changed files with 7 additions and 5 deletions

View File

@@ -37,7 +37,7 @@ const SessionHistoryList: FunctionComponent<Props> = ({ noteHistoryController })
{group.entries.map((entry, index) => (
<HistoryListItem
key={index}
isSelected={selectedRevision?.payload.created_at === entry.payload.created_at}
isSelected={selectedRevision?.payload.updated_at === entry.payload.updated_at}
onClick={() => {
selectSessionRevision(entry)
}}

View File

@@ -17,15 +17,16 @@ export type ListGroup<EntryType extends RevisionEntry> = {
export type RemoteRevisionListGroup = ListGroup<RevisionListEntry>
export type SessionRevisionListGroup = ListGroup<NoteHistoryEntry>
export const formatDateAsMonthYearString = (date: Date) =>
date.toLocaleDateString(undefined, {
export const formatDateAsMonthYearString = (date: Date) => {
return date.toLocaleDateString(undefined, {
month: 'long',
year: 'numeric',
})
}
export const getGroupIndexForEntry = (entry: RevisionEntry, groups: ListGroup<RevisionEntry>[]) => {
const todayAsDate = new Date()
const entryDate = new Date((entry as RevisionListEntry).created_at ?? (entry as NoteHistoryEntry).payload.created_at)
const entryDate = new Date((entry as RevisionListEntry).created_at ?? (entry as NoteHistoryEntry).payload.updated_at)
const differenceBetweenDatesInDays = calculateDifferenceBetweenDatesInDays(todayAsDate, entryDate)
@@ -78,7 +79,7 @@ export const sortRevisionListIntoGroups = <EntryType extends RevisionEntry>(revi
} else {
addBeforeLastGroup({
title: formatDateAsMonthYearString(
new Date((entry as RevisionListEntry).created_at ?? (entry as NoteHistoryEntry).payload.created_at),
new Date((entry as RevisionListEntry).created_at ?? (entry as NoteHistoryEntry).payload.updated_at),
),
entries: [entry],
})

View File

@@ -174,6 +174,7 @@ export class NoteHistoryController {
this.clearSelection()
this.setSelectedEntry(entry)
this.setSelectedRevision(entry)
this.setContentState(RevisionContentState.Loaded)
}
private get flattenedRemoteHistory() {