You can directly open the link below to see the page:
https://licaomeng.github.io/github-repo-search-app/
STEP 1: Perform yarn install
or npm install
STEP 2: Perform yarn start
or npm start
STEP 3: Open https://localhost:3000
Perform yarn build
or npm run build
, ./build
would be generated for production deployment.
- React
- TypeScript
- The page should meet the basic requirement on view/search/pagination/share
- Should consider the throttle use cases including but not limited to enter, click pagination, etc.
- Should consider the performance. (garbage data collection, event listener management, animation, user interaction, etc.)
- Should consider the corner cases. (no search result, without pagination, fetch failure, etc.)
- Should work well on responsive window and desktop/tablets/mobile sides.
- Should consider basic user experience such as loading
- Should consider the accessibility (ARIA, high contrast, theme mode, etc.).
- Should consider the localization (RTL, translation).
Except LoadingBar
, customized those components: Header, SearchBox, RepoList, Pagination
.
Use TS notation to describe data entities to power your components
type SearchBoxProps = {
isInHeader: boolean;
}
type dataList = {
name?: string;
full_name: string;
html_url: string;
description: string;
updated_at: string;
stargazers_count: number;
language: string;
}[];
type ListProps = {
data: dataList;
}
type PaginationProps = {
currentPage: number;
totalPages: number;
}
type HeaderProps = {
children?: any;
}
Use the following API from GitHub: https://docs.github.com/en/rest/reference/search.
octokit: https://github.com/octokit/core.js
Octokit provides two approaches: Restful & GraphQL. For this scenario, GraphQL doesn't have much advantages than Restful, I would choose Restful. Below is their comparison.
- URL indicates the location of source, more semantical
- long history, industrial standard
- caching
- overfetching and underfetching
- The response is exactly what you described in query
- client-driven architecture, benefit the rapid iteration
- Lacks in-built caching mechanism
Using Flexbox & CSS3 to allow the page responsive, providing Desktop/Pad/Mobile experience to users. The layout of header/search-box/navigator can be changed according to the window size.
- consists of
< Prev
,Next >
, anditem button
. - 5 items per page by default.
- responsive with Desktop/Mobile
- integrated with throttling fetch
- Hooks
- Router + top-down data flow
const throttleFetch = throttle(fetch, wait)
throttleFetch.then(resolve => resolve)
export function throttle(fetch: RequestInterface<object>, wait: number) {
return function throttled(
route: keyof Endpoints | "GET /search/repositories?q={q}&per_page={per_page}",
options?: RequestParameters | undefined
): Promise<OctokitResponse<any, number>> {}
}
We attached many event listeners, and setInterval, those should be cleaned up at the right time.
- ErrorBoundary
Using CSS module to prevent css globle pollution: https://create-react-app.dev/docs/adding-a-css-modules-stylesheet/
useRef vs useState
: for form-input senario, best practice is using useRef instead of useState(with onClick) to prevent component frequent rendering.
All test is under src/__test__
, run npm run test
Writing tests can help you improve efficiency, ensure quality, avoid regression, etc. The front-end testing usually include: unit testing, component testing, integration test.
The testing coverage is pretty high, the UT/CT coverage is close to 100%.
The project shipped with ESLint, which can make your code style consistent, avoid errors, and improve code quality.
- Dark mode
- Light mode
- Aria-label
- High contrast
- RTL
-
Desktop
-
Mobile