blob: 54f66b5df078cba070e9b69e6111231af40ddc15 (
plain) (
blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
|
import styles from '../Notes.module.scss'
import React, {useState, useEffect} from 'react'
import useUser from 'lib/useUser'
import useNotes from '../hooks/useNotes'
import useSort from '../hooks/useSort'
import ListItem from './ListItem'
import Actions from './Actions'
import Splash from './Splash'
const List = () => {
const [fetchedNote, setFetchedNote] = useState()
const [action, setAction] = useState('')
const [loading, setLoading] = useState(false)
const {notes, error} = useNotes()
const [sortedBy, sortBy, sortFn] = useSort(3)
const {user} = useUser({
redirectToLogin: true,
redirectToVerify: true,
})
useEffect(() => {
setLoading(false)
}, [fetchedNote])
if (error) return <Splash type='connection' />
if (loading) return <Splash />
if (!user || !user.isLoggedIn || !user.isVerified || !notes || !sortFn) {
return <Splash />
}
return (
action === '' ? (
<>
<div className='window__submenu'>
<div onClick={() => setAction('addNote')}>New note</div>
<div onClick={() => setAction('importNotes')}>Import</div>
<div onClick={() => setAction('exportNotes')}>Export</div>
</div>
<table className={styles.notesList}>
<thead>
<tr>
<th onClick={() => sortBy(1)}>Title {sortedBy(1)}</th>
<th onClick={() => sortBy(2)}>Created {sortedBy(2)}</th>
<th onClick={() => sortBy(3)}>Modified {sortedBy(3)}</th>
</tr>
</thead>
<tbody>
{
notes.length > 0
? (notes.sort(sortFn).map(note => (
<ListItem
key={note._id}
note={note}
setAction={setAction}
setFetchedNote={setFetchedNote}
setLoading={setLoading}
/>
))) : (
<tr>
<td>Your notes list is empty.</td>
</tr>
)}
</tbody>
</table>
</>
) : (
<Actions
action={action}
setAction={setAction}
fetchedNote={fetchedNote}
setFetchedNote={setFetchedNote}
/>
)
)
}
export default List
|