Keep email list mounted between opens

This commit is contained in:
pewdiepie-archdaemon
2026-06-01 13:17:58 +09:00
parent 24f73bf539
commit b8fefe1a82

View File

@@ -449,12 +449,27 @@ export function initEmailLibrary(config) {
export function isOpen() { return state._libOpen; }
export function openEmailLibrary(opts = {}) {
// Force-clean any stale state from previous attempts
const existing = document.getElementById('email-lib-modal');
if (existing) existing.remove();
if (state._libEscHandler) {
document.removeEventListener('keydown', state._libEscHandler);
state._libEscHandler = null;
if (existing) {
existing.classList.remove('hidden');
existing.style.display = 'block';
state._libOpen = true;
if (window.innerWidth <= 768) {
document.getElementById('sidebar')?.classList.add('hidden');
document.getElementById('sidebar-backdrop')?.classList.remove('visible');
}
document.body.classList.add('email-front');
if (Object.prototype.hasOwnProperty.call(opts, 'account_id')) {
state._libAccountId = opts.account_id || null;
_publishActiveAccount();
}
if (opts.folder) state._libFolder = opts.folder;
state._libPendingExpandUid = opts.uid || null;
_loadAccounts();
_loadFolders();
_loadEmailReminderBellVisibility();
_loadEmails({ preserveCurrent: true });
return;
}
state._libOpen = true;
// On mobile the sidebar overlays content — close it so the email view isn't
@@ -958,6 +973,8 @@ export function openEmailLibrary(opts = {}) {
// ESC to close + Arrow nav + Delete on the selected / currently-expanded email.
state._libEscHandler = (e) => {
const modal = document.getElementById('email-lib-modal');
if (!modal || modal.classList.contains('hidden')) return;
if (e.key === 'Escape') {
if (state._selectMode) {
e.preventDefault();
@@ -1044,12 +1061,8 @@ function _renderAccountsStrip() {
export function closeEmailLibrary() {
const modal = document.getElementById('email-lib-modal');
if (modal) modal.remove();
if (modal) modal.classList.add('hidden');
_clearEmailDocumentSplit();
if (state._libEscHandler) {
document.removeEventListener('keydown', state._libEscHandler);
state._libEscHandler = null;
}
state._libOpen = false;
// If the /email route collapsed the wide sidebar to make room for
// the fullscreen modal, re-expand it now that the modal is gone.
@@ -1294,7 +1307,7 @@ async function _refreshUnreadBadge() {
} catch (_) { _syncUnreadTabBadge(0); }
}
async function _loadEmails({ force = false } = {}) {
async function _loadEmails({ force = false, preserveCurrent = false } = {}) {
const seq = ++_libLoadSeq;
state._libLoading = true;
const accountAtStart = state._libAccountId || '';
@@ -1336,6 +1349,8 @@ async function _loadEmails({ force = false } = {}) {
_renderGrid();
const stats = document.getElementById('email-lib-stats');
if (stats) stats.textContent = `${state._libTotal} emails`;
} else if (preserveCurrent && state._libEmails.length) {
sp = null;
} else {
grid.innerHTML = '';
sp = spinnerModule.createWhirlpool(28);