From 58825b5bcd92524e3ddb4fb422138b44b8da18f8 Mon Sep 17 00:00:00 2001
From: Anthony Correa
Date: Mon, 20 May 2024 09:06:53 -0500
Subject: [PATCH 1/3] 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')
From 7e803cc8e374d75ea0366ecd0ff8df9a97f090b4 Mon Sep 17 00:00:00 2001
From: Anthony Correa
Date: Mon, 20 May 2024 09:07:54 -0500
Subject: [PATCH 2/3] fix for if availabilities aren't available
---
src/helpers/eventlineup.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/helpers/eventlineup.js b/src/helpers/eventlineup.js
index aabb973..d860827 100644
--- a/src/helpers/eventlineup.js
+++ b/src/helpers/eventlineup.js
@@ -108,7 +108,7 @@ exports.loadSlots = (options) =>{
players_without_lineup_entry.forEach(member =>{
const availability = availabilities.find(a=>a.memberId==member.id)
let initial_slotset
- if (availability.statusCode == 0 || availability.statusCode == null) {
+ if (availability?.statusCode == 0 || availability?.statusCode == null) {
initial_slotset =`lineup-out-${event.id}`
} else {
initial_slotset =`lineup-bench-${event.id}`
From af9fa3bd9b7571ed7a8d7dc0c13f66fef41b6765 Mon Sep 17 00:00:00 2001
From: Anthony Correa
Date: Mon, 20 May 2024 09:11:08 -0500
Subject: [PATCH 3/3] fix for if availabilities aren't available
---
src/helpers/eventlineup.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/helpers/eventlineup.js b/src/helpers/eventlineup.js
index d860827..8f4e381 100644
--- a/src/helpers/eventlineup.js
+++ b/src/helpers/eventlineup.js
@@ -106,7 +106,7 @@ exports.loadSlots = (options) =>{
member=>!event_lineup_entries.map(lue=>lue.memberId).includes(member.id) && !member.isNonPlayer
)
players_without_lineup_entry.forEach(member =>{
- const availability = availabilities.find(a=>a.memberId==member.id)
+ const availability = availabilities?.find(a=>a.memberId==member.id)
let initial_slotset
if (availability?.statusCode == 0 || availability?.statusCode == null) {
initial_slotset =`lineup-out-${event.id}`