update single + small fixes

This commit is contained in:
cv
2021-04-27 13:46:16 +02:00
parent f8825ed7dc
commit 8834b9933d
4 changed files with 43 additions and 13 deletions
@@ -13,6 +13,8 @@ export default function EventBlock(props) {
const { data, selected, next, delay, index, eventsHandler } = props; const { data, selected, next, delay, index, eventsHandler } = props;
const [more, setMore] = useState(false); const [more, setMore] = useState(false);
// NOTE: cheating to add responsiveness
const [visible, setVisible] = useState(data.isPublic || false);
const updateValues = (field, value) => { const updateValues = (field, value) => {
// validate field // validate field
@@ -52,9 +54,10 @@ export default function EventBlock(props) {
updateValues('presenter', v); updateValues('presenter', v);
}; };
const handleVisibleToggle = (v) => { const handleVisibleToggle = () => {
// setVisible(previousState => !previousState); let viz = !data.isPublic || !visible;
updateValues('isPublic', !data.isPublic); setVisible(viz);
updateValues('isPublic', viz);
}; };
return ( return (
@@ -113,10 +116,7 @@ export default function EventBlock(props) {
</div> </div>
</div> </div>
<div className={style.actionOverlay}> <div className={style.actionOverlay}>
<VisibleIconBtn <VisibleIconBtn clickhandler={handleVisibleToggle} active={visible} />
clickhandler={handleVisibleToggle}
active={data.isPublic}
/>
<DeleteIconBtn clickhandler={deleteHandler} /> <DeleteIconBtn clickhandler={deleteHandler} />
<ActionButtons <ActionButtons
showAdd showAdd
@@ -33,6 +33,7 @@ export default function StageManager(props) {
}, },
}; };
console.log('debug', events)
return ( return (
<div className={style.container__gray}> <div className={style.container__gray}>
<NavLogo /> <NavLogo />
+23 -3
View File
@@ -373,9 +373,28 @@ class EventTimer extends Timer {
// Reload data if running // Reload data if running
let type = this._startedAt != null ? 'reload' : 'load'; let type = this._startedAt != null ? 'reload' : 'load';
this.loadEvent(eventIndex, type); 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 // Loads a given event
@@ -434,7 +453,7 @@ class EventTimer extends Timer {
if (eventIndex === 0) return; if (eventIndex === 0) return;
// iterate backwards to find it // iterate backwards to find it
for (let i = eventIndex - 1; i >= 0; i--) { for (let i = eventIndex; i >= 0; i--) {
if ( if (
this._eventList[i].type === 'event' && this._eventList[i].type === 'event' &&
this._eventList[i].isPublic this._eventList[i].isPublic
@@ -443,6 +462,7 @@ class EventTimer extends Timer {
this.titlesPublic.subtitleNow = this._eventList[i].subtitle; this.titlesPublic.subtitleNow = this._eventList[i].subtitle;
this.titlesPublic.presenterNow = this._eventList[i].presenter; this.titlesPublic.presenterNow = this._eventList[i].presenter;
this.selectedPublicEventId = this._eventList[i].id; this.selectedPublicEventId = this._eventList[i].id;
break;
} }
} }
} }
+12 -3
View File
@@ -45,6 +45,11 @@ function _updateTimers() {
global.timer.updateEventList(results); 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' // Create controller for GET request to '/events'
// Returns - // Returns -
exports.eventsGetAll = async (req, res) => { exports.eventsGetAll = async (req, res) => {
@@ -129,7 +134,9 @@ exports.eventsPut = async (req, res) => {
.find({ id: req.body.id }) .find({ id: req.body.id })
.assign({ ...req.body }) .assign({ ...req.body })
.write(); .write();
_updateTimers();
// update timer
_updateTimersSingle(req.body.id, req.body);
res.sendStatus(200); res.sendStatus(200);
} catch (error) { } catch (error) {
@@ -159,8 +166,7 @@ exports.eventsPatch = async (req, res) => {
.write(); .write();
// update timer // update timer
// TODO: update single values when possible _updateTimersSingle(req.body.id, req.body);
_updateTimers();
res.sendStatus(200); res.sendStatus(200);
} catch (error) { } catch (error) {
@@ -175,6 +181,7 @@ exports.eventsDelete = async (req, res) => {
if (!req.params.eventId) { if (!req.params.eventId) {
res.status(400).send(`No id found in request`); res.status(400).send(`No id found in request`);
return; return;
console.log('debug: No id found in request');
} }
try { try {
@@ -197,6 +204,8 @@ exports.eventsDelete = async (req, res) => {
res.sendStatus(201); res.sendStatus(201);
} catch (error) { } catch (error) {
console.log('debug:', error);
res.status(400).send(error); res.status(400).send(error);
} }
}; };