2022-03-28 21:02:55 +11:00
|
|
|
/** @jsxImportSource @emotion/react */
|
|
|
|
import { css } from '@emotion/react';
|
2022-03-29 16:24:10 +11:00
|
|
|
import { useNavigate } from 'react-router-dom';
|
2022-03-28 21:02:55 +11:00
|
|
|
|
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-28 21:02:55 +11:00
|
|
|
import { PrimaryButton } from './Styles';
|
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-29 16:24:10 +11:00
|
|
|
const navigate = useNavigate();
|
2022-03-26 16:50:56 +11:00
|
|
|
const handleAskQuestionClick = () => {
|
2022-03-29 16:24:10 +11:00
|
|
|
navigate('ask');
|
2022-03-26 16:50:56 +11:00
|
|
|
};
|
2022-03-26 16:46:05 +11:00
|
|
|
|
2022-03-26 16:03:57 +11:00
|
|
|
return (
|
|
|
|
<Page>
|
2022-03-28 21:02:55 +11:00
|
|
|
<div
|
|
|
|
css={css`
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: space-between;
|
|
|
|
`}
|
|
|
|
>
|
2022-03-26 16:03:57 +11:00
|
|
|
<PageTitle>Unanswered Questions</PageTitle>
|
2022-03-28 21:02:55 +11:00
|
|
|
<PrimaryButton onClick={handleAskQuestionClick}>
|
|
|
|
Ask a question
|
|
|
|
</PrimaryButton>
|
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>
|
|
|
|
);
|
|
|
|
};
|