From 7ed91c7e51cef9ab2904654bdd776b6a2c60540c Mon Sep 17 00:00:00 2001 From: Belle Date: Fri, 23 Aug 2024 17:08:02 +0800 Subject: [PATCH] fix voting api check --- pages/api/arcade/showcase/vote.js | 17 ++++++++++------- pages/arcade/showcase/vote.js | 12 +++++++++++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/pages/api/arcade/showcase/vote.js b/pages/api/arcade/showcase/vote.js index d48e8a49..78c66b42 100644 --- a/pages/api/arcade/showcase/vote.js +++ b/pages/api/arcade/showcase/vote.js @@ -22,7 +22,8 @@ export default async function handler(req, res) { ?.replace('Bearer ', '') .replace(/[^a-zA-Z0-9-]/g, '') - const { Overall, Technical, Creative } = req.body + console.log(req.body) + const { overall, technical, creative } = req.body const pointsDistribution = [5, 4, 3, 2, 1] @@ -37,6 +38,8 @@ export default async function handler(req, res) { const userID = users[0].id const userRecord = await usersTable.find(userID) + + console.log(userRecord) const voted = userRecord.fields.Voted if (voted) { @@ -45,8 +48,8 @@ export default async function handler(req, res) { let jobs = [] - for (let i = 0; i < Overall.length; i++) { - const project = Overall[i] + for (let i = 0; i < overall.length; i++) { + const project = overall[i] const points = pointsDistribution[i] jobs.push(addVote(project, points, userID, 'Overall')) @@ -56,8 +59,8 @@ export default async function handler(req, res) { jobs = [] - for (let i = 0; i < Technical.length; i++) { - const project = Technical[i] + for (let i = 0; i < technical.length; i++) { + const project = technical[i] const points = pointsDistribution[i] await addVote(project, points, userID, 'Technical') @@ -67,8 +70,8 @@ export default async function handler(req, res) { jobs = [] - for (let i = 0; i < Creative.length; i++) { - const project = Creative[i] + for (let i = 0; i < creative.length; i++) { + const project = creative[i] const points = pointsDistribution[i] await addVote(project, points, userID, 'Creative') diff --git a/pages/arcade/showcase/vote.js b/pages/arcade/showcase/vote.js index 3e9257cd..b356a892 100644 --- a/pages/arcade/showcase/vote.js +++ b/pages/arcade/showcase/vote.js @@ -219,7 +219,7 @@ const Vote = () => { const [openProject, setOpenProject] = useState([]) /* status variables */ - const [loadStatus, setLoadStatus] = useState('success') // change + const [loadStatus, setLoadStatus] = useState('loading') const [status, setStatus] = useState('loading') const [submitStatus, setSubmitStatus] = useState('loading') @@ -270,6 +270,7 @@ const Vote = () => { console.error(e) setLoadStatus('error') }) + setLoadStatus('loading') const data = await response.json() if (data.error) { setLoadStatus('error') @@ -609,6 +610,7 @@ const Vote = () => { }) const data = await response.json() + if (data.error) { console.error('Error submitting vote:', data.error) setSubmitStatus('error') @@ -677,6 +679,14 @@ const Vote = () => { ? 'Thanks for voting!' : 'Ran into an error sending your votes'} + + + {submitStatus == 'loading' ? 'It takes a while' : ''} +