Make user input saving account-specific

This commit is contained in:
Cohee
2025-02-12 11:21:13 +02:00
parent 5085f6cdc9
commit 340c03cedf
2 changed files with 13 additions and 2 deletions

View File

@ -41,6 +41,7 @@ import { debounce_timeout } from './constants.js';
import { Popup } from './popup.js';
import { accountStorage } from './util/AccountStorage.js';
import { getCurrentUserHandle } from './user.js';
var RPanelPin = document.getElementById('rm_button_panel_pin');
var LPanelPin = document.getElementById('lm_button_panel_pin');
@ -428,13 +429,15 @@ function OpenNavPanels() {
}
}
const getUserInputKey = () => getCurrentUserHandle() + '_userInput';
function restoreUserInput() {
if (!power_user.restore_user_input) {
console.debug('restoreUserInput disabled');
return;
}
const userInput = localStorage.getItem('userInput');
const userInput = localStorage.getItem(getUserInputKey());
if (userInput) {
$('#send_textarea').val(userInput)[0].dispatchEvent(new Event('input', { bubbles: true }));
}
@ -442,7 +445,7 @@ function restoreUserInput() {
function saveUserInput() {
const userInput = String($('#send_textarea').val());
localStorage.setItem('userInput', userInput);
localStorage.setItem(getUserInputKey(), userInput);
console.debug('User Input -- ', userInput);
}
const saveUserInputDebounced = debounce(saveUserInput);

View File

@ -43,6 +43,14 @@ export function isAdmin() {
return Boolean(currentUser.admin);
}
/**
* Gets the handle string of the current user.
* @returns {string} User handle
*/
export function getCurrentUserHandle() {
return currentUser?.handle || 'default-user';
}
/**
* Get the current user.
* @returns {Promise<void>}