diff --git a/public/js/notes.js b/public/js/notes.js index aed986c..348c271 100644 --- a/public/js/notes.js +++ b/public/js/notes.js @@ -4,6 +4,7 @@ let notes = []; let editingId = null; let dragId = null; + let saving = false; function hdr() { const t = sessionStorage.getItem('authToken'); @@ -148,9 +149,11 @@ const rawTags = document.getElementById('notesTags').value.trim(); const tags = rawTags ? rawTags.split(',').map(t => t.trim()).filter(Boolean).slice(0, 10).join(', ') : ''; const color = document.getElementById('notesColor').value; - if (!title) { showToast('Укажите заголовок заметки', true); return; } + if (!title && !noteText) { showToast('Заполните текст заметки', true); return; } + if (saving) return; const payload = { title: title, note: noteText, tags: tags, color: color }; let res; + saving = true; try { if (editingId) { res = await fetch(API + '/api/notes/' + editingId, { method: 'PUT', headers: Object.assign({ 'Content-Type': 'application/json' }, hdr()), body: JSON.stringify(payload) }); @@ -158,9 +161,11 @@ res = await fetch(API + '/api/notes', { method: 'POST', headers: Object.assign({ 'Content-Type': 'application/json' }, hdr()), body: JSON.stringify(payload) }); } } catch (e) { + saving = false; showToast('Ошибка сети', true); return; } + saving = false; const data = await res.json().catch(function () { return {}; }); if (!res.ok) { showToast(data.error || 'Ошибка при сохранении', true); @@ -211,9 +216,14 @@ }); } document.addEventListener('keydown', function (e) { - if (e.key !== 'Escape') return; const m = document.getElementById('notesModal'); - if (m && m.classList.contains('open')) closeModal(); + const open = m && m.classList.contains('open'); + if (e.key === 'Enter' && (e.ctrlKey || e.metaKey) && open) { + e.preventDefault(); + saveNote(); + return; + } + if (e.key === 'Escape' && open) closeModal(); }); } diff --git a/public/notes.html b/public/notes.html index b1199bb..fe301e7 100644 --- a/public/notes.html +++ b/public/notes.html @@ -79,7 +79,7 @@
- +
diff --git a/server.js b/server.js index 6d79012..f5bd4ca 100644 --- a/server.js +++ b/server.js @@ -3312,7 +3312,7 @@ app.get('/api/notes', requireAuth, async (req, res) => { app.post('/api/notes', requireAuth, async (req, res) => { try { - const title = reqStr(req.body?.title, NOTE_TITLE_MAX); + const title = optStr(req.body?.title, NOTE_TITLE_MAX) || ''; const note = optStr(req.body?.note, NOTE_TEXT_MAX) || ''; let tags = ''; if (req.body?.tags !== undefined && req.body.tags !== null) { @@ -3379,7 +3379,7 @@ app.put('/api/notes/:id', requireAuth, async (req, res) => { const note = await findNote(req.user, id); if (!note) return res.status(404).json({ error: 'Not found' }); if (note.forbidden) return res.status(403).json({ error: 'Нет доступа' }); - const title = reqStr(req.body?.title, NOTE_TITLE_MAX); + const title = optStr(req.body?.title, NOTE_TITLE_MAX) || ''; const text = optStr(req.body?.note, NOTE_TEXT_MAX) || ''; let tags = ''; if (req.body?.tags !== undefined && req.body.tags !== null) {