2022-03-26 16:46:05 +11:00
|
|
|
import React from 'react';
|
2022-03-26 14:10:10 +11:00
|
|
|
import { PageTitle } from './PageTitle';
|
|
|
|
import { Page } from './Page';
|
2022-03-26 00:08:00 +11:00
|
|
|
import { QuestionList } from './QuestionList';
|
2022-03-26 16:46:05 +11:00
|
|
|
import { getUnansweredQuestions, QuestionData } from './QuestionsData';
|
2022-03-24 00:02:35 +11:00
|
|
|
|
2022-03-26 16:03:57 +11:00
|
|
|
export const HomePage = () => {
|
2022-03-26 16:46:05 +11:00
|
|
|
const [questions, setQuestions] = React.useState<QuestionData[]>([]);
|
|
|
|
const [questionsLoading, setQuestionsLoading] = React.useState(true);
|
|
|
|
|
|
|
|
React.useEffect(() => {
|
|
|
|
const doGetUnansweredQuestion = async () => {
|
|
|
|
const unanswereedQuestions = await getUnansweredQuestions();
|
|
|
|
setQuestions(unanswereedQuestions);
|
|
|
|
setQuestionsLoading(false);
|
|
|
|
};
|
|
|
|
doGetUnansweredQuestion();
|
2022-03-26 16:03:57 +11:00
|
|
|
}, []);
|
|
|
|
|
2022-03-26 16:50:56 +11:00
|
|
|
const handleAskQuestionClick = () => {
|
|
|
|
console.log('TODO - move to the AskPage');
|
|
|
|
};
|
2022-03-26 16:46:05 +11:00
|
|
|
|
2022-03-26 16:03:57 +11:00
|
|
|
return (
|
|
|
|
<Page>
|
|
|
|
<div>
|
|
|
|
<PageTitle>Unanswered Questions</PageTitle>
|
2022-03-26 16:50:56 +11:00
|
|
|
<button onClick={handleAskQuestionClick}>Ask a question</button>
|
2022-03-26 16:03:57 +11:00
|
|
|
</div>
|
2022-03-26 16:46:05 +11:00
|
|
|
{questionsLoading ? (
|
|
|
|
<div>Loading...</div>
|
|
|
|
) : (
|
|
|
|
<QuestionList data={questions || []} />
|
|
|
|
)}
|
2022-03-26 16:03:57 +11:00
|
|
|
</Page>
|
|
|
|
);
|
|
|
|
};
|