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 11 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 @@ -7,6 +7,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",
"lodash": "^4.17.21",
Expand Down
48 changes: 35 additions & 13 deletions src/meta/play-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
DynamicRoutes,
SimpleLiveChat,
FlipCardEffect,
GitHubUserSearch,
} from "plays";

export const plays = [
Expand Down Expand Up @@ -391,19 +392,24 @@ export const plays = [
blog: "",
video: "",
language: "js",
}, {
id: 'pl-simple-live-chat',
name: 'Simple Live Chat',
description: 'Its a very simple live chat which is build using reactjs and firebase firestore',
component: () => {return <SimpleLiveChat />},
path: '/plays/simple-live-chat',
level: 'Intermediate',
tags: 'LiveChat,Firebase,React',
github: 'Angryman18',
cover: 'https://images.unsplash.com/photo-1522096823084-2d1aa8411c13?ixlib&#x3D;rb-1.2.1&amp;ixid&#x3D;MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto&#x3D;format&amp;fit&#x3D;crop&amp;w&#x3D;870&amp;q&#x3D;80',
blog: '',
video: '',
language: 'js'
},
TejasShekar marked this conversation as resolved.
Show resolved Hide resolved
{
id: "pl-simple-live-chat",
name: "Simple Live Chat",
description:
"Its a very simple live chat which is build using reactjs and firebase firestore",
component: () => {
return <SimpleLiveChat />;
},
path: "/plays/simple-live-chat",
level: "Intermediate",
tags: "LiveChat,Firebase,React",
github: "Angryman18",
cover:
"https://images.unsplash.com/photo-1522096823084-2d1aa8411c13?ixlib&#x3D;rb-1.2.1&amp;ixid&#x3D;MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&amp;auto&#x3D;format&amp;fit&#x3D;crop&amp;w&#x3D;870&amp;q&#x3D;80",
blog: "",
video: "",
language: "js",
},
{
id: "pl-flip-card-effect",
Expand All @@ -420,5 +426,21 @@ export const plays = [
blog: "",
video: "",
language: "js",
},
{
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
];
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>
);
};
130 changes: 130 additions & 0 deletions src/plays/github-user-search/GitHubUserSearch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import {getPlayById} from "meta/play-meta-util";

import PlayHeader from "common/playlists/PlayHeader";
import "./gitHubUserSearch.css";
import {useEffect, useState} from "react";
import axios from "axios";
import {GitHubUserCard} from "./GitHubUserCard";

function GitHubUserSearch(props) {
// Do not remove the below lines.
// The following code is to fetch the current play from the URL
const {id} = props;
const play = getPlayById(id);

// Your Code Start below.
const [query, setQuery] = useState("");
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 getUsers = async () => {
try {
setDataFetchStates((prev) => ({
...prev,
loading: true,
}));
const res = await axios.get(
`https://api.github.com/search/users?q=${query}&per_page=24`
);
setDataFetchStates((prev) => ({
...prev,
loading: false,
}));
setData((prev) => ({...prev, data: res.data.items}));
} catch (error) {
setDataFetchStates((prev) => ({
...prev,
loading: false,
error: true,
}));
setData((prev) => ({...prev, data: null}));
}
};

useEffect(() => {
(async function () {
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;
if (reset_count > 1)
setDataFetchStates((prev) => ({
...prev,
error: false,
}));
setData((prev) => ({
...prev,
remaining_searches: reset_count,
time_until_reset: reset_time,
}));
})();
}, [query, resData]);

return (
<>
<div className="play-details">
<PlayHeader play={play} />
<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
<input
className=" rounded-lg p-2 text-center"
type="search"
value={query}
placeholder="Enter query here"
onChange={(e) => setQuery(e.target.value)}
/>
<button
className="bg-[#00f2fe] p-2 rounded-xl disabled:text-gray-500 disabled:cursor-not-allowed disabled:bg-[#00bbc5]"
onClick={getUsers}
disabled={query === "" || dataFetchStates.error ? true : false}
>
Search
</button>
{!resData.remaining_searches < 1 && (
<p>No. of searches remaining : {resData.remaining_searches}</p>
)}
{dataFetchStates.loading && <h2> L O A D I N G . . .</h2>}
{dataFetchStates.error && (
<h2>
You have exhausted your search limit. Try again after{" "}
koustov marked this conversation as resolved.
Show resolved Hide resolved
{resData.time_until_reset}
</h2>
)}
{resData?.data?.length === 0 && (
<h1 className="text-3xl text-center">
No matching GitHub User Profiles
koustov marked this conversation as resolved.
Show resolved Hide resolved
</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;
27 changes: 27 additions & 0 deletions src/plays/github-user-search/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# GitHub User Search

A simple ReactJS application to search for GitHub users.
koustov marked this conversation as resolved.
Show resolved Hide resolved

## Play Demographic

- Language: js
- Level: Beginner

## Creator Information

- User: TejasShekar
- Gihub Link: https://github.com/TejasShekar
- Blog:
- Video:

## Implementation Details
koustov marked this conversation as resolved.
Show resolved Hide resolved

Update your implementation idea and details here

## Consideration

Update all considerations(if any)

## Resources

Update external resources(if any)
1 change: 1 addition & 0 deletions src/plays/github-user-search/gitHubUserSearch.css
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/* enter stlyes here */
TejasShekar marked this conversation as resolved.
Show resolved Hide resolved
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/src/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
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: [],
}
};