From 18fde39f20cdba320ad1de113312e1623264b340 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Mon, 23 Jan 2023 09:53:38 -0500 Subject: [PATCH] feat: closes #11182, save qr text --- public/src/modules/quickreply.js | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/public/src/modules/quickreply.js b/public/src/modules/quickreply.js index edfe12629a..e2e569e2b4 100644 --- a/public/src/modules/quickreply.js +++ b/public/src/modules/quickreply.js @@ -2,15 +2,16 @@ define('quickreply', [ 'components', 'composer', 'composer/autocomplete', 'api', - 'alerts', 'uploadHelpers', 'mousetrap', + 'alerts', 'uploadHelpers', 'mousetrap', 'storage', ], function ( components, composer, autocomplete, api, - alerts, uploadHelpers, mousetrap + alerts, uploadHelpers, mousetrap, storage ) { const QuickReply = {}; QuickReply.init = function () { const element = components.get('topic/quickreply/text'); + const qrDraftId = `qr:draft:tid:${ajaxify.data.tid}`; const data = { element: element, strategies: [], @@ -52,8 +53,8 @@ define('quickreply', [ return; } - var replyMsg = components.get('topic/quickreply/text').val(); - var replyData = { + const replyMsg = components.get('topic/quickreply/text').val(); + const replyData = { tid: ajaxify.data.tid, handle: undefined, content: replyMsg, @@ -84,13 +85,28 @@ define('quickreply', [ } components.get('topic/quickreply/text').val(''); + storage.removeItem(qrDraftId); autocomplete._active.core_qr.hide(); }); }); + const draft = storage.getItem(qrDraftId); + if (draft) { + element.val(draft); + } + + element.on('keyup', utils.debounce(function () { + const text = element.val(); + if (text) { + storage.setItem(qrDraftId, text); + } else { + storage.removeItem(qrDraftId); + } + }, 1000)); + components.get('topic/quickreply/expand').on('click', (e) => { e.preventDefault(); - + storage.removeItem(qrDraftId); const textEl = components.get('topic/quickreply/text'); composer.newReply({ tid: ajaxify.data.tid,