A simple React app that searches Github.
https://github-search-pi.now.sh/
yarn start
# Deploy using Vercel / Zeit (https://vercel.com/)
now
- Display repository’s
id
,name
,watchers_count
. - Sort the results by the number of stars.
- Have a search input that will show results (from all possible repositories) to those that have its name matches the search field.
- Any 3rd-party libraries can be used if necessary.
- No need to focus on the UX of the page.
- Ensure we can get the right data via the Github API.
- Generate a new React app using
create-react-app
. - Create basic component structure; We'll need a search box, search result list, spinner, etc.
- Call API and render result (unstyled).
- Implement search.
- Implement pagination.
- Make things "purrty".
-
Do a quick curl call to see we can get the right data.
We want to make sure we get the search results in the correct order.
curl -s 'https://api.github.com/search/repositories?q=ace&sort=stars&order=desc' | grep stargazers_count
# Output:
# "stargazers_count": 21482,
# "stargazers_count": 3568,
# "stargazers_count": 2458,
# "stargazers_count": 2165,
# .. (27 more repos) ..
- Generate an app using
create-react-app
# TypeScript FTW.
yarn create react-app --typescript github-search
cd github-search
# Boldly upgrade to latest everything (only the brave):
yarn upgrade-interactive --latest
# A must-have:
yarn add styled-components @types/styled-components
-
Create a "decent" component structure
App.tsx
holds our main app.components/SearchBox.tsx
has our search input field and search button.components/GithubSearchResult.tsx
is search result list.components/SpinningOctocat.tsx
is our home-made spinner.github.ts
contains our Github API access logic, implemented entirely as a reusable React effect hook.
We use
styled-components
everywhere! ✌️ -
Call API and render result (unstyled)
We just want to make a API call, e.g. inside a React effect hook, and dump the data to the screen.
This basically just confirms that we're wired up everything correctly.
It's probably a good idea to save the Github search response to a local file and use the data during development to speed things up a bit, e.g. not having to perform an actual search API call everytime you reload the app.
-
Implement search.
We'll create a separate
SearchBox
andGithubSearchResult
components to keep things nice and orderly. -
Implement pagination.
Github returns a
link
HTTP header containing pagination links for most of it's API endpoints. We'll extract and use those in our app. -
Make things "purrty".
Add some bling to make our app look somewhat less crappy.