Skip to content
Snippets Groups Projects
Commit 4a6a0281 authored by Ari-Pekka Kauppinen's avatar Ari-Pekka Kauppinen
Browse files

trying to add MainPage to gitlab

parent a348db81
No related branches found
No related tags found
2 merge requests!4Merge develop to master,!2Merge MainPage to Develop
This diff is collapsed.
...@@ -2,6 +2,7 @@ import React, { Component } from 'react'; ...@@ -2,6 +2,7 @@ import React, { Component } from 'react';
import './App.css'; import './App.css';
import Start from "../src/components/Start.js" import Start from "../src/components/Start.js"
import Cookies from 'universal-cookie'; import Cookies from 'universal-cookie';
import MainPage from "../src/components/MainPage.js"
class App extends Component { class App extends Component {
...@@ -14,8 +15,7 @@ class App extends Component { ...@@ -14,8 +15,7 @@ class App extends Component {
if(cookies.get('firstPage') === "true"){ if(cookies.get('firstPage') === "true"){
return ( return (
<div className="App"> <div className="App">
{/* TODO: main view*/} <MainPage />
<p>cookie found! load main page here</p>
</div> </div>
); );
} }
......
import React, { Component } from 'react';
import "../styles/MainPage.css"
class MainPage extends Component {
constructor(props) {
super(props);
this.state = {
currentWeather : [],
isLoaded: false,
error: null
}
}
componentDidMount(){
//token for API request
const token = "&APPID=dc7912235b38897f91307afe6e1162c3"
const unit = "&units=metric"
//API address
const apiUrl ='http://api.openweathermap.org/data/2.5/weather?q=Tampere,fi'
fetch(apiUrl+token+unit)
.then(res => res.json())
.then(
(result) => {
const tempArr =[]
tempArr.push(result.main.temp)
tempArr.push(result.wind.speed)
this.setState({
isLoaded: true,
currentWeather: tempArr
})
console.log(result)
},
(error) => {
this.setState({
isLoaded: true,
error
})
}
)
}
render() {
const {currentWeather, isLoaded} = this.state
if(isLoaded){
return (
<div className="weatherBox">
{/* <ul>
<li>testdata</li>
<li>testdata</li>
<li>testdata</li>
</ul>
*/}
<ul>
<li>Lämpötila: { JSON.stringify(currentWeather[0]) }C</li>
<li>Tuuli: { JSON.stringify(currentWeather[1]) }m/s</li>
<li>Tuntuu kuin: ?</li>
</ul>
</div>
);
}
else{
return <p>Lataa...</p>
}
}
}
export default MainPage;
ul{
list-style: none;
box-sizing: content-box;
width: 300px;
height: 100px;
padding: 30px;
border: solid;
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment