From a9d3686ccc496044cfdee013ccfbece955793052 Mon Sep 17 00:00:00 2001 From: piotrruss Date: Sat, 21 Aug 2021 00:24:01 +0200 Subject: icon focus, notes update timestamp, loading note --- apps/Notes/Notes.module.scss | 10 ++-- apps/Notes/components/Actions.js | 2 - apps/Notes/components/Export.js | 47 ++++--------------- apps/Notes/components/List.js | 98 ++++++++++++++++++++------------------- apps/Notes/components/ListItem.js | 34 +++++--------- apps/Notes/components/NoteEdit.js | 17 ++----- apps/Notes/components/NoteView.js | 3 +- apps/Notes/components/Splash.js | 4 +- apps/Notes/helpers/export.js | 32 +++++++++++++ apps/Notes/helpers/noteActions.js | 1 + 10 files changed, 118 insertions(+), 130 deletions(-) create mode 100644 apps/Notes/helpers/export.js (limited to 'apps/Notes') diff --git a/apps/Notes/Notes.module.scss b/apps/Notes/Notes.module.scss index 2e3c68f..fba396a 100644 --- a/apps/Notes/Notes.module.scss +++ b/apps/Notes/Notes.module.scss @@ -29,7 +29,7 @@ min-width: 10em; white-space: nowrap; padding-bottom: .5em; - cursor: pointer; + // cursor: pointer; line-height: 1.1em; &:first-of-type { @@ -50,10 +50,12 @@ &:first-of-type { width: 99%; display: flex; - padding-right: 1em; + margin-right: 1em; + // display:inline-block; & > span:nth-child(1) { text-overflow: ellipsis; + overflow: hidden; flex-grow: 1; } @@ -73,7 +75,7 @@ &:hover { background: #eee; border-radius: .5em; - cursor: pointer; + // cursor: pointer; & > td:first-of-type > span:nth-child(n+2){ color: #666; @@ -216,7 +218,7 @@ label { display: inline-block; - cursor: pointer; + // cursor: pointer; } li { diff --git a/apps/Notes/components/Actions.js b/apps/Notes/components/Actions.js index 1f5d680..9591cfa 100644 --- a/apps/Notes/components/Actions.js +++ b/apps/Notes/components/Actions.js @@ -16,13 +16,11 @@ const Actions = ({ ) case 'addNote': return ( ) case 'editNote': return ( diff --git a/apps/Notes/components/Export.js b/apps/Notes/components/Export.js index f281d1a..7232632 100644 --- a/apps/Notes/components/Export.js +++ b/apps/Notes/components/Export.js @@ -1,45 +1,11 @@ import styles from '../Notes.module.scss' import React, {useState} from 'react' import useNotes from '../hooks/useNotes' -import fetchJson from 'lib/fetchJson' -import JSZip from 'jszip' -import saveFile from 'helpers/saveFile' -import filename from '../helpers/fileName' -// import {state, color, handleImport, handleChange} from '../helpers/import' +import {handleSelect, handleSelectAll, handleExport} from '../helpers/export' const Export = ({setAction}) => { const {notes} = useNotes() const [ids, setIds] = useState(notes.map(n => n.noteId)) - // const [files, setFiles] = useState() - // const [done, setDone] = useState([]) - - const handleSelect = id => { - ids.includes(id) - ? setIds(ids.filter(i => i !== id)) - : setIds([...ids, id]) - } - - const handleSelectAll = e => { - if (e.target.checked) { - setIds(notes.map(n => n.noteId)) - } else { - setIds([]) - } - } - - const handleExport = e => { - e.preventDefault() - const zip = new JSZip() - - Promise.all(ids.map(async id => { - const title = notes.find(n => n.noteId === id).title - const {content} = await fetchJson(`/api/note/${id}`) - zip.folder('notes').file(filename(title), content, {binary: true}) - })).then(() => { - zip.generateAsync({type:"blob"}) - .then(c => saveFile(c, 'notes.zip', 'application/zip')) - }) - } if (!notes) return null @@ -54,11 +20,16 @@ const Export = ({setAction}) => { className="window__button" type="submit" value="Export" - onClick={handleExport} + onClick={e => handleExport(e, ids, notes)} />

Notes to export:

- + handleSelectAll(e, notes, setIds)} + checked={notes.length === ids.length} + />
{notes.map(note => ( @@ -68,7 +39,7 @@ const Export = ({setAction}) => { name={note.noteId} value={note.noteId} checked={ids.includes(note.noteId)} - onChange={() => handleSelect(note.noteId)} + onChange={() => handleSelect(note.noteId, ids, setIds)} />