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.
This commit is contained in:
2024-05-20 09:06:53 -05:00
parent 03a9ac3aae
commit 58825b5bcd
2 changed files with 14 additions and 6 deletions

View File

@@ -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) => {

View File

@@ -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')