Add 'Set as Activity' button to each activity entry in Web UI

Each activity in the mood lists now has a 🎯 Set button that immediately
sets it as the bot's current Discord activity (30-min manual override),
so users can pick from existing entries instead of typing manually.
This commit is contained in:
2026-04-27 23:43:18 +03:00
parent d6cdb89e42
commit 9d1ad7f783

View File

@@ -6918,17 +6918,21 @@ function activitiesRenderSection(section) {
function activitiesRenderView(section, mood, entries) {
let html = '';
for (const entry of entries) {
for (let i = 0; i < entries.length; i++) {
const entry = entries[i];
const icons = { listening: '🎵', playing: '🎮', watching: '📺', competing: '🏆', streaming: '🔴' };
const labels = { listening: 'Listening to', playing: 'Playing', watching: 'Watching', competing: 'Competing in', streaming: 'Streaming' };
const icon = icons[entry.type] || '🎮';
const label = labels[entry.type] || 'Playing';
// Encode entry data for the "Set as Activity" button
const entryData = encodeURIComponent(JSON.stringify({ type: entry.type, name: entry.name, state: entry.state || '', url: entry.url || '' }));
html += `<div class="act-entry">`;
html += `<span class="act-entry-icon">${icon}</span>`;
html += `<span style="flex:1;"><strong style="color:#61dafb; font-size:0.8rem;">${label}</strong> ${escapeHtml(entry.name)}`;
if (entry.state) html += ` <span style="color:#aaa; font-size:0.85rem;">— ${escapeHtml(entry.state)}</span>`;
html += `</span>`;
html += `<span style="color:#888; font-size:0.8rem;">weight: ${entry.weight}</span>`;
html += `<button onclick="activitySetFromEntry(this)" data-entry="${entryData}" style="background:#e67e22; font-size:0.75rem; padding:0.2rem 0.5rem; margin-left:0.3rem;" title="Set this as bot's current activity (30 min override)">🎯 Set</button>`;
html += `</div>`;
}
html += `<div class="act-toolbar">`;
@@ -7129,6 +7133,32 @@ async function activitySetManual() {
}
}
async function activitySetFromEntry(btnElement) {
const raw = btnElement.getAttribute('data-entry');
if (!raw) return;
let entry;
try { entry = JSON.parse(decodeURIComponent(raw)); } catch { return; }
const type = entry.type;
const name = entry.name;
const state = entry.state || null;
const url = entry.url || null;
if (!name) { showNotification('Activity name is empty', 'error'); return; }
if (type === 'streaming' && !url) { showNotification('Streaming requires a URL', 'error'); return; }
try {
const body = { type, name };
if (state) body.state = state;
if (url) body.url = url;
await apiCall('/activities/current', 'POST', body);
const icon = _activityTypeIcon(type);
showNotification(`${icon} Set activity: ${name}`, 'success');
await activityRefreshCurrent();
} catch (e) {
showNotification('Failed to set activity: ' + e.message, 'error');
}
}
async function activityClearManual() {
try {
await apiCall('/activities/current', 'DELETE');