Add creating IMAP folders from the app
Bump version to 0.2.0 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
@@ -102,6 +102,58 @@ openMessage = function (id) {
|
||||
}
|
||||
};
|
||||
|
||||
let customFolders = [];
|
||||
|
||||
function renderCustomFolders() {
|
||||
const box = $('#custom-folders');
|
||||
if (!box) return;
|
||||
box.replaceChildren(...customFolders.map(folder => {
|
||||
const button = document.createElement('button');
|
||||
button.className = 'folder custom-folder';
|
||||
button.dataset.folder = folder.id;
|
||||
button.classList.toggle('active', activeFolder === folder.id);
|
||||
const glyph = document.createElement('span');
|
||||
glyph.className = 'nav-glyph';
|
||||
glyph.textContent = '▭';
|
||||
const label = document.createElement('span');
|
||||
label.textContent = folder.name;
|
||||
button.title = folder.path;
|
||||
button.append(glyph, label);
|
||||
button.addEventListener('click', () => {
|
||||
if ($('#filter-folder').value) { $('#filter-folder').value = ''; folderBeforeSearch = null; }
|
||||
activeFolder = folder.id;
|
||||
$$('.folder').forEach(item => item.classList.toggle('active', item === button));
|
||||
$('#sidebar-title').textContent = folder.name;
|
||||
$('#crumb-current').textContent = folder.name;
|
||||
mailPageOffset = 0;
|
||||
void syncMailbox(false, { offset: 0 });
|
||||
});
|
||||
return button;
|
||||
}));
|
||||
}
|
||||
|
||||
async function loadCustomFolders() {
|
||||
if (!connectedMailAccount || !window.daybreakMail?.listFolders) return;
|
||||
try {
|
||||
customFolders = (await window.daybreakMail.listFolders()).folders || [];
|
||||
renderCustomFolders();
|
||||
} catch {}
|
||||
}
|
||||
|
||||
async function createMailFolder() {
|
||||
if (!connectedMailAccount || !window.daybreakMail?.createFolder) { openMailAccount(); return; }
|
||||
const name = prompt('New mail folder name:')?.trim();
|
||||
if (!name) return;
|
||||
try {
|
||||
const result = await window.daybreakMail.createFolder(name);
|
||||
customFolders = result.folders || customFolders;
|
||||
renderCustomFolders();
|
||||
toast(`Folder “${result.folder?.name || name}” created`);
|
||||
} catch (error) {
|
||||
toast(error.message || 'Could not create the folder');
|
||||
}
|
||||
}
|
||||
|
||||
function updateAccountCard(account) {
|
||||
const card = $('#account-settings');
|
||||
if (!card) return;
|
||||
@@ -114,6 +166,7 @@ function updateAccountCard(account) {
|
||||
card.querySelector('.account-info span').textContent = email;
|
||||
card.title = `${displayName} <${email}>`;
|
||||
if (typeof renderLabels === 'function') renderLabels();
|
||||
void loadCustomFolders();
|
||||
card.querySelector('.online-dot').style.background = '#70ad7b';
|
||||
const profileButton = $('.top-avatar');
|
||||
if (profileButton) {
|
||||
@@ -499,6 +552,7 @@ if (window.daybreakMail) {
|
||||
});
|
||||
$('#settings-button').onclick = () => openPreferences();
|
||||
$('#refresh').onclick = () => syncMailbox(true);
|
||||
$('#add-folder').addEventListener('click', createMailFolder);
|
||||
$$('.folder').forEach(button => button.addEventListener('click', () => {
|
||||
if ($('#filter-folder').value) {
|
||||
$('#filter-folder').value = '';
|
||||
|
||||
Reference in New Issue
Block a user