Compare commits
51 Commits
Author | SHA1 | Date |
---|---|---|
Jason Zhu | d0bb6abf15 | |
Jason Zhu | 98125ab39c | |
Jason Zhu | fc14b1bca6 | |
Jason Zhu | d72ed50173 | |
Jason Zhu | 3e93e072f0 | |
Jason Zhu | 17dd32bcac | |
Jason Zhu | 2f868ead68 | |
Jason Zhu | e03de1f1fa | |
Jason Zhu | 269e6173d1 | |
Jason Zhu | 1f05de9a0c | |
Jason Zhu | 6ccb67ca01 | |
Jason Zhu | cdc8fea5b5 | |
Jason Zhu | 292294adf4 | |
Jason Zhu | 2ea9deeba6 | |
Jason Zhu | dee956f542 | |
Jason Zhu | 17cecb2931 | |
Jason Zhu | 527d00be86 | |
Jason Zhu | b5f12380b3 | |
Jason Zhu | a2f0fb0522 | |
Jason Zhu | de5e78e621 | |
Jason Zhu | 3fb4435d68 | |
Jason Zhu | 1f7388e26d | |
Jason Zhu | 8e13f18a03 | |
Jason Zhu | b18e0588b5 | |
Jason Zhu | 379feb7e99 | |
Jason Zhu | 89ea270218 | |
Jason Zhu | 353cb61006 | |
Jason Zhu | 076120fee7 | |
Jason Zhu | 70839dfeca | |
Jason Zhu | 94545f83c1 | |
Jason Zhu | 1a0a1006dd | |
Jason Zhu | ab5f1fb67f | |
Jason Zhu | eeae6b889c | |
Jason Zhu | a2eb621624 | |
Jason Zhu | 3f5f086e44 | |
Jason Zhu | c9a2989a15 | |
Jason Zhu | e4ca4f079c | |
Jason Zhu | b7f435a986 | |
Jason Zhu | 05f529d84e | |
Jason Zhu | beedc2aef8 | |
Jason Zhu | 58c82bb334 | |
Jason Zhu | 8a19835b45 | |
Jason Zhu | 563aaf0d27 | |
Jason Zhu | 27421824c7 | |
Jason Zhu | e3810cc810 | |
Jason Zhu | 5772c175af | |
Jason Zhu | ffc8fe16f5 | |
Jason Zhu | de5bc7f437 | |
Jason Zhu | 5d7f817620 | |
Jason Zhu | f833534d19 | |
Jason Zhu | affd03b580 |
File diff suppressed because it is too large
Load Diff
|
@ -12,8 +12,11 @@
|
|||
"@types/node": "^16.11.26",
|
||||
"@types/react": "^17.0.41",
|
||||
"@types/react-dom": "^17.0.14",
|
||||
"history": "^5.3.0",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"react-hook-form": "^7.29.0",
|
||||
"react-router-dom": "^6.2.2",
|
||||
"react-scripts": "5.0.0",
|
||||
"typescript": "^4.6.2",
|
||||
"web-vitals": "^2.1.4"
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
|
||||
import React from 'react';
|
||||
import { AnswerData } from './QuestionsData';
|
||||
import { gray3 } from './Styles';
|
||||
|
||||
interface Props {
|
||||
data: AnswerData;
|
||||
}
|
||||
|
||||
export const Answer = ({ data }: Props) => (
|
||||
<div
|
||||
css={css`
|
||||
padding: 10px 0px;
|
||||
`}
|
||||
>
|
||||
<div
|
||||
css={css`
|
||||
padding: 10px 0px;
|
||||
font-size: 13px;
|
||||
`}
|
||||
>
|
||||
{data.content}
|
||||
</div>
|
||||
<div
|
||||
css={css`
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
color: ${gray3};
|
||||
`}
|
||||
>
|
||||
{`Answered by ${
|
||||
data.userName
|
||||
} on ${data.created.toLocaleDateString()} ${data.created.toLocaleTimeString()}`}
|
||||
</div>
|
||||
</div>
|
||||
);
|
|
@ -0,0 +1,31 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import React from 'react';
|
||||
import { AnswerData } from './QuestionsData';
|
||||
import { Answer } from './Answer';
|
||||
import { gray5 } from './Styles';
|
||||
|
||||
interface Props {
|
||||
data: AnswerData[];
|
||||
}
|
||||
|
||||
export const AnswerList = ({ data }: Props) => (
|
||||
<ul
|
||||
css={css`
|
||||
list-style: none;
|
||||
margin: 10px 0 0 0;
|
||||
padding: 0;
|
||||
`}
|
||||
>
|
||||
{data.map((answer) => (
|
||||
<li
|
||||
css={css`
|
||||
border-top: 1px solid ${gray5};
|
||||
`}
|
||||
key={answer.answertId}
|
||||
>
|
||||
<Answer data={answer} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
);
|
|
@ -2,29 +2,58 @@
|
|||
import { css } from '@emotion/react';
|
||||
|
||||
import React from 'react';
|
||||
import { BrowserRouter, Routes, Route } from 'react-router-dom';
|
||||
|
||||
import { Header } from './Header';
|
||||
import { HomePage } from './HomePage';
|
||||
import { fontFamily, fontSize, gray2 } from './Styles';
|
||||
import { SearchPage } from './SearchPage';
|
||||
import { SignInPage } from './SignInPage';
|
||||
import { NotFoundPage } from './NotFoundPage';
|
||||
import { QuestionPage } from './QuestionPage';
|
||||
|
||||
const AskPage = React.lazy(() => import('./AskPage'));
|
||||
|
||||
function App() {
|
||||
return (
|
||||
<div
|
||||
css={css`
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
color: ${gray2};
|
||||
`}
|
||||
>
|
||||
<BrowserRouter>
|
||||
<Header />
|
||||
<HomePage />
|
||||
</div>
|
||||
<div
|
||||
css={css`
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
color: ${gray2};
|
||||
`}
|
||||
>
|
||||
<Routes>
|
||||
<Route path="" element={<HomePage />} />
|
||||
<Route path="search" element={<SearchPage />} />
|
||||
<Route
|
||||
path="ask"
|
||||
element={
|
||||
<React.Suspense
|
||||
fallback={
|
||||
<div
|
||||
css={css`
|
||||
margin-top: 100px;
|
||||
text-align: center;
|
||||
`}
|
||||
>
|
||||
Loading...
|
||||
</div>
|
||||
}
|
||||
>
|
||||
<AskPage />
|
||||
</React.Suspense>
|
||||
}
|
||||
/>
|
||||
<Route path="signin" element={<SignInPage />} />
|
||||
<Route path="questions/:questionId" element={<QuestionPage />} />
|
||||
<Route path="*" element={<NotFoundPage />} />
|
||||
</Routes>
|
||||
</div>
|
||||
</BrowserRouter>
|
||||
);
|
||||
}
|
||||
|
||||
class ProblemComponent extends React.Component {
|
||||
render() {
|
||||
return <div ref="div" />;
|
||||
}
|
||||
}
|
||||
|
||||
export default App;
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
import React from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Page } from './Page';
|
||||
import {
|
||||
FieldInput,
|
||||
FieldLabel,
|
||||
Fieldset,
|
||||
FieldContainer,
|
||||
FieldTextArea,
|
||||
FormButtonContainer,
|
||||
PrimaryButton,
|
||||
} from './Styles';
|
||||
|
||||
type FormData = {
|
||||
title: string;
|
||||
content: string;
|
||||
};
|
||||
|
||||
export const AskPage = () => {
|
||||
const { register } = useForm<FormData>();
|
||||
return (
|
||||
<Page title="Ask a question">
|
||||
<form>
|
||||
<Fieldset>
|
||||
<FieldContainer>
|
||||
<FieldLabel htmlFor="title">Title</FieldLabel>
|
||||
<FieldInput
|
||||
{...register('title')}
|
||||
id="title"
|
||||
name="title"
|
||||
type="text"
|
||||
/>
|
||||
</FieldContainer>
|
||||
<FieldContainer>
|
||||
<FieldLabel htmlFor="content">Content</FieldLabel>
|
||||
<FieldTextArea
|
||||
{...register('content')}
|
||||
id="content"
|
||||
name="content"
|
||||
/>
|
||||
</FieldContainer>
|
||||
<FormButtonContainer>
|
||||
<PrimaryButton type="submit">Submit Your Question</PrimaryButton>
|
||||
</FormButtonContainer>
|
||||
</Fieldset>
|
||||
</form>
|
||||
</Page>
|
||||
);
|
||||
};
|
||||
|
||||
export default AskPage;
|
|
@ -1,13 +1,23 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import React from 'react';
|
||||
import { Link, useSearchParams } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { UserIcon } from './Icons';
|
||||
import { fontFamily, fontSize, gray1, gray2, gray5 } from './Styles';
|
||||
|
||||
import React from 'react';
|
||||
import { UserIcon } from './Icons';
|
||||
type FormData = {
|
||||
search: string;
|
||||
};
|
||||
|
||||
export const Header = () => {
|
||||
const handleSearchInputChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
console.log(e.currentTarget.value);
|
||||
const { register } = useForm<FormData>();
|
||||
const [searchParams] = useSearchParams();
|
||||
const criteria = searchParams.get('criteria') || '';
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
};
|
||||
|
||||
return (
|
||||
|
@ -26,8 +36,8 @@ export const Header = () => {
|
|||
box-shadow: 0 3px 7px 0 rgba(100, 112, 114, 0.21);
|
||||
`}
|
||||
>
|
||||
<a
|
||||
href="./"
|
||||
<Link
|
||||
to="/"
|
||||
css={css`
|
||||
font-size: 24px;
|
||||
font-weight: bold;
|
||||
|
@ -36,29 +46,33 @@ export const Header = () => {
|
|||
`}
|
||||
>
|
||||
Q & A
|
||||
</a>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Search ..."
|
||||
onChange={handleSearchInputChange}
|
||||
css={css`
|
||||
box-sizing: border-box;
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
padding: 8px 10px;
|
||||
border: 1px solid ${gray5};
|
||||
border-radius: 3px;
|
||||
color: ${gray2};
|
||||
background-color: white;
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
:focus {
|
||||
outline-color: ${gray5};
|
||||
}
|
||||
`}
|
||||
/>
|
||||
<a
|
||||
href="./signin"
|
||||
</Link>
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input
|
||||
{...register('search')}
|
||||
name="search"
|
||||
type="text"
|
||||
placeholder="Search ..."
|
||||
defaultValue={criteria}
|
||||
css={css`
|
||||
box-sizing: border-box;
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
padding: 8px 10px;
|
||||
border: 1px solid ${gray5};
|
||||
border-radius: 3px;
|
||||
color: ${gray2};
|
||||
background-color: white;
|
||||
width: 200px;
|
||||
height: 30px;
|
||||
:focus {
|
||||
outline-color: ${gray5};
|
||||
}
|
||||
`}
|
||||
/>
|
||||
</form>
|
||||
<Link
|
||||
to="signin"
|
||||
css={css`
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
|
@ -76,14 +90,8 @@ export const Header = () => {
|
|||
`}
|
||||
>
|
||||
<UserIcon />
|
||||
<span
|
||||
css={css`
|
||||
margin-left: 7px;
|
||||
`}
|
||||
>
|
||||
Sign In
|
||||
</span>
|
||||
</a>
|
||||
<span>Sign In</span>
|
||||
</Link>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
import React from 'react';
|
||||
import { PageTitle } from './PageTitle';
|
||||
|
@ -21,8 +22,9 @@ export const HomePage = () => {
|
|||
doGetUnansweredQuestion();
|
||||
}, []);
|
||||
|
||||
const navigate = useNavigate();
|
||||
const handleAskQuestionClick = () => {
|
||||
console.log('TODO - move to the AskPage');
|
||||
navigate('ask');
|
||||
};
|
||||
|
||||
return (
|
||||
|
|
|
@ -0,0 +1,4 @@
|
|||
import React from 'react';
|
||||
import { Page } from './Page';
|
||||
|
||||
export const NotFoundPage = () => <Page title="Page Not Found">{null}</Page>;
|
|
@ -1,8 +1,9 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import { gray2, gray3 } from './Styles';
|
||||
|
||||
import { Link } from 'react-router-dom';
|
||||
import React from 'react';
|
||||
|
||||
import { gray2, gray3 } from './Styles';
|
||||
import { QuestionData } from './QuestionsData';
|
||||
|
||||
interface Props {
|
||||
|
@ -18,7 +19,15 @@ export const Question = ({ data, showContent }: Props) => (
|
|||
font-size: 19px;
|
||||
`}
|
||||
>
|
||||
{data.title}
|
||||
<Link
|
||||
css={css`
|
||||
text-decoration: none;
|
||||
color: ${gray2};
|
||||
`}
|
||||
to={`/questions/${data.questionId}`}
|
||||
>
|
||||
{data.title}
|
||||
</Link>
|
||||
</div>
|
||||
{showContent && (
|
||||
<div
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
import {
|
||||
FieldContainer,
|
||||
FieldLabel,
|
||||
Fieldset,
|
||||
FieldTextArea,
|
||||
FormButtonContainer,
|
||||
gray3,
|
||||
gray6,
|
||||
PrimaryButton,
|
||||
} from './Styles';
|
||||
|
||||
import React from 'react';
|
||||
import { useParams } from 'react-router-dom';
|
||||
import { useForm } from 'react-hook-form';
|
||||
|
||||
import { Page } from './Page';
|
||||
import { QuestionData, getQuestion } from './QuestionsData';
|
||||
import { AnswerList } from './AnswerList';
|
||||
|
||||
type FormData = {
|
||||
content: string;
|
||||
};
|
||||
|
||||
export const QuestionPage = () => {
|
||||
const [question, setQuestion] = React.useState<QuestionData | null>(null);
|
||||
const { questionId } = useParams();
|
||||
const { register } = useForm<FormData>();
|
||||
React.useEffect(() => {
|
||||
const doGetQuestion = async (questionId: number) => {
|
||||
const foundQuestion = await getQuestion(questionId);
|
||||
setQuestion(foundQuestion);
|
||||
};
|
||||
if (questionId) {
|
||||
doGetQuestion(Number(questionId));
|
||||
}
|
||||
}, [questionId]);
|
||||
return (
|
||||
<Page>
|
||||
<div
|
||||
css={css`
|
||||
background-color: white;
|
||||
padding: 15px 20px 20px 20px;
|
||||
border-radius: 4px;
|
||||
border: 1px solid ${gray6};
|
||||
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.16);
|
||||
`}
|
||||
>
|
||||
<div
|
||||
css={css`
|
||||
font-size: 19px;
|
||||
font-weight: bold;
|
||||
margin: 10px 0px 5px;
|
||||
`}
|
||||
>
|
||||
{question === null ? '' : question.title}
|
||||
</div>
|
||||
{question !== null && (
|
||||
<React.Fragment>
|
||||
<p
|
||||
css={css`
|
||||
margin-top: 0px;
|
||||
background-color: white;
|
||||
`}
|
||||
>
|
||||
{question.content}
|
||||
</p>
|
||||
<div
|
||||
css={css`
|
||||
font-size: 12px;
|
||||
font-style: italic;
|
||||
color: ${gray3};
|
||||
`}
|
||||
>
|
||||
{`Asked by ${
|
||||
question.userName
|
||||
} on ${question.created.toLocaleDateString()} ${question.created.toLocaleTimeString()}`}
|
||||
</div>
|
||||
<AnswerList data={question.answers} />
|
||||
<form
|
||||
css={css`
|
||||
margin-top: 20px;
|
||||
`}
|
||||
>
|
||||
<Fieldset>
|
||||
<FieldContainer>
|
||||
<FieldLabel htmlFor="content">Your Answer</FieldLabel>
|
||||
<FieldTextArea
|
||||
{...register('content')}
|
||||
id="content"
|
||||
name="content"
|
||||
/>
|
||||
</FieldContainer>
|
||||
<FormButtonContainer>
|
||||
<PrimaryButton type="submit">
|
||||
Submit Your Answer
|
||||
</PrimaryButton>
|
||||
</FormButtonContainer>
|
||||
</Fieldset>
|
||||
</form>
|
||||
</React.Fragment>
|
||||
)}
|
||||
</div>
|
||||
Question Page {questionId}
|
||||
</Page>
|
||||
);
|
||||
};
|
|
@ -56,3 +56,22 @@ export const getUnansweredQuestions = async (): Promise<QuestionData[]> => {
|
|||
const wait = (ms: number): Promise<void> => {
|
||||
return new Promise((resolve) => setTimeout(resolve, ms));
|
||||
};
|
||||
|
||||
export const getQuestion = async (
|
||||
questionId: number,
|
||||
): Promise<QuestionData | null> => {
|
||||
await wait(500);
|
||||
const results = questions.filter((q) => q.questionId === questionId);
|
||||
return results.length === 0 ? null : results[0];
|
||||
};
|
||||
|
||||
export const searchQuestions = async (
|
||||
criteria: string,
|
||||
): Promise<QuestionData[]> => {
|
||||
await wait(500);
|
||||
return questions.filter(
|
||||
(q) =>
|
||||
q.title.toLowerCase().indexOf(criteria.toLowerCase()) >= 0 ||
|
||||
q.content.toLowerCase().indexOf(criteria.toLowerCase()) >= 0,
|
||||
);
|
||||
};
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
/** @jsxImportSource @emotion/react */
|
||||
import { css } from '@emotion/react';
|
||||
|
||||
import React from 'react';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
import { Page } from './Page';
|
||||
import { QuestionList } from './QuestionList';
|
||||
import { searchQuestions, QuestionData } from './QuestionsData';
|
||||
|
||||
export const SearchPage = () => {
|
||||
const [searchParams] = useSearchParams();
|
||||
const [questions, setQuestions] = React.useState<QuestionData[]>([]);
|
||||
const search = searchParams.get('criteria') || '';
|
||||
React.useEffect(() => {
|
||||
const doSearch = async (criteria: string) => {
|
||||
const foundResults = await searchQuestions(criteria);
|
||||
setQuestions(foundResults);
|
||||
};
|
||||
doSearch(search);
|
||||
}, [search]);
|
||||
|
||||
return (
|
||||
<Page title="Search Results">
|
||||
{search && (
|
||||
<p
|
||||
css={css`
|
||||
font-size: 16px;
|
||||
font-style: italic;
|
||||
margin-top: 0px;
|
||||
`}
|
||||
>
|
||||
<QuestionList data={questions} />
|
||||
</p>
|
||||
)}
|
||||
</Page>
|
||||
);
|
||||
};
|
|
@ -0,0 +1,4 @@
|
|||
import React from 'react';
|
||||
import { Page } from './Page';
|
||||
|
||||
export const SignInPage = () => <Page title="Sign In">{null}</Page>;
|
|
@ -1,4 +1,5 @@
|
|||
import styled from '@emotion/styled';
|
||||
import { css } from '@emotion/react';
|
||||
|
||||
export const gray1 = '#383737';
|
||||
export const gray2 = '#5c5a5a';
|
||||
|
@ -33,3 +34,70 @@ export const PrimaryButton = styled.button`
|
|||
cursor: not-allowed;
|
||||
}
|
||||
`;
|
||||
|
||||
export const Fieldset = styled.fieldset`
|
||||
margin: 10px auto 0 auto;
|
||||
padding: 30px;
|
||||
width: 350px;
|
||||
background-color: ${gray6};
|
||||
border-radius: 4px;
|
||||
border: 1px solid ${gray5};
|
||||
box-shadow: 0 3px 5px 0 rgba(0, 0, 0, 0.16);
|
||||
`;
|
||||
|
||||
export const FieldContainer = styled.label`
|
||||
font-weight: 10px;
|
||||
`;
|
||||
|
||||
const baseFieldCSS = css`
|
||||
box-sizing: border-box;
|
||||
font-family: ${fontFamily};
|
||||
font-size: ${fontSize};
|
||||
margin-bottom: 5px;
|
||||
padding: 8px 10px;
|
||||
border: 1px solid ${gray5};
|
||||
border-radius: 3px;
|
||||
color: ${gray2};
|
||||
background-color: white;
|
||||
width: 100%;
|
||||
:focus {
|
||||
outline-color: ${gray5};
|
||||
}
|
||||
:disabled {
|
||||
background-color: ${gray6};
|
||||
}
|
||||
`;
|
||||
|
||||
export const FieldLabel = styled.label`
|
||||
font-weight: bold;
|
||||
`;
|
||||
|
||||
export const FieldInput = styled.input`
|
||||
${baseFieldCSS}
|
||||
`;
|
||||
|
||||
export const FieldTextArea = styled.textarea`
|
||||
${baseFieldCSS}
|
||||
height: 100px;
|
||||
`;
|
||||
|
||||
export const FieldError = styled.div`
|
||||
font-size: 12px;
|
||||
color: red;
|
||||
`;
|
||||
|
||||
export const FormButtonContainer = styled.div`
|
||||
margin: 30px 0px 0px 0px;
|
||||
padding: 20px 0px 0px 0px;
|
||||
border-top: 1px solid ${gray5};
|
||||
`;
|
||||
|
||||
export const SubmissionSussess = styled.div`
|
||||
margin-top: 10px;
|
||||
color: green;
|
||||
`;
|
||||
|
||||
export const SubmissionFailure = styled.div`
|
||||
margin-top: 10px;
|
||||
color: red;
|
||||
`;
|
||||
|
|
Loading…
Reference in New Issue