Compare commits
12 Commits
master
...
e90cc6b191
Author | SHA1 | Date |
---|---|---|
Yiqing Zhu | e90cc6b191 | |
Yiqing Zhu | 9830fb1af2 | |
Yiqing Zhu | a5d1351f92 | |
Yiqing Zhu | 2b3cbdddd5 | |
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,38 +0,0 @@
|
|||
.App {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.App-logo {
|
||||
height: 40vmin;
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: no-preference) {
|
||||
.App-logo {
|
||||
animation: App-logo-spin infinite 20s linear;
|
||||
}
|
||||
}
|
||||
|
||||
.App-header {
|
||||
background-color: #282c34;
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: calc(10px + 2vmin);
|
||||
color: white;
|
||||
}
|
||||
|
||||
.App-link {
|
||||
color: #61dafb;
|
||||
}
|
||||
|
||||
@keyframes App-logo-spin {
|
||||
from {
|
||||
transform: rotate(0deg);
|
||||
}
|
||||
to {
|
||||
transform: rotate(360deg);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
.container {
|
||||
font-family: 'Segoe UI', 'Helvetica', sans-serif;
|
||||
font-size: 16px;
|
||||
color: #5c5a5a;
|
||||
}
|
|
@ -1,11 +1,11 @@
|
|||
import React from 'react';
|
||||
import { Header } from './Header';
|
||||
import './App.css';
|
||||
import style from './App.module.css';
|
||||
import { HomePage } from './HomePage';
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div className="App">
|
||||
<div className={style.container}>
|
||||
<Header />
|
||||
<HomePage />
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
.container {
|
||||
position: fixed;
|
||||
box-sizing: border-box;
|
||||
top: 0;
|
||||
width: 100%;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
padding: 10px 20px;
|
||||
background-color: #fff;
|
||||
border-bottom: 1px solid #e3e2e2;
|
||||
box-shadow: 0 3px 7px 0 rgba(110, 112, 114, 0.21);
|
||||
}
|
|
@ -1,13 +1,24 @@
|
|||
import React from 'react';
|
||||
import { UserIcon } from './Icons';
|
||||
import style from './Header.module.css';
|
||||
|
||||
export const Header = () => (
|
||||
<div>
|
||||
<a href="./">Q & A</a>
|
||||
<input type="text" placeholder="Search ..." />
|
||||
<a href="./signin">
|
||||
<UserIcon />
|
||||
<span>Sign In</span>
|
||||
</a>
|
||||
</div>
|
||||
);
|
||||
export const Header = () => {
|
||||
const handleSearchInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
console.log(e.currentTarget.value);
|
||||
};
|
||||
|
||||
return (
|
||||
<div className={style.container}>
|
||||
<a href="./">Q & A</a>
|
||||
<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 { PageTitle } from './PageTitle';
|
||||
import { Page } from './Page';
|
||||
import { QuestionList } from './QuestionList';
|
||||
import { getUnansweredQuestions } from './QuestionsData';
|
||||
import { getUnansweredQuestions, QuestionData } from './QuestionsData';
|
||||
|
||||
export const HomePage = () => (
|
||||
<div>
|
||||
<div>
|
||||
<h2>Unanswered Questions</h2>
|
||||
<button>Ask a question</button>
|
||||
</div>
|
||||
<QuestionList data={getUnansweredQuestions()} />
|
||||
</div>
|
||||
);
|
||||
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>
|
||||
<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);
|
||||
};
|
||||
|
||||
const wait = (ms: number): Promise<void> => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
|
|
|
@ -1,13 +1,4 @@
|
|||
body {
|
||||
margin: 0;
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
|
||||
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
|
||||
sans-serif;
|
||||
-webkit-font-smoothing: antialiased;
|
||||
-moz-osx-font-smoothing: grayscale;
|
||||
}
|
||||
|
||||
code {
|
||||
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
|
||||
monospace;
|
||||
background-color: #f7f8fa;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue