-
-
Notifications
You must be signed in to change notification settings - Fork 393
/
LegacyHistoryList.tsx
49 lines (42 loc) · 1.58 KB
/
LegacyHistoryList.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { Action } from '@standardnotes/snjs'
import { FunctionComponent, useState } from 'react'
import { useListKeyboardNavigation } from '@/Hooks/useListKeyboardNavigation'
import HistoryListItem from './HistoryListItem'
import { NoteHistoryController } from '@/Controllers/NoteHistory/NoteHistoryController'
type Props = {
legacyHistory: Action[] | undefined
noteHistoryController: NoteHistoryController
onSelectRevision: () => void
}
const LegacyHistoryList: FunctionComponent<Props> = ({ legacyHistory, noteHistoryController, onSelectRevision }) => {
const { selectLegacyRevision, selectedEntry } = noteHistoryController
const [listElement, setListElement] = useState<HTMLDivElement | null>(null)
useListKeyboardNavigation(listElement)
return (
<div
className={`flex h-full w-full flex-col focus:shadow-none ${
!legacyHistory?.length ? 'items-center justify-center' : ''
}`}
ref={setListElement}
>
{legacyHistory?.map((entry) => {
const selectedEntryUrl = (selectedEntry as Action)?.subactions?.[0].url
const url = entry.subactions?.[0].url
return (
<HistoryListItem
key={url}
isSelected={selectedEntryUrl === url}
onClick={() => {
void selectLegacyRevision(entry)
onSelectRevision()
}}
>
{entry.label}
</HistoryListItem>
)
})}
{!legacyHistory?.length && <div className="select-none text-sm text-passive-0">No legacy history found</div>}
</div>
)
}
export default LegacyHistoryList