diff --git a/src/Gateway.jsx b/src/Gateway.jsx index 6776447..62fd962 100644 --- a/src/Gateway.jsx +++ b/src/Gateway.jsx @@ -7,7 +7,8 @@ export default function Gateway() { } Gateway.loader = async function loader({ params }) { - const vote = await getDoc(doc(db, `/votes/${params.id}`)); + const { id } = params; + const vote = await getDoc(doc(db, `/votes/${id}`)); if (!vote.exists()) { new Response("Not Found", { status: 404, @@ -25,17 +26,17 @@ Gateway.loader = async function loader({ params }) { moment.unix(voteData.endTime.seconds).tz("Europe/Berlin") ) ) { - return redirect(`/r/${voteData.id}`); + return redirect(`/r/${id}`); } if ( berlinTime.isBefore( moment.unix(voteData.startTime.seconds).tz("Europe/Berlin") ) ) { - return redirect(`/s/${voteData.id}`); + return redirect(`/s/${id}`); } - if (localStorage.getItem(voteData.id)) { - return redirect(`/x/${voteData.id}`); + if (localStorage.getItem(id)) { + return redirect(`/x/${id}`); } - return redirect(`/v/${voteData.id}`); + return redirect(`/v/${id}`); }; diff --git a/src/admin/vote/Results.jsx b/src/admin/vote/Results.jsx index b6a6a92..febf015 100644 --- a/src/admin/vote/Results.jsx +++ b/src/admin/vote/Results.jsx @@ -503,7 +503,8 @@ export default function Results() { Results.loader = async function loader({ params }) { const { id } = params; - const vote = (await getDoc(doc(db, `/votes/${id}`))).data(); + const vote = await getDoc(doc(db, `/votes/${id}`)); + const voteData = { id: vote.id, ...vote.data() }; const options = ( await getDocs(collection(db, `/votes/${id}/options`)) ).docs.map((doc) => { @@ -523,7 +524,7 @@ Results.loader = async function loader({ params }) { }); return { - vote, + vote: voteData, options, results, choices,