Compare commits
No commits in common. "b4d0fed5cb73ce9409d9e0c8ca5b921521701fd1" and "dafd006124440c24516335f4833b4693fcf3a19d" have entirely different histories.
b4d0fed5cb
...
dafd006124
|
@ -1,23 +1,13 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { UserIcon } from './Icons';
|
import { UserIcon } from './Icons';
|
||||||
|
|
||||||
export const Header = () => {
|
export const Header = () => (
|
||||||
const handleSearchInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
|
||||||
console.log(e.currentTarget.value);
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<div>
|
<div>
|
||||||
<a href="./">Q & A</a>
|
<a href="./">Q & A</a>
|
||||||
<input
|
<input type="text" placeholder="Search ..." />
|
||||||
type="text"
|
|
||||||
placeholder="Search ..."
|
|
||||||
onChange={handleSearchInputChange}
|
|
||||||
/>
|
|
||||||
<a href="./signin">
|
<a href="./signin">
|
||||||
<UserIcon />
|
<UserIcon />
|
||||||
<span>Sign In</span>
|
<span>Sign In</span>
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
|
||||||
|
|
|
@ -1,37 +1,13 @@
|
||||||
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, QuestionData } from './QuestionsData';
|
import { getUnansweredQuestions } from './QuestionsData';
|
||||||
|
|
||||||
export const HomePage = () => {
|
export const HomePage = () => (
|
||||||
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();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleAskQuestionClick = () => {
|
|
||||||
console.log('TODO - move to the AskPage');
|
|
||||||
};
|
|
||||||
|
|
||||||
return (
|
|
||||||
<Page>
|
|
||||||
<div>
|
<div>
|
||||||
<PageTitle>Unanswered Questions</PageTitle>
|
<div>
|
||||||
<button onClick={handleAskQuestionClick}>Ask a question</button>
|
<h2>Unanswered Questions</h2>
|
||||||
|
<button>Ask a question</button>
|
||||||
</div>
|
</div>
|
||||||
{questionsLoading ? (
|
<QuestionList data={getUnansweredQuestions()} />
|
||||||
<div>Loading...</div>
|
</div>
|
||||||
) : (
|
);
|
||||||
<QuestionList data={questions || []} />
|
|
||||||
)}
|
|
||||||
</Page>
|
|
||||||
);
|
|
||||||
};
|
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
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>
|
|
||||||
);
|
|
|
@ -1,5 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
interface Props {
|
|
||||||
children: React.ReactNode;
|
|
||||||
}
|
|
||||||
export const PageTitle = ({ children }: Props) => <h2>{children}</h2>;
|
|
|
@ -48,11 +48,6 @@ const questions: QuestionData[] = [
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
|
|
||||||
export const getUnansweredQuestions = async (): Promise<QuestionData[]> => {
|
export const getUnansweredQuestions = (): 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