diff options
Diffstat (limited to 'apps/Notes/components/List.js')
-rw-r--r-- | apps/Notes/components/List.js | 96 |
1 files changed, 50 insertions, 46 deletions
diff --git a/apps/Notes/components/List.js b/apps/Notes/components/List.js index 238e305..05d0711 100644 --- a/apps/Notes/components/List.js +++ b/apps/Notes/components/List.js @@ -1,24 +1,24 @@ import styles from '../styles/Notes.module.scss' -import React, {useState, useEffect} from 'react' +import React, { useState, useEffect } from 'react' import useUser from 'hooks/useUser' import useSettings from 'hooks/useSettings' import useNotes from '../hooks/useNotes' import useSort from '../hooks/useSort' import ListItem from './ListItem' import Actions from './Actions' -import {Splash} from 'components' +import { Splash } from 'components' const List = () => { const [fetchedNote, setFetchedNote] = useState() const [action, setAction] = useState('') const [loading, setLoading] = useState(false) const [showSort, setShowSort] = useState(false) - const {notes, error} = useNotes() + const { notes, error } = useNotes() const [sortedBy, sortBy, sortFn] = useSort(3) - const {t} = useSettings() - const {user} = useUser({ + const { t } = useSettings() + const { user } = useUser({ redirectToLogin: true, - redirectToVerify: true, + redirectToVerify: true }) useEffect(() => { @@ -32,33 +32,34 @@ const List = () => { } return ( - action === '' ? ( - <> - <div className='window__submenu'> - <div> - <div onClick={() => setAction('addNote')}>{t('notes_new')}</div> - <div className='mobile-only' onClick={() => {setShowSort(s => !s)}}>{t('sort')}</div> - <div onClick={() => setAction('importNotes')}>{t('import')}</div> - <div onClick={() => setAction('exportNotes')}>{t('export')}</div> + action === '' + ? ( + <> + <div className='window__submenu'> + <div> + <div onClick={() => setAction('addNote')}>{t('notes_new')}</div> + <div className='mobile-only' onClick={() => { setShowSort(s => !s) }}>{t('sort')}</div> + <div onClick={() => setAction('importNotes')}>{t('import')}</div> + <div onClick={() => setAction('exportNotes')}>{t('export')}</div> + </div> </div> - </div> - <div className='window__scroll'> - <table className={styles.notesList}> - <thead className={showSort ? styles.mobileSort : 'desktop-only'}> - <tr className="mobile-only"> - <th>{t('sort_by')}</th> - </tr> - <tr> - <th onClick={() => sortBy(1)}>{t('title')} {sortedBy(1)}</th> - <th onClick={() => sortBy(2)}>{t('created')} {sortedBy(2)}</th> - <th onClick={() => sortBy(3)}>{t('modified')} {sortedBy(3)}</th> - </tr> - <tr className='mobile-only'> - <td className='window__button' onClick={() => setShowSort(false)}>{t('close')}</td> - </tr> - </thead> - <tbody> - { + <div className='window__scroll'> + <table className={styles.notesList}> + <thead className={showSort ? styles.mobileSort : 'desktop-only'}> + <tr className='mobile-only'> + <th>{t('sort_by')}</th> + </tr> + <tr> + <th onClick={() => sortBy(1)}>{t('title')} {sortedBy(1)}</th> + <th onClick={() => sortBy(2)}>{t('created')} {sortedBy(2)}</th> + <th onClick={() => sortBy(3)}>{t('modified')} {sortedBy(3)}</th> + </tr> + <tr className='mobile-only'> + <td className='window__button' onClick={() => setShowSort(false)}>{t('close')}</td> + </tr> + </thead> + <tbody> + { notes.length > 0 ? (notes.sort(sortFn).map(note => ( <ListItem @@ -68,23 +69,26 @@ const List = () => { setFetchedNote={setFetchedNote} setLoading={setLoading} /> - ))) : ( + ))) + : ( <tr> <td>{t('notes_list_empty')}</td> </tr> - )} - </tbody> - </table> - </div> - </> - ) : ( - <Actions - action={action} - setAction={setAction} - fetchedNote={fetchedNote} - setFetchedNote={setFetchedNote} - /> - ) + ) +} + </tbody> + </table> + </div> + </> + ) + : ( + <Actions + action={action} + setAction={setAction} + fetchedNote={fetchedNote} + setFetchedNote={setFetchedNote} + /> + ) ) } |