Compare commits
8 Commits
Author | SHA1 | Date |
---|---|---|
Yiqing Zhu | b4d0fed5cb | |
Yiqing Zhu | 7dd02a76ea | |
Yiqing Zhu | 0f31f492cc | |
Yiqing Zhu | 2afb204673 | |
Yiqing Zhu | cdecba7c2e | |
Yiqing Zhu | 072b7dcf88 | |
Yiqing Zhu | b6fdcbd740 | |
Yiqing Zhu | 4affa35f00 |
|
@ -1,13 +1,23 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { UserIcon } from './Icons';
|
import { UserIcon } from './Icons';
|
||||||
|
|
||||||
export const Header = () => (
|
export const Header = () => {
|
||||||
<div>
|
const handleSearchInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
<a href="./">Q & A</a>
|
console.log(e.currentTarget.value);
|
||||||
<input type="text" placeholder="Search ..." />
|
};
|
||||||
<a href="./signin">
|
|
||||||
<UserIcon />
|
return (
|
||||||
<span>Sign In</span>
|
<div>
|
||||||
</a>
|
<a href="./">Q & A</a>
|
||||||
</div>
|
<input
|
||||||
);
|
type="text"
|
||||||
|
placeholder="Search ..."
|
||||||
|
onChange={handleSearchInputChange}
|
||||||
|
/>
|
||||||
|
<a href="./signin">
|
||||||
|
<UserIcon />
|
||||||
|
<span>Sign In</span>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -1,13 +1,37 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
import { PageTitle } from './PageTitle';
|
||||||
|
import { Page } from './Page';
|
||||||
import { QuestionList } from './QuestionList';
|
import { QuestionList } from './QuestionList';
|
||||||
import { getUnansweredQuestions } from './QuestionsData';
|
import { getUnansweredQuestions, QuestionData } from './QuestionsData';
|
||||||
|
|
||||||
export const HomePage = () => (
|
export const HomePage = () => {
|
||||||
<div>
|
const [questions, setQuestions] = React.useState<QuestionData[]>([]);
|
||||||
<div>
|
const [questionsLoading, setQuestionsLoading] = React.useState(true);
|
||||||
<h2>Unanswered Questions</h2>
|
|
||||||
<button>Ask a question</button>
|
React.useEffect(() => {
|
||||||
</div>
|
const doGetUnansweredQuestion = async () => {
|
||||||
<QuestionList data={getUnansweredQuestions()} />
|
const unanswereedQuestions = await getUnansweredQuestions();
|
||||||
</div>
|
setQuestions(unanswereedQuestions);
|
||||||
);
|
setQuestionsLoading(false);
|
||||||
|
};
|
||||||
|
doGetUnansweredQuestion();
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const handleAskQuestionClick = () => {
|
||||||
|
console.log('TODO - move to the AskPage');
|
||||||
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Page>
|
||||||
|
<div>
|
||||||
|
<PageTitle>Unanswered Questions</PageTitle>
|
||||||
|
<button onClick={handleAskQuestionClick}>Ask a question</button>
|
||||||
|
</div>
|
||||||
|
{questionsLoading ? (
|
||||||
|
<div>Loading...</div>
|
||||||
|
) : (
|
||||||
|
<QuestionList data={questions || []} />
|
||||||
|
)}
|
||||||
|
</Page>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
import React from 'react';
|
||||||
|
import { PageTitle } from './PageTitle';
|
||||||
|
|
||||||
|
interface Props {
|
||||||
|
title?: string;
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const Page = ({ title, children }: Props) => (
|
||||||
|
<div>
|
||||||
|
{title && <PageTitle>{title}</PageTitle>}
|
||||||
|
{children}
|
||||||
|
{/* Component nested within Page component will be rendere here */}
|
||||||
|
</div>
|
||||||
|
);
|
|
@ -0,0 +1,5 @@
|
||||||
|
import React from 'react';
|
||||||
|
interface Props {
|
||||||
|
children: React.ReactNode;
|
||||||
|
}
|
||||||
|
export const PageTitle = ({ children }: Props) => <h2>{children}</h2>;
|
|
@ -48,6 +48,11 @@ const questions: QuestionData[] = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const getUnansweredQuestions = (): QuestionData[] => {
|
export const getUnansweredQuestions = async (): Promise<QuestionData[]> => {
|
||||||
|
await wait(500);
|
||||||
return questions.filter((q) => q.answers.length === 0);
|
return questions.filter((q) => q.answers.length === 0);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const wait = (ms: number): Promise<void> => {
|
||||||
|
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in New Issue