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

React Challenge #7

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "react-app"
}
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
.DS_Store
node_modules
dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*
# See https://help.github.com/ignore-files/ for more about ignoring files.

# dependencies
/node_modules

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,8 @@
# react-challenge
# Github Card
## About
A github card profile, made with React and Github API.

## How to Use
- Fork or download
- npm install
- npm start
1 change: 1 addition & 0 deletions README.old.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# react-challenge
18 changes: 18 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"name": "react-challenge-1",
"version": "0.1.0",
"private": true,
"dependencies": {
"react": "^15.6.1",
"react-dom": "^15.6.1"
},
"devDependencies": {
"react-scripts": "1.0.10"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.

Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Github User Info</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "192x192",
"type": "image/png"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
141 changes: 141 additions & 0 deletions src/component/App.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
@import url(https://fonts.googleapis.com/css?family=Titillium+Web:400,700,600);
body {
background: #ecf0f1;
font-family: "Titillium Web", sans-serif;
font-weight: 400;
}

* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
*:active, *:focus {
border: 0;
outline: 0;
}

a {
text-decoration: none;
display: inline-block;
}

#card {
width: 25rem;
margin: auto;
overflow: hidden;
position: absolute;
top: 50%;
left: 50%;
-webkit-transform: translateX(-50%) translateY(-50%);
transform: translateX(-50%) translateY(-50%);
}

.search--box label {
position: relative;
}
.search--box label:after {
position: absolute;
content: "";
border-right: .625rem solid transparent;
border-left: .625rem solid transparent;
border-bottom: .625rem solid #fff;
bottom: -1.0625rem;
right: 50%;
margin-right: -0.3125rem;
}
.search--box input[type='search'] {
width: 100%;
font: 1rem "Titillium Web", sans-serif;
color: #1a4e8e;
border: 0;
padding: .75rem .9375rem .9375rem;
background: #e6ebed;
border-radius: .3125rem .3125rem 0 0;
text-align: center;
box-sizing: border-box;
}

.notfound {
background: #fff;
padding: 1.875rem;
text-align: center;
}
.notfound h2 {
font-size: 2rem;
color: #2368bd;
margin-bottom: .625rem;
}
.notfound p {
font-size: 1rem;
color: #a3b6bb;
}

.github--profile {
width: 100%;
}
.github--profile__info {
background: #fff;
text-align: center;
padding: 1.875rem .9375rem;
}
.github--profile__info img {
width: 6.25rem;
height: 6.25rem;
border-radius: 50%;
display: block;
box-shadow: 0 0 0.0625rem rgba(0, 0, 0, 0.5);
}
.github--profile__info h2 a {
font-size: 1.65rem;
color: #2368bd;
}
.github--profile__info h3 {
font-size: 1.1885rem;
color: #bdcbce;
}
.github--profile__state {
background: #1a4e8e;
text-align: center;
padding: 1.875rem .9375rem;
border-radius: 0 0 .3125rem .3125rem;
}
.github--profile__state ul {
direction: ltr;
}
.github--profile__state li {
list-style: none;
display: inline-block;
margin-right: 1rem;
}
.github--profile__state li:last-child {
margin-right: 0;
}
.github--profile__state a {
color: #fff;
}
.github--profile__state i {
font-size: 1.5rem;
font-weight: 700;
font-style: normal;
display: block;
}
.github--profile__state span {
font-size: .844rem;
letter-spacing: .0625rem;
color: #2776d7;
}

.author {
font-size: .9rem;
font-weight: 400;
color: #b4c4c8;
position: absolute;
bottom: 3%;
left: 50%;
-webkit-transform: translateX(-50%);
transform: translateX(-50%);
}
.author a {
color: #2368bd;
}
65 changes: 65 additions & 0 deletions src/component/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import React from 'react';

import './App.css';
import SearchProfile from './Search';
import Profile from './Profile';

const API = 'https://api.github.com/users';

class App extends React.Component {
constructor(props) {
super(props)
this.state = {
username: 'raynormw',
name:'',
avatar:'',
location:'',
repos:'',
followers: '',
following:'',
homeUrl:'',
notFound:''
}
}

_fetchProfile(username) {
let url = `${API}/${username}`;
fetch(url)
.then((res) => res.json() )
.then((data) => {
console.log(data);
this.setState({
username: data.login,
name: data.name,
avatar: data.avatar_url,
location: data.location,
repos: data.public_repos,
followers: data.followers,
following: data.following,
homeUrl: data.html_url,
notFound: data.message
})
})
.catch((error) => console.log('Uh oh! There Is A Problem..') )
}

componentDidMount() {
this._fetchProfile(this.state.username);
}

render() {
return (
<div className="App">
<div>
<section id="card">
<SearchProfile fetchProfile={this._fetchProfile.bind(this)}/>
<Profile data={this.state} />
</section>
<span className="author">GitHub Card With ReactJs - Created By <a href="http://tirtawiryaputra.com" target="_blank" rel="noopener noreferrer" title="Tirta Wirya Putra">Tirta Wirya Putra</a></span>
</div>
</div>
);
}
}

export default App;
8 changes: 8 additions & 0 deletions src/component/App.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';

it('renders without crashing', () => {
const div = document.createElement('div');
ReactDOM.render(<App />, div);
});
40 changes: 40 additions & 0 deletions src/component/Profile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import React from 'react';

export default class Profile extends React.Component {
render() {
let data = this.props.data;
let followers = `${data.homeUrl}/followers`;
let repositories = `${data.homeUrl}?tab=repositories`;
let following = `${data.homeUrl}/following`;
if (data.notFound === 'Not Found')
return (
<div className="notfound">
<h2>Oops !!!</h2>
<p>The Component Couldn't Find The You Were Looking For . Try Again </p>
</div>
);
else
return (
<section className="github--profile">
<div className="github--profile__info">
<a href={data.homeUrl} target="_blank" title={data.name || data.username}><img src={data.avatar} alt={data.username}/></a>
<h2><a href={data.homeUrl} title={data.username} target="_blank">{data.name || data.username}</a></h2>
<h3>{data.location || "Time is illussion"}</h3>
</div>
<div className="github--profile__state">
<ul>
<li>
<a href={followers} target="_blank" title="Number Of Followers"><i>{data.followers}</i><span>Followers</span></a>
</li>
<li>
<a href={repositories} target="_blank" title="Number Of Repositoriy"><i>{data.repos}</i><span>Repositoriy</span></a>
</li>
<li>
<a href={following} target="_blank" title="Number Of Following"><i>{data.following}</i><span>Following</span></a>
</li>
</ul>
</div>
</section>
);
}
}
Loading