From 58825b5bcd92524e3ddb4fb422138b44b8da18f8 Mon Sep 17 00:00:00 2001 From: Anthony Correa Date: Mon, 20 May 2024 09:06:53 -0500 Subject: [PATCH] reloads the page on lineup save realized that the duplicates come from saving the lineup more than once. this occurs when initially no one has an eventlineupentry, it gets one on save, but the front end is not updated on save, so it keeps creating entrires on save. simple fix is to refresh the page on save. "better" solution would be to have the front end update on save, but that's longer to implement. i started this by having `postEventLineup` return the newly fetched lineupentries. --- src/controllers/eventlineup.js | 16 +++++++++++----- src/public/js/eventlineup.js | 4 +++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/controllers/eventlineup.js b/src/controllers/eventlineup.js index b87a411..071857f 100644 --- a/src/controllers/eventlineup.js +++ b/src/controllers/eventlineup.js @@ -1,6 +1,6 @@ const path = require('path') const fs = require('fs') -const {embeddedSvgFromPath, parsePositionLabel, compilePositionLabel} = require("../lib/utils") +const {groupTeamsnapItems, parsePositionLabel, compilePositionLabel, teamsnapCallback} = require("../lib/utils") const tsUtils = require('../lib/utils') const { loadEventLineupEntries } = require('teamsnap.js') @@ -105,14 +105,20 @@ exports.postEventLineup = async (req,res) => { const eventLineupEntries = req.event_lineup.eventLineupEntries const {newEventLineupEntries, deleteEventLineupEntries} = processPostedEventLineupEntries(body, eventLineupEntries, req.event_lineup) newEventLineupEntries.forEach(e=>{ - teamsnap.saveEventLineupEntry(e) + teamsnap.saveEventLineupEntry(e, teamsnapCallback) }) deleteEventLineupEntries.forEach(e=>{ - teamsnap.deleteEventLineupEntry(e) + teamsnap.deleteEventLineupEntry(e, teamsnapCallback) }) - eventLineup = await teamsnap.loadEventLineups(req.params.event_id) - res.status(201).end() + const bulk_items = await teamsnap.bulkLoad( + {teamId: req.params.team_id, types: ['eventLineup', 'eventLineupEntry'], scopeTo:'event', event__id:req.params.event_id,}, + null, + (err, items) => {teamsnapCallback(err, items, {req, source:"postEventLineup", method:'bulkLoad'})} + ) + groupedReturnedItems = groupTeamsnapItems(bulk_items) + returnedEventLineupEntries = groupedReturnedItems.eventLineupEntries + res.status(201).end(JSON.stringify(returnedEventLineupEntries)) } const processPostedEventLineupEntries = (body, eventLineupEntries, eventLineup) => { diff --git a/src/public/js/eventlineup.js b/src/public/js/eventlineup.js index 08f7b0f..0b6bb30 100644 --- a/src/public/js/eventlineup.js +++ b/src/public/js/eventlineup.js @@ -324,6 +324,7 @@ async function onSubmit(form, event) { event.submitter.blur() waiting_icon.classList.add("u-hidden"); success_icon.classList.remove("u-hidden"); + console.log(text); // success_icon.querySelector("span.message").innerHTML = text; }) .catch((error) => { @@ -332,7 +333,8 @@ async function onSubmit(form, event) { failure_icon.classList.remove("u-hidden"); console.log(error); // success_icon.querySelector("span.message").innerHTML = error; - }); + }) + .finally(()=>{location.reload()});//refresh page setTimeout(() => { [waiting_icon, success_icon, failure_icon].forEach(e=>e.classList.add('u-hidden')) teamsnap_icon.classList.remove('u-hidden')