From 191d87662d718557998ebeb938dc604e449f2743 Mon Sep 17 00:00:00 2001 From: Jason Zhu Date: Wed, 30 Mar 2022 14:04:55 +1100 Subject: [PATCH] Chap05 -> Using route parameters -> Implementing more of the question pagee -> 1. Add a function that will simulate a web request to get a question --- QandA/frontend/src/QuestionsData.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/QandA/frontend/src/QuestionsData.ts b/QandA/frontend/src/QuestionsData.ts index 8bac88a..4b5fc97 100644 --- a/QandA/frontend/src/QuestionsData.ts +++ b/QandA/frontend/src/QuestionsData.ts @@ -56,3 +56,11 @@ export const getUnansweredQuestions = async (): Promise => { const wait = (ms: number): Promise => { return new Promise((resolve) => setTimeout(resolve, ms)); }; + +export const getQuestion = async ( + questionId: number, +): Promise => { + await wait(500); + const results = questions.filter((q) => q.questionId === questionId); + return results.length === 0 ? null : results[0]; +};