-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Tulio Gabriel
committed
Mar 18, 2020
1 parent
bd99a41
commit cfa2ee8
Showing
5 changed files
with
186 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,63 @@ | ||
import React from 'react'; | ||
import { FaGithubAlt, FaPlus } from 'react-icons/fa'; | ||
/* eslint-disable react/state-in-constructor */ | ||
/* eslint-disable react/prefer-stateless-function */ | ||
import React, { Component } from 'react'; | ||
import { FaGithubAlt, FaPlus, FaSpinner } from 'react-icons/fa'; | ||
|
||
import { Container, Form, SubmitButton } from './styles'; | ||
|
||
export default function Main() { | ||
return ( | ||
<Container> | ||
<h1> | ||
<FaGithubAlt /> Repositórios | ||
</h1> | ||
|
||
<Form onSubmit={() => {}}> | ||
<input type="text" placeholder="Adicionar repositório" /> | ||
<SubmitButton disabled> | ||
<FaPlus color="#FFF" size={14} /> | ||
</SubmitButton> | ||
</Form> | ||
</Container> | ||
); | ||
import api from '../../services/api'; | ||
|
||
export default class Main extends Component { | ||
state = { | ||
newRepo: '', | ||
repositories: [], | ||
loading: false, | ||
}; | ||
|
||
handleInputChange = e => { | ||
this.setState({ newRepo: e.target.value }); | ||
}; | ||
|
||
handleSubmit = async e => { | ||
e.preventDefault(); | ||
this.setState({ loading: true }); | ||
const { newRepo, repositories } = this.state; | ||
const response = await api.get(`/repos/${newRepo}`); | ||
const data = { | ||
name: response.data.full_name, | ||
}; | ||
|
||
this.setState({ | ||
repositories: [...repositories, data], | ||
newRepo: '', | ||
loading: false, | ||
}); | ||
}; | ||
|
||
render() { | ||
const { newRepo, loading } = this.state; | ||
|
||
return ( | ||
<Container> | ||
<h1> | ||
<FaGithubAlt /> Repositórios | ||
</h1> | ||
<Form onSubmit={this.handleSubmit}> | ||
<input | ||
type="text" | ||
placeholder="Adicionar repositório" | ||
value={newRepo} | ||
onChange={this.handleInputChange} | ||
/> | ||
<SubmitButton loading={loading}> | ||
{loading ? ( | ||
<FaSpinner color="#FFF" size={14} /> | ||
) : ( | ||
<FaPlus color="#FFF" size={14} /> | ||
)} | ||
</SubmitButton> | ||
</Form> | ||
</Container> | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import axios from 'axios'; | ||
|
||
const api = axios.create({ | ||
baseURL: 'https://api.github.com', | ||
}); | ||
|
||
export default api; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters