Skip to content

Commit

Permalink
connected to OpenData solar system API for planetary body info
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristoGrab committed Feb 7, 2023
1 parent 17a1408 commit e216ef2
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 0 deletions.
56 changes: 56 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"@testing-library/jest-dom": "^5.16.5",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.3.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.8.1",
Expand Down
Binary file added public/sun.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,28 @@
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { useState } from 'react'
import './App.css';
import axios from 'axios';
import Navigation from './components/Navigation';
import Viewport from './components/Viewport';
import InfoCard from "./components/InfoCard";
import { useEffect } from "react";
import normalizeSolarSystemData from "./functions/normalizeData";

function App() {

const [data, setData] = useState(null)

const fetchData = async () => {
return axios.get("https://api.le-systeme-solaire.net/rest/bodies/")
.then((response) => setData(normalizeSolarSystemData(response.data)))
}

useEffect(() => {
fetchData()
}, [])

console.log(data)

return (
<>
<BrowserRouter>
Expand Down
2 changes: 2 additions & 0 deletions src/components/InfoCard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const InfoCard = () => {
return navigate('/')
}



return (
<section className="info-card">
<div className="infocard-title">
Expand Down
12 changes: 12 additions & 0 deletions src/functions/normalizeData.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const normalizeSolarSystemData = (data) => {
let dataObject = {}

data.bodies.forEach(body => {
dataObject[body.englishName] = body
})

return dataObject

}

export default normalizeSolarSystemData;

0 comments on commit e216ef2

Please sign in to comment.