diff --git a/client/src/features/editors/list/EventBlock.jsx b/client/src/features/editors/list/EventBlock.jsx index 872005e0f..dc16ad949 100644 --- a/client/src/features/editors/list/EventBlock.jsx +++ b/client/src/features/editors/list/EventBlock.jsx @@ -13,6 +13,8 @@ export default function EventBlock(props) { const { data, selected, next, delay, index, eventsHandler } = props; const [more, setMore] = useState(false); + // NOTE: cheating to add responsiveness + const [visible, setVisible] = useState(data.isPublic || false); const updateValues = (field, value) => { // validate field @@ -52,9 +54,10 @@ export default function EventBlock(props) { updateValues('presenter', v); }; - const handleVisibleToggle = (v) => { - // setVisible(previousState => !previousState); - updateValues('isPublic', !data.isPublic); + const handleVisibleToggle = () => { + let viz = !data.isPublic || !visible; + setVisible(viz); + updateValues('isPublic', viz); }; return ( @@ -113,10 +116,7 @@ export default function EventBlock(props) {
- + diff --git a/server/classes/EventTimer.js b/server/classes/EventTimer.js index 975b751bc..623ae96d5 100644 --- a/server/classes/EventTimer.js +++ b/server/classes/EventTimer.js @@ -373,9 +373,28 @@ class EventTimer extends Timer { // Reload data if running let type = this._startedAt != null ? 'reload' : 'load'; this.loadEvent(eventIndex, type); - - this.broadcastState(); } + this.broadcastState(); + } + + updateSingleEvent(id, entry) { + // find object in events + const eventIndex = this._eventList.findIndex((e) => e.id === id); + if (eventIndex === -1) return; + + // update events + const e = this._eventList[eventIndex]; + this._eventList[eventIndex] = { ...e, ...entry }; + + // handle reload selected + // Reload data if running + let type = + this.selectedEventId === id && this._startedAt != null + ? 'reload' + : 'load'; + this.loadEvent(this.selectedEvent, type); + + this.broadcastState(); } // Loads a given event @@ -434,7 +453,7 @@ class EventTimer extends Timer { if (eventIndex === 0) return; // iterate backwards to find it - for (let i = eventIndex - 1; i >= 0; i--) { + for (let i = eventIndex; i >= 0; i--) { if ( this._eventList[i].type === 'event' && this._eventList[i].isPublic @@ -443,6 +462,7 @@ class EventTimer extends Timer { this.titlesPublic.subtitleNow = this._eventList[i].subtitle; this.titlesPublic.presenterNow = this._eventList[i].presenter; this.selectedPublicEventId = this._eventList[i].id; + break; } } } diff --git a/server/controllers/eventsController.js b/server/controllers/eventsController.js index 2d702be73..8d009a444 100644 --- a/server/controllers/eventsController.js +++ b/server/controllers/eventsController.js @@ -45,6 +45,11 @@ function _updateTimers() { global.timer.updateEventList(results); } +// Updates timer object single event +function _updateTimersSingle(id, entry) { + global.timer.updateSingleEvent(id, entry); +} + // Create controller for GET request to '/events' // Returns - exports.eventsGetAll = async (req, res) => { @@ -129,7 +134,9 @@ exports.eventsPut = async (req, res) => { .find({ id: req.body.id }) .assign({ ...req.body }) .write(); - _updateTimers(); + + // update timer + _updateTimersSingle(req.body.id, req.body); res.sendStatus(200); } catch (error) { @@ -159,8 +166,7 @@ exports.eventsPatch = async (req, res) => { .write(); // update timer - // TODO: update single values when possible - _updateTimers(); + _updateTimersSingle(req.body.id, req.body); res.sendStatus(200); } catch (error) { @@ -175,6 +181,7 @@ exports.eventsDelete = async (req, res) => { if (!req.params.eventId) { res.status(400).send(`No id found in request`); return; + console.log('debug: No id found in request'); } try { @@ -197,6 +204,8 @@ exports.eventsDelete = async (req, res) => { res.sendStatus(201); } catch (error) { + console.log('debug:', error); + res.status(400).send(error); } };