Skip to content

Commit

Permalink
Initial working example
Browse files Browse the repository at this point in the history
  • Loading branch information
SeedyROM committed Jun 22, 2019
1 parent d045acd commit af67475
Show file tree
Hide file tree
Showing 10 changed files with 525 additions and 82 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.19.0",
"bulma": "^0.7.5",
"bulma-react-components": "^1.0.2",
"react": "^16.8.6",
"react-bulma-components": "2.3.0",
"react-dom": "^16.8.6",
"react-scripts": "3.0.1"
},
Expand Down
38 changes: 5 additions & 33 deletions src/App.css
Original file line number Diff line number Diff line change
@@ -1,33 +1,5 @@
.App {
text-align: center;
}

.App-logo {
animation: App-logo-spin infinite 20s linear;
height: 40vmin;
pointer-events: none;
}

.App-header {
background-color: #282c34;
min-height: 100vh;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
font-size: calc(10px + 2vmin);
color: white;
}

.App-link {
color: #61dafb;
}

@keyframes App-logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
.App-characters {
display: grid;
grid-template-columns: repeat(4, 1fr);
grid-gap: 2em;
}
44 changes: 26 additions & 18 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
import React from 'react';
import logo from './logo.svg';
import React, { useState } from 'react';
import { Button } from "react-bulma-components";

import useFetchCharacters from './hooks/useFetchCharacters';
import Character from './Character';

import './App.css';

function App() {
const App = () => {
const [page, setPage] = useState(1);
const [loading, characters] = useFetchCharacters(page);

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div>
<div>Page #{page}</div>
<div>
<Button color="info" onClick={() => setPage(Math.max(1, page - 1))}>
Previous Page
</Button>
<Button color="info" onClick={() => setPage(page + 1)}>
Next Page
</Button>
</div>
{loading && <div>Loading...</div>}
<div className="App-characters">
{!loading && characters.map((character) => (
<Character key={character.id} data={character} />
))}
</div>
</div>
);
}
Expand Down
9 changes: 0 additions & 9 deletions src/App.test.js

This file was deleted.

26 changes: 26 additions & 0 deletions src/Character.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import React from "react";

import { Card, Media, Content, Heading } from "react-bulma-components";

const Character = props => (
<Card>
<Card.Image
size="1by1"
src={props.data.image}
/>
<Card.Content>
<Media>
<Media.Item>
<Heading size={4}>{props.data.name}</Heading>
</Media.Item>
</Media>
<Content>
<p>{props.data.status}</p>
<p><b>{props.data.species}</b>: <i>{props.data.gender}</i></p>
</Content>
</Card.Content>
</Card>
);


export default Character;
24 changes: 24 additions & 0 deletions src/hooks/useFetchCharacters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { useState, useEffect } from 'react';
import axios from 'axios';

const useFetchCharacters = (page = 1) => {
const [characters, setCharacters] = useState([]);
const [loading, setLoading] = useState(true);

useEffect(() => {
const fetchData = async () => {
setLoading(true);
const { data } = await axios.get(`https://rickandmortyapi.com/api/character/?page=${page}`);
console.log(data);

setCharacters(data.results);
setLoading(false);
}

fetchData();
}, [page]);

return [loading, characters];
}

export default useFetchCharacters;
1 change: 1 addition & 0 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
body {
margin: 0;
padding: 2em;
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen",
"Ubuntu", "Cantarell", "Fira Sans", "Droid Sans", "Helvetica Neue",
sans-serif;
Expand Down
5 changes: 4 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';

import App from './App';
import * as serviceWorker from './serviceWorker';

import 'react-bulma-components/dist/react-bulma-components.min.css';
import './index.css';

ReactDOM.render(<App />, document.getElementById('root'));

// If you want your app to work offline and load faster, you can change
Expand Down
7 changes: 0 additions & 7 deletions src/logo.svg

This file was deleted.

Loading

0 comments on commit af67475

Please sign in to comment.