add saving draft to localStorage
This commit is contained in:
@@ -3,6 +3,10 @@ export const b = {
|
||||
}
|
||||
|
||||
export function enhance(_, __, el) {
|
||||
if (el === undefined) { // nothing to enhance but init still runs
|
||||
return;
|
||||
}
|
||||
|
||||
if (el.classList.contains('js-only')) {
|
||||
el.classList.remove('js-only');
|
||||
}
|
||||
|
||||
@@ -3,6 +3,14 @@ export const b = {
|
||||
init: 'babycodeEditorCharCountInit',
|
||||
}
|
||||
|
||||
const getThreadId = () => {
|
||||
const scheme = window.location.pathname.split("/");
|
||||
if (scheme[1] !== 'threads' || scheme[2] === 'new') {
|
||||
return -1;
|
||||
}
|
||||
return parseInt(scheme[2]);
|
||||
}
|
||||
|
||||
export function setTab(_, sender, el) {
|
||||
if (sender.ariaSelected === 'true') {
|
||||
return;
|
||||
@@ -95,10 +103,24 @@ export function babycodeEditorCharCount(evOrPayload, sender, el) {
|
||||
const maxLength = sender.maxLength;
|
||||
const currentLength = sender.value.length;
|
||||
|
||||
el.innerText = `${currentLength}/${maxLength}`
|
||||
el.innerText = `${currentLength}/${maxLength}`;
|
||||
|
||||
const threadId = getThreadId();
|
||||
|
||||
if (threadId !== -1) {
|
||||
localStorage.setItem(`thread-${threadId}`, sender.value);
|
||||
}
|
||||
}
|
||||
|
||||
export function babycodeEditorCharCountInit(_, __, el) {
|
||||
if (el === undefined) { // no editors on page
|
||||
return;
|
||||
}
|
||||
|
||||
const threadId = getThreadId();
|
||||
if (threadId !== -1) {
|
||||
el.value = localStorage.getItem(`thread-${threadId}`);
|
||||
}
|
||||
b.send({ sender: el }, 'babycodeEditorCharCount');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user