Skip to content

Commit

Permalink
renderd bots
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinNyaga committed Jul 28, 2023
1 parent 1e903a7 commit dd254d8
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 16 deletions.
2 changes: 1 addition & 1 deletion public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
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>React App</title>
<title>Bot Battlr</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
32 changes: 17 additions & 15 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
import logo from './logo.svg';
import React, {useState, useEffect} from 'react';
import BotCollection from './components/BotCollection';

import './App.css';

function App() {
//Declared variables for rendering the bots
const [bots, setBots] = useState([]);


//Fetching the bot data from deployed db.json
useEffect(() => {
fetch('https://bot-app-data.onrender.com/bots')
.then((response) => response.json())
.then((data) => setBots(data))
.catch((error) => console.error('Error fetching data:', error));
}, []);

return (
//Rendering bots on the web page
<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>
<BotCollection bots={bots} />
</div>
);
}
Expand Down
23 changes: 23 additions & 0 deletions src/components/BotCollection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from "react";

export default function BotCollection({bots}){
//Renderd bots
return(
<div>
{bots.map((bot) => (
<div key={bot.id}>
<img src={bot.avatar_url}/>
<h3>Bot Name: {bot.name}</h3>
<p>Class : {bot.bot_class}</p>
<p>Catch Phrase : {bot.catchphrase}</p>
<p>Armor : {bot.armor}</p>
<p>Health : {bot.health}</p>
<p>Damage : {bot.damage}</p>
<p>Created At : {bot.created_at}</p>
<p>Updated at : {bot.updated_at}</p>

</div>
))}
</div>
)
}
Empty file added src/components/YourBotArmy.js
Empty file.

0 comments on commit dd254d8

Please sign in to comment.