Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat new react-play: GitHub User Search #309

Merged
merged 35 commits into from
Jun 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
c50a738
build: added axios as dependency
TejasShekar Jun 14, 2022
47e0d37
initial commit
TejasShekar Jun 14, 2022
05c2857
feat: add user card component
TejasShekar Jun 14, 2022
76b4d36
feat: add full GitHub user search functionality
TejasShekar Jun 14, 2022
8e42548
styles: add media queries for smaller screen
TejasShekar Jun 14, 2022
9df0796
fix: add loader and error handling
TejasShekar Jun 14, 2022
d122db0
styles: update styles for media queries
TejasShekar Jun 14, 2022
71fcd96
refactor: merged two states into one
TejasShekar Jun 14, 2022
9718a05
refactor: reduced the data states
TejasShekar Jun 14, 2022
d2c59c9
refactor: minor refactor
TejasShekar Jun 14, 2022
6438dff
Update GitHubUserSearch.jsx
TejasShekar Jun 14, 2022
72acd70
Add thumbnail image
TejasShekar Jun 15, 2022
87b9b08
build: downgrade react-snap version
TejasShekar Jun 15, 2022
76688ed
refactor: remove simple live chat play
TejasShekar Jun 15, 2022
caf3735
refactor: remove simple live chat
TejasShekar Jun 15, 2022
a523178
Revert "refactor: remove simple live chat"
TejasShekar Jun 15, 2022
fd00f5d
Revert "refactor: remove simple live chat play"
TejasShekar Jun 15, 2022
b8cc34d
Revert "build: downgrade react-snap version"
TejasShekar Jun 15, 2022
c2c085a
refactor: removed API calls for rate limit fetching
TejasShekar Jun 16, 2022
41ce0d6
fix: Added rate limit API calls
TejasShekar Jun 16, 2022
c3d912a
feat: added input for response size
TejasShekar Jun 16, 2022
41358a4
Delete cover_image.png
TejasShekar Jun 16, 2022
4cdceeb
Update Readme.md
TejasShekar Jun 16, 2022
1d4df71
add cover image
TejasShekar Jun 16, 2022
e707c4d
fix: null time issue on error msg
TejasShekar Jun 16, 2022
ae41127
refactor: remove disable state from btn
TejasShekar Jun 16, 2022
10a22af
refactor: minor changes
TejasShekar Jun 16, 2022
bc23eac
Merge branch 'main' of https://github.com/reactplay/react-play
TejasShekar Jun 17, 2022
308b541
remove stylesheet
TejasShekar Jun 17, 2022
b70763c
fix: import error
TejasShekar Jun 17, 2022
5b94372
Merge branch 'main' of https://github.com/reactplay/react-play
TejasShekar Jun 20, 2022
086aea0
refactor: negligible changes
TejasShekar Jun 20, 2022
aabf449
Merge branch 'main' of https://github.com/reactplay/react-play
TejasShekar Jun 22, 2022
735334b
Merge branch 'main' of https://github.com/reactplay/react-play
TejasShekar Jun 27, 2022
4fb5beb
fix: remove id and getPlayById
TejasShekar Jun 27, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"@types/lodash": "^4.14.182",
"@types/react": "^18.0.6",
"@types/react-dom": "^18.0.2",
"axios": "^0.27.2",
"date-fns": "^2.28.0",
"firebase": "^9.8.2",
"graphql": "^16.5.0",
Expand Down
21 changes: 19 additions & 2 deletions src/meta/play-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ import {
DynamicRoutes,
SimpleLiveChat,
FlipCardEffect,
//import play here
GitHubUserSearch,
//import play here
} from "plays";

export const plays = [
Expand Down Expand Up @@ -427,5 +428,21 @@ export const plays = [
video: "",
language: "js",
},
//replace new play item here
{
id: "pl-github-user-search",
name: "GitHub User Search",
description: "A simple ReactJS application to search for GitHub users.",
component: () => {
return <GitHubUserSearch />;
},
path: "/plays/github-user-search",
level: "Beginner",
tags: "JSX,Tailwind,useState,Axios",
github: "TejasShekar",
cover: "",
koustov marked this conversation as resolved.
Show resolved Hide resolved
blog: "",
video: "",
language: "js",
},
//replace new play item here
];
3 changes: 1 addition & 2 deletions src/plays/expanding-cards/ExpandingCards.jsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
import PlayHeader from "common/playlists/PlayHeader";
import "./ExpandingCards.css";
import { useState } from "react";
import {useState} from "react";
import data from "./Expanding-Card-Images";

function ExpandingCards(props) {

// Your Code Start below.

const [activeCard, setActiveCard] = useState(0);
Expand Down
15 changes: 15 additions & 0 deletions src/plays/github-user-search/GitHubUserCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
export const GitHubUserCard = ({username, avatar, link}) => {
return (
<a
href={link}
target="_blank"
rel="noreferrer"
style={{backgroundImage: `url(${avatar})`}}
className=" bg-cover bg-center h-[15rem] w-[15rem] rounded-lg flex flex-col justify-end"
>
<h1 className="text-2xl text-center xs:bg-black p-2 w-full rounded-lg text-white lg:h-full lg:opacity-0 lg:hover:opacity-80 lg:hover:bg-black ">
{username}
</h1>
</a>
);
};
162 changes: 162 additions & 0 deletions src/plays/github-user-search/GitHubUserSearch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
import PlayHeader from "common/playlists/PlayHeader";
import {useState} from "react";
import axios from "axios";
import {GitHubUserCard} from "./GitHubUserCard";

function GitHubUserSearch(props) {
// Your Code Start below.
const [input, setInput] = useState({
query: "",
response_size: 30,
});
const [resData, setData] = useState({
data: null,
remaining_searches: 0,
time_until_reset: null,
});
const [dataFetchStates, setDataFetchStates] = useState({
loading: false,
error: false,
});

const getResetTime = (time) => {
const newTime = new Date(time * 1000);
return newTime.toLocaleTimeString();
};

const getRateLimitData = async () => {
const rate_limit = await axios.get("https://api.github.com/rate_limit");
const reset_time = getResetTime(rate_limit.data.resources.search.reset);
const reset_count = rate_limit.data.resources.search.remaining - 1;
if (reset_count > 1)
setDataFetchStates((prev) => ({
...prev,
error: false,
}));
setData((prev) => ({
...prev,
remaining_searches: reset_count,
time_until_reset: reset_time,
}));
};

const getUsersData = async () => {
const res = await axios.get(
`https://api.github.com/search/users?q=${input.query}&per_page=${input.response_size}`
);
setData((prev) => ({...prev, data: res.data.items}));
};

const getGitHubData = async () => {
try {
setDataFetchStates((prev) => ({
...prev,
loading: true,
}));
await getRateLimitData();
koustov marked this conversation as resolved.
Show resolved Hide resolved
await getUsersData();
setDataFetchStates((prev) => ({
...prev,
loading: false,
}));
} catch (error) {
setDataFetchStates((prev) => ({
...prev,
loading: false,
error: true,
}));
setData((prev) => ({...prev, data: null}));
}
};

return (
<>
<div className="play-details">
<PlayHeader play={props} />
<div className="play-details-body">
{/* Your Code Starts Here */}
<div className=" w-full flex items-center justify-center flex-col gap-4">
koustov marked this conversation as resolved.
Show resolved Hide resolved
<form
className="flex flex-col gap-2"
onSubmit={(e) => e.preventDefault()}
>
<label htmlFor="user_name" className="text-center">
Who are you searching for ?{" "}
</label>
<input
id="user_name"
className=" rounded-lg p-2 text-center"
type="search"
inputMode="text"
value={input.query}
placeholder="Enter query here"
onChange={(e) =>
setInput((prev) => ({...prev, query: e.target.value}))
}
required
autoFocus
/>
<label htmlFor="response_size">
Maximum number of results you want to see at once:
</label>
<input
id="response_size"
className=" rounded-lg p-2 text-center"
type="number"
inputMode="numeric"
min="1"
max="100"
value={input.response_size}
onChange={(e) =>
setInput((prev) => ({...prev, response_size: e.target.value}))
}
/>
<p className="text-xs text-neutral-500 text-center">
Default value is 30
</p>
<button
type="submit"
className="bg-[#00f2fe] p-2 rounded-xl disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-[#00bbc5]"
onClick={() => {
input.query !== "" && getGitHubData();
}}
>
Search
</button>
</form>
{resData.remaining_searches >= 0 && (
<p>No. of searches remaining : {resData.remaining_searches}</p>
)}
{dataFetchStates.loading && <h2> L O A D I N G . . .</h2>}

<h2 className=" text-red-500">
{dataFetchStates.error &&
`You have exhausted your search limit. Try again after ${resData.time_until_reset}`}
</h2>

{resData?.data?.length === 0 && (
<h1 className="text-3xl text-center">
No matching GitHub User Profile
</h1>
)}
{!dataFetchStates.error && (
<div className="grid gap-2 grid-cols-[repeat(auto-fit,minmax(15rem,1fr))] w-full place-items-center">
{resData?.data?.map(({id, login, avatar_url, html_url}) => (
<GitHubUserCard
key={id}
username={login}
avatar={avatar_url}
link={html_url}
/>
))}
</div>
)}
</div>
{/* Your Code Ends Here */}
</div>
</div>
</>
);
}

export default GitHubUserSearch;
23 changes: 23 additions & 0 deletions src/plays/github-user-search/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# GitHub User Search

A simple ReactJS application to search for GitHub users. You can use this app to find users on GitHub by entering your search query and the number of profiles you want to see for each search.

The results are arranged in the default order of most matching to least matching User name.

## Play Demographic

- Language: JS
- Level: Beginner

## Creator Information

- User: Tejas Shekar
- GitHub Link: https://github.com/TejasShekar

## Consideration

- GitHub Search API has a default response size of 30 when user does not input any value for the response size.

## Resources

[GitHub Search API](https://docs.github.com/en/rest/search)
Binary file added src/plays/github-user-search/cover.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions src/plays/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ export { default as DynamicRoutes } from "plays/dynamic-routes/DynamicRoutes";
export { default as Quizeo } from "plays/quizeo/Quizeo";
export { default as SimpleLiveChat } from 'plays/simple-live-chat/SimpleLiveChat';
export { default as FlipCardEffect } from 'plays/flip-card-effect/FlipCardEffect';
export { default as GitHubUserSearch } from 'plays/github-user-search/GitHubUserSearch';
//add export here
2 changes: 1 addition & 1 deletion src/plays/simple-live-chat/firebase.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { initializeApp } from "firebase/app";
import {initializeApp} from "firebase/app";

const firebaseConfig = {
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
Expand Down
25 changes: 21 additions & 4 deletions tailwind.config.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,26 @@
module.exports = {
content: [
"./src/**/*.{js,jsx,ts,tsx}",
],
content: ["./src/**/*.{js,jsx,ts,tsx}"],
theme: {
screens: {
koustov marked this conversation as resolved.
Show resolved Hide resolved
xs: {min: "310px"},
// => @media (min-width: 640px and max-width: 767px) { ... }

sm: {min: "640px"},
// => @media (min-width: 640px and max-width: 767px) { ... }

md: {min: "768px"},
// => @media (min-width: 768px and max-width: 1023px) { ... }

lg: {min: "1024px"},
// => @media (min-width: 1024px and max-width: 1279px) { ... }

xl: {min: "1280px"},
// => @media (min-width: 1280px and max-width: 1535px) { ... }

"2xl": {min: "1536px"},
// => @media (min-width: 1536px) { ... }
},
extend: {},
},
plugins: [],
}
};