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
50
51
|
import styles from '../styles/Notes.module.scss'
import React from 'react'
import {getNote, exportNote, removeNote} from '../helpers/noteActions.js'
import useSettings from 'hooks/useSettings'
import usePopup from 'hooks/usePopup'
import useNotes from '../hooks/useNotes'
import {faEdit, faDownload, faTrash } from '@fortawesome/free-solid-svg-icons'
import {FontAwesomeIcon} from '@fortawesome/react-fontawesome'
const datestring = date => {
const d = new Date(date);
return ("0" + d.getDate()).slice(-2) + "-" + ("0"+(d.getMonth()+1)).slice(-2) + "-" +
d.getFullYear() + " " + ("0" + d.getHours()).slice(-2) + ":" + ("0" + d.getMinutes()).slice(-2)
};
const ListItem = ({note, setAction, setFetchedNote, setLoading}) => {
const {t} = useSettings()
const {setPopup} = usePopup()
const {mutateNotes} = useNotes()
const handleNoteAction = async (a, note, e) => {
if (e) e.stopPropagation()
setLoading(true)
await getNote(note, setFetchedNote, t, setPopup, () => setAction(a))
}
return (
<tr
className={styles.listItem}
key={note._id}
onClick={() => handleNoteAction('showNote', note)}
>
<td>
<span>{`${note.title}`}</span>
<span onClick={e => handleNoteAction('editNote', note, e)}>
<FontAwesomeIcon icon={faEdit} />
</span>
<span onClick={e => {e.stopPropagation(); exportNote(note)}}>
<FontAwesomeIcon icon={faDownload} />
</span>
<span onClick={e => removeNote(e, note._id, mutateNotes, t, setPopup, setAction)}>
<FontAwesomeIcon icon={faTrash} />
</span>
</td>
<td>{datestring(note.created_at)}</td>
<td>{datestring(note.updated_at)}</td>
</tr>
)
}
export default ListItem
|