From 355feb234bf93cd32da25437e3539178f309c0f5 Mon Sep 17 00:00:00 2001 From: dev Date: Thu, 8 Oct 2026 15:55:44 +0300 Subject: [PATCH] =?UTF-8?q?fix(notes):=20=D0=BD=D0=B5=D0=BE=D0=B1=D1=8F?= =?UTF-8?q?=D0=B7=D0=B0=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B9=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=B3=D0=BE=D0=BB=D0=BE=D0=B2=D0=BE=D0=BA,=20=D0=B7?= =?UTF-8?q?=D0=B0=D1=89=D0=B8=D1=82=D0=B0=20=D0=BE=D1=82=20=D0=B4=D0=B2?= =?UTF-8?q?=D0=BE=D0=B9=D0=BD=D0=BE=D0=B3=D0=BE=20=D1=81=D0=BE=D1=85=D1=80?= =?UTF-8?q?=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F,=20Ctrl+Enter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- public/js/notes.js | 16 +++++++++++++--- public/notes.html | 2 +- server.js | 4 ++-- 3 files changed, 16 insertions(+), 6 deletions(-) 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) {