import styles from '../styles/Notes.module.scss' import { useRouter } from 'next/router' 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 handleLogout from 'helpers/logout' const List = ({ logout }) => { const [fetchedNote, setFetchedNote] = useState() const [action, setAction] = useState('') const [loading, setLoading] = useState(false) const [showSort, setShowSort] = useState(false) const { notes, error } = useNotes() const [sortedBy, sortBy, sortFn] = useSort(3) const { t } = useSettings() const router = useRouter() const { user, mutateUser } = useUser({ redirectToLogin: true, redirectToVerify: true }) useEffect(() => { setLoading(false) }, [fetchedNote]) if (error) return if (loading) return if (!user || !user.isLoggedIn || !user.isVerified || !notes || !sortFn) { return } return ( action === '' ? ( <>
setAction('addNote')}>{t('notes_new')}
{ setShowSort(s => !s) }}>{t('sort')}
setAction('importNotes')}>{t('import')}
setAction('exportNotes')}>{t('export')}
{logout && (
handleLogout(e, router, mutateUser)}> {t('logout')}
)}
{ notes.length > 0 ? (notes.sort(sortFn).map(note => ( ))) : ( ) }
{t('sort_by')}
sortBy(1)}>{t('title')} {sortedBy(1)} sortBy(2)}>{t('created')} {sortedBy(2)} sortBy(3)}>{t('modified')} {sortedBy(3)}
setShowSort(false)}>{t('close')}
{t('notes_list_empty')}
) : ( ) ) } export default List