Commit ade72aac authored by Solveig Hergot Langås's avatar Solveig Hergot Langås
Browse files

Merge remote-tracking branch 'origin/master' into Explore-page-+-scroll

parents bfbe711f dde634a0
export const setPage = (page) => { export const setPage = (page) => {
return (dispatch, getState) => { return (dispatch, getState) => {
console.log("INNI ACTION med page: ", page) //console.log("INNI ACTION med page: ", page)
dispatch({ dispatch({
type: 'SET_PAGE', page type: 'SET_PAGE', page
......
import Axios from "axios" import axios from "axios"
const createURL = (input) => { const createURL = (input) => {
const API_URL = "http://it2810-10.idi.ntnu.no:3001/api/" const API_URL = "http://it2810-10.idi.ntnu.no:3001/api/"
...@@ -12,22 +9,19 @@ const createURL = (input) => { ...@@ -12,22 +9,19 @@ const createURL = (input) => {
return API_URL + "search/" + input return API_URL + "search/" + input
} }
if(typeof input == 'number'){ if(typeof input == 'number'){
return API_URL + "fiveMostPopular" return API_URL + "fiveMostPopular"
} }
} }
export const GetData = (input) => { export const GetData = async (input) => {
const url = createURL(input) const url = createURL(input)
console.log("Her er url: ",url) return await axios.get(url).catch((err) => {console.log("Error from axios: ", err)})
return Axios.get(url);
} }
/*
const UpdatePopulatiry =(destinationID, newPopularity) => { export const UpdatePopulatiry =(destinationID, newPopularity) => {
Axios.post(API_URL + "updateData", { axios.post("http://it2810-10.idi.ntnu.no:3001/api/updateData", {
id: destinationID, id: destinationID,
update: { popularity: newPopularity }, update: { popularity: newPopularity },
}) })
} }
*/
\ No newline at end of file
import React, { Component } from 'react'; import React, { Component } from 'react';
import { StyleSheet, Text, View, Alert, TouchableHighlight, Image } from 'react-native'; import { StyleSheet, Text, View, Alert, TouchableHighlight, Image, Dimensions } from 'react-native';
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import { GetData } from '../api/fetchers' import { GetData, UpdatePopulatiry } from '../api/fetchers'
import { ScrollView } from 'react-native-gesture-handler';
class Card extends Component { class Card extends Component {
state ={ state ={
data: [], data: [],
} }
componentDidMount(){ componentWillMount(){
this.checkPage() this.checkPage()
} }
setData(input) {
GetData(input).then((res) => this.setState({data: res.data.data}))
}
checkPage(){ checkPage(){
if(this.props.page === "Home"){ if(this.props.page === "Home"){
var locations = GetData(5) this.setData(5)
locations.then((data) => {console.log(data);this.setState({data: data})}) if(this.props.page === "Explore"){
if(this.props.word === "all"){
if(this.props.continent === 'all'){
this.setData()
}else{
this.setData(this.props.continent)}
}else if(this.props.continent === 'all'){
this.setData(this.props.word)
}else{this.setData(this.props.continent + "/" + this.props.word)}
}
} }
} }
render(){ render(){
const styles = StyleSheet.create({ const styles = StyleSheet.create({
container: { container: {
borderRadius: 7, borderRadius: 7,
...@@ -35,31 +49,42 @@ class Card extends Component { ...@@ -35,31 +49,42 @@ class Card extends Component {
backgroundColor: 'white', backgroundColor: 'white',
margin: 10, margin: 10,
padding: 10, padding: 10,
alignItems: "center" alignItems: "center",
height: 250,
},
Image: {
width: 300,
height: 200,
resizeMode: 'contain',
alignSelf: "center"
} }
}) })
const { data } = this.state const { data } = this.state
const dataCards = data.map(dat => {
return( return (
<View> <TouchableHighlight key={dat._id} underlayColor = 'white' onPress = {() => Alert.alert("HEI")}>
<TouchableHighlight underlayColor = 'transparent' onPress = {() => Alert.alert("HEI")}> <View style = {styles.container}>
<View style = {styles.container}> <View><Image style={styles.Image} source={{uri: dat.img}}/></View>
<View><Text> HEisann!</Text></View> <View><Text> {dat.name} </Text></View>
<View><Text> HER SDDWJROJ FSKD </Text></View> </View>
</View> </TouchableHighlight>
</TouchableHighlight> );
})
</View> return (
<ScrollView>
{dataCards}
</ScrollView>
)} )}
} }
const mapStateToProps = (state) => { //give us accsess to the data in store const mapStateToProps = (state) => { //give us accsess to the data in store
return { return {
page: state.page.page, page: state.page.page,
word: state.filter.searchWord,
continent: state.filter.continent
} }
}; };
......
import React, { Component } from 'react'; import React, { Component } from 'react';
import { Text, View } from 'react-native'; import { Text, View, ScrollView } from 'react-native';
import Card from '../components/Card' import Card from '../components/Card'
import { createStore, applyMiddleware } from 'redux'; import { createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers/'; import rootReducer from '../reducers/';
...@@ -18,15 +18,21 @@ class HomePage extends Component{ ...@@ -18,15 +18,21 @@ class HomePage extends Component{
render(){ render(){
return( return(
<View style={{ <ScrollView style={{
padding: 36, padding: 36,
flex: 1 flex: 1
}}> }}>
<Text style={{fontSize: 28, textAlign: "center", padding: 8}}>Welcome to Dream Destinations</Text> <Text style={{fontSize: 28, textAlign: "center", padding: 8}}>Welcome to Dream Destinations</Text>
<Text style={{fontSize: 20, textAlign: "center", padding: 8}}>Click here to see a wordcloud showing the most popular locations</Text> <Text style={{fontSize: 20, textAlign: "center", padding: 8}}>Click here to see a wordcloud showing the most popular locations</Text>
<Text style={{fontSize: 16, textAlign: "center", padding: 8}}>Below you see the five most popular places</Text> <Text style={{fontSize: 16, textAlign: "center", padding: 8}}>Below you see the five most popular places</Text>
<Card /> <Card/>
</View> </ScrollView>
/*
<Provider store = {store}>
<Test/>
</Provider>
*/
) )
} }
} }
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment