Skip to content

Commit

Permalink
Fix Results component to handle optional chaining and improve vote da…
Browse files Browse the repository at this point in the history
…ta retrieval logging
  • Loading branch information
JohanGrims committed Dec 16, 2024
1 parent 1df48e9 commit 765f780
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/admin/vote/Results.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,9 @@ export default function Results() {
<td>
{
options.find((option) => option.id === result.result)
.title
?.title
}
{result.result}
</td>
</tr>
))}
Expand Down Expand Up @@ -252,7 +253,7 @@ export default function Results() {
<td>
{
options.find((option) => option.id === result.result)
.title
?.title
}
</td>
</tr>
Expand Down Expand Up @@ -501,15 +502,18 @@ export default function Results() {
);
}

Results.loader = async function loader({ params }) {
Results.loader = async function loader({ params }) {
const { id } = params;
console.log(id);
const vote = await getDoc(doc(db, `/votes/${id}`));
const voteData = { id: vote.id, ...vote.data() };
const voteData = { id, ...vote.data() };
console.log(voteData);
const options = (
await getDocs(collection(db, `/votes/${id}/options`))
).docs.map((doc) => {
return { id, ...doc.data() };
return { id: doc.id, ...doc.data() };
});
console.log(options);

const results = (
await getDocs(collection(db, `/votes/${id}/results`))
Expand All @@ -529,4 +533,4 @@ Results.loader = async function loader({ params }) {
results,
choices,
};
}
};

0 comments on commit 765f780

Please sign in to comment.