fixes: tag assign stale body, board placeholder, plugin pending, bucket activate
- Context menu tag toggle reads fresh body from state.cards — was overwriting with stale snapshot, dropping existing tags (e.g. #done) - Board empty-state centered with flex (vertical + horizontal) - Plugin settings: batch toggles via Apply button, single reload instead of one reload per toggle - New bucket creation activates it directly on the board Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
3cca14a3c6
commit
002562b1d3
6 files changed
+105
-70
No files matched your search
@@ -1,13 +1,11 @@
|
||||
// ── Plugin Settings UI ──
|
||||
// Renders the list of installed plugins with on/off toggles in the
|
||||
// settings overlay. Disabled plugins are skipped at PHP render time;
|
||||
// toggling requires a reload to take effect (page must re-fetch the
|
||||
// new script/css/html tag set).
|
||||
// Toggles collect pending changes client-side and commit together via
|
||||
// the Apply button. Only reloads once all changes are committed.
|
||||
|
||||
import { $, esc, api } from './util.js';
|
||||
|
||||
let pluginsCache = null;
|
||||
let dirtyAfterToggle = false;
|
||||
let pending = new Map(); // name -> desired enabled state
|
||||
|
||||
async function fetchPlugins() {
|
||||
const res = await fetch('api/plugins');
|
||||
@@ -23,63 +21,86 @@ function render(list) {
|
||||
container.innerHTML = '<p class="text-xs text-t-dim italic">No plugins installed. Drop a plugin folder into <code>public/plugins/</code> to add one.</p>';
|
||||
return;
|
||||
}
|
||||
container.innerHTML = list.map(p => `
|
||||
<div class="flex items-start gap-3 px-3 py-2 border border-t-border bg-t-bg rounded-sm" data-plugin="${esc(p.name)}">
|
||||
container.innerHTML = list.map(p => {
|
||||
const effectiveEnabled = pending.has(p.name) ? pending.get(p.name) : p.enabled;
|
||||
const isPending = pending.has(p.name);
|
||||
return `
|
||||
<div class="flex items-start gap-3 px-3 py-2 border ${isPending ? 'border-t-accent' : 'border-t-border'} bg-t-bg rounded-sm" data-plugin="${esc(p.name)}">
|
||||
<div class="flex-1 min-w-0">
|
||||
<div class="flex items-center gap-2">
|
||||
<span class="font-pixel text-[11px] text-t-bright">${esc(p.name)}</span>
|
||||
<span class="font-pixel text-[9px] text-t-dim">v${esc(p.version || '?')}</span>
|
||||
${p.hasBackend ? '<span class="font-pixel text-[8px] px-1 py-0.5 border border-t-border text-t-muted uppercase">php</span>' : ''}
|
||||
${isPending ? `<span class="font-pixel text-[8px] px-1 py-0.5 text-t-accent border border-t-accent uppercase">${effectiveEnabled ? 'will enable' : 'will disable'}</span>` : ''}
|
||||
</div>
|
||||
${p.description ? `<div class="text-[10px] text-t-muted leading-snug mt-1">${esc(p.description)}</div>` : ''}
|
||||
</div>
|
||||
<label class="flex items-center cursor-pointer shrink-0 mt-0.5">
|
||||
<input type="checkbox" class="plugin-toggle accent-t-accent w-4 h-4" ${p.enabled ? 'checked' : ''} data-name="${esc(p.name)}">
|
||||
<input type="checkbox" class="plugin-toggle accent-t-accent w-4 h-4" ${effectiveEnabled ? 'checked' : ''} data-name="${esc(p.name)}" data-original="${p.enabled ? '1' : '0'}">
|
||||
</label>
|
||||
</div>
|
||||
`).join('');
|
||||
</div>`;
|
||||
}).join('');
|
||||
|
||||
container.querySelectorAll('.plugin-toggle').forEach(input => {
|
||||
input.addEventListener('change', onToggle);
|
||||
});
|
||||
|
||||
updateApplyBar();
|
||||
}
|
||||
|
||||
let reloadTimer = null;
|
||||
|
||||
async function onToggle(e) {
|
||||
function onToggle(e) {
|
||||
const input = e.currentTarget;
|
||||
const name = input.dataset.name;
|
||||
const enabled = input.checked;
|
||||
input.disabled = true;
|
||||
try {
|
||||
const res = await api('api/plugins/toggle', {
|
||||
method: 'POST',
|
||||
body: { name, enabled },
|
||||
});
|
||||
if (res.error) throw new Error(res.error);
|
||||
pluginsCache = res.plugins;
|
||||
dirtyAfterToggle = true;
|
||||
$('plugins-reload-notice')?.classList.remove('hidden');
|
||||
// Auto-reload so the effect of the toggle is visible immediately.
|
||||
// Debounced so rapid successive toggles only trigger one reload.
|
||||
if (reloadTimer) clearTimeout(reloadTimer);
|
||||
reloadTimer = setTimeout(() => location.reload(), 400);
|
||||
} catch (err) {
|
||||
// Revert UI on failure
|
||||
input.checked = !enabled;
|
||||
console.error('[plugins] toggle failed:', err);
|
||||
} finally {
|
||||
input.disabled = false;
|
||||
const original = input.dataset.original === '1';
|
||||
const desired = input.checked;
|
||||
if (desired === original) {
|
||||
pending.delete(name);
|
||||
} else {
|
||||
pending.set(name, desired);
|
||||
}
|
||||
render(pluginsCache); // re-render to update badge and border
|
||||
}
|
||||
|
||||
function updateApplyBar() {
|
||||
const bar = $('plugins-apply-bar');
|
||||
if (!bar) return;
|
||||
if (pending.size === 0) {
|
||||
bar.classList.add('hidden');
|
||||
return;
|
||||
}
|
||||
bar.classList.remove('hidden');
|
||||
const count = pending.size;
|
||||
const label = $('plugins-apply-count');
|
||||
if (label) label.textContent = `${count} pending change${count !== 1 ? 's' : ''}`;
|
||||
}
|
||||
|
||||
async function applyChanges() {
|
||||
if (pending.size === 0) return;
|
||||
const btn = $('plugins-apply-btn');
|
||||
if (btn) { btn.disabled = true; btn.textContent = 'applying...'; }
|
||||
try {
|
||||
for (const [name, enabled] of pending) {
|
||||
const res = await api('api/plugins/toggle', { method: 'POST', body: { name, enabled } });
|
||||
if (res.error) throw new Error(`${name}: ${res.error}`);
|
||||
}
|
||||
pending.clear();
|
||||
// Reload so the new plugin set takes effect
|
||||
location.reload();
|
||||
} catch (err) {
|
||||
if (btn) { btn.disabled = false; btn.textContent = 'Apply'; }
|
||||
alert('Failed to apply: ' + err.message);
|
||||
}
|
||||
}
|
||||
|
||||
function discardChanges() {
|
||||
pending.clear();
|
||||
render(pluginsCache);
|
||||
}
|
||||
|
||||
export async function openPluginSettings() {
|
||||
const container = $('plugins-list');
|
||||
if (!container) return;
|
||||
container.innerHTML = '<p class="text-xs text-t-dim italic">Loading...</p>';
|
||||
if (!dirtyAfterToggle) {
|
||||
$('plugins-reload-notice')?.classList.add('hidden');
|
||||
}
|
||||
try {
|
||||
const list = await fetchPlugins();
|
||||
render(list);
|
||||
@@ -88,9 +109,5 @@ export async function openPluginSettings() {
|
||||
}
|
||||
}
|
||||
|
||||
// Wire reload button once at module load
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
$('plugins-reload-btn')?.addEventListener('click', () => location.reload());
|
||||
}, { once: true });
|
||||
// In case DOMContentLoaded already fired (modules are deferred but safe to retry)
|
||||
$('plugins-reload-btn')?.addEventListener('click', () => location.reload());
|
||||
$('plugins-apply-btn')?.addEventListener('click', applyChanges);
|
||||
$('plugins-discard-btn')?.addEventListener('click', discardChanges);
|
||||
Reference in new issue
Block a user