Skip to content

Commit

Permalink
Filter questions for the right local authority
Browse files Browse the repository at this point in the history
  • Loading branch information
tewson committed Mar 19, 2024
1 parent b6bb57c commit fbed68c
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 50 deletions.
53 changes: 28 additions & 25 deletions src/pages/areas/[localAuthority]/[area].astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,12 @@ export async function getStaticPaths() {
})
.all();
const questions = await airtableClient("Questions")
const questionRecords = await airtableClient("Questions")
.select({
view: "Grid view",
})
.all();
const questionsList = questions.map((record) =>
getStringFieldValue(record, "Text")
);
const answers = await airtableClient("Answers")
.select({
view: "Grid view",
Expand Down Expand Up @@ -64,27 +60,34 @@ export async function getStaticPaths() {
};
}, {});
const questions = questionsList.map((question, index) => {
return {
text: question,
answers: candidatesAnswersForArea.map((answerRecord) => {
const candidateFullName = getLookupFieldValue(
answerRecord,
"Candidate full name"
);
const answer =
answersListByCandidate[candidateFullName][index] &&
getStringFieldValue(
answersListByCandidate[candidateFullName][index],
"Text"
const questions = questionRecords
.filter(
(questionRecord) =>
getLookupFieldValue(questionRecord, "Local authority name") ===
getLookupFieldValue(electoralAreaRecord, "Local Authority Name")
)
.map((questionRecord) => getStringFieldValue(questionRecord, "Text"))
.map((question, index) => {
return {
text: question,
answers: candidatesAnswersForArea.map((answerRecord) => {
const candidateFullName = getLookupFieldValue(
answerRecord,
"Candidate full name"
);
return {
candidateFullName,
answer,
};
}),
};
});
const answer =
answersListByCandidate[candidateFullName][index] &&
getStringFieldValue(
answersListByCandidate[candidateFullName][index],
"Text"
);
return {
candidateFullName,
answer,
};
}),
};
});
const hasAnswers = questions.some((question) =>
question.answers.some((answer) => Boolean(answer.answer))
Expand Down
53 changes: 28 additions & 25 deletions src/pages/candidates/[candidate].astro
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,12 @@ export async function getStaticPaths() {
})
.all();
const questions = await airtableClient("Questions")
const questionRecords = await airtableClient("Questions")
.select({
view: "Grid view",
})
.all();
const questionsList = questions.map((record) =>
getStringFieldValue(record, "Text")
);
const candidatesAnswers = await airtableClient("Answers")
.select({
view: "Grid view",
Expand Down Expand Up @@ -69,27 +65,34 @@ export async function getStaticPaths() {
};
}, {});
const questions = questionsList.map((question, index) => {
return {
text: question,
answers: candidatesAnswersForArea.map((answerRecord) => {
const candidateFullName = getLookupFieldValue(
answerRecord,
"Candidate full name"
);
const answer =
answersListByCandidate[candidateFullName][index] &&
getStringFieldValue(
answersListByCandidate[candidateFullName][index],
"Text"
const questions = questionRecords
.filter(
(questionRecord) =>
getLookupFieldValue(questionRecord, "Local authority name") ===
getLookupFieldValue(candidateRecord, "Area local authority name")
)
.map((questionRecord) => getStringFieldValue(questionRecord, "Text"))
.map((question, index) => {
return {
text: question,
answers: candidatesAnswersForArea.map((answerRecord) => {
const candidateFullName = getLookupFieldValue(
answerRecord,
"Candidate full name"
);
return {
candidateFullName,
answer,
};
}),
};
});
const answer =
answersListByCandidate[candidateFullName][index] &&
getStringFieldValue(
answersListByCandidate[candidateFullName][index],
"Text"
);
return {
candidateFullName,
answer,
};
}),
};
});
const hasAnswers = questions.some((question) =>
question.answers.some((answer) => Boolean(answer.answer))
Expand Down

0 comments on commit fbed68c

Please sign in to comment.