added edit settings feature with save/reset buttons

This commit is contained in:
uukelele-scratch 2025-03-20 18:48:04 +00:00
parent 3763fab3fe
commit 2b42f3f6b0
3 changed files with 18 additions and 1 deletions

View file

@ -3,7 +3,7 @@ import express from 'express';
import http from 'http';
import path from 'path';
import { fileURLToPath } from 'url';
import settings from '../../settings.js';
import settings, { updateSettings } from '../../settings.js';
// Module-level variables
let io;
@ -133,6 +133,10 @@ export function createMindServer(port = 8080) {
socket.on('get-settings', (callback) => {
callback(settings);
})
socket.on('update-settings', (newSettings) => {
updateSettings(newSettings);
})
});
server.listen(port, 'localhost', () => {

View file

@ -122,6 +122,10 @@
<input type="radio" name="mcChatBotMessages" value="false">No</input>
<h5>Publicly chat messages to other bots.</h5>
</div>
<div class="formOption" style="display:flex;">
<button class="green-btn add-btn" onclick="saveSettings()"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="24" fill="currentColor" class="bi bi-floppy" viewBox="0 0 16 16"><path d="M11 2H9v3h2z"/><path d="M1.5 0h11.586a1.5 1.5 0 0 1 1.06.44l1.415 1.414A1.5 1.5 0 0 1 16 2.914V14.5a1.5 1.5 0 0 1-1.5 1.5h-13A1.5 1.5 0 0 1 0 14.5v-13A1.5 1.5 0 0 1 1.5 0M1 1.5v13a.5.5 0 0 0 .5.5H2v-4.5A1.5 1.5 0 0 1 3.5 9h9a1.5 1.5 0 0 1 1.5 1.5V15h.5a.5.5 0 0 0 .5-.5V2.914a.5.5 0 0 0-.146-.353l-1.415-1.415A.5.5 0 0 0 13.086 1H13v4.5A1.5 1.5 0 0 1 11.5 7h-7A1.5 1.5 0 0 1 3 5.5V1H1.5a.5.5 0 0 0-.5.5m3 4a.5.5 0 0 0 .5.5h7a.5.5 0 0 0 .5-.5V1H4zM3 15h10v-4.5a.5.5 0 0 0-.5-.5h-9a.5.5 0 0 0-.5.5z"/></svg>Save</button>
<button class="red-btn add-btn" onclick="getSettings()"><svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" class="bi bi-x" viewBox="0 0 16 16"><path fill="white" d="M4.646 4.646a.5.5 0 0 1 .708 0L8 7.293l2.646-2.647a.5.5 0 0 1 .708.708L8.707 8l2.647 2.646a.5.5 0 0 1-.708.708L8 8.707l-2.646 2.647a.5.5 0 0 1-.708-.708L7.293 8 4.646 5.354a.5.5 0 0 1 0-.708"/></svg>Reset</button>
</div>
</div>
</div>
@ -191,6 +195,11 @@
})
}
function saveSettings() {
const newSettings = getNewSettings();
socket.emit('update-settings', newSettings);
}
function updateListItem(listId, listContent) {
document.getElementById(listId).innerHTML = "";
listContent.forEach(element => {

View file

@ -104,6 +104,10 @@ button:hover {
justify-content: space-between;
}
.add-btn svg {
margin-right: 5px;
}
.green-btn {
background: #4CAF50;
}