Commit 1c106c1d authored by Maroš Dovec's avatar Maroš Dovec
Browse files

fixes

parent c459118a
import React, { useEffect, useState } from "react";
import { Button, View, Image, Text, StyleSheet, TextInput, Pressable, KeyboardAvoidingView, TouchableWithoutFeedback, Keyboard, SafeAreaView, ScrollView, TouchableOpacity } from "react-native";
import {
Button, View, Image, Text, StyleSheet, TextInput, Pressable,
KeyboardAvoidingView, TouchableWithoutFeedback, Keyboard, SafeAreaView, ScrollView, TouchableOpacity,
ActivityIndicator
} from "react-native";
import { Icon, Card } from "react-native-elements";
//NOOB REDUX
......@@ -10,13 +14,14 @@ import { creditReducer } from './fakeRedux/fakeStore';
//NOOB REDUX ENDS HERE
//let show = true;
export function Credit() {
// const Credit = props => {
const [username, setUsername] = useState("");
const [pass, setPass] = useState("");
const [data, setData] = useState([]);
const [show, setShow] = useState(false);
const [isLoaded, setLoading] = useState(false)
const [random, setRandom] = useState(Math.random());
const dispatch = useDispatch()
......@@ -37,10 +42,11 @@ export function Credit() {
.then((response) => response.json())
.then((data) => {
if (data["balance"] == "Bad username or password!") {
setData(-1)
setData(data)
dispatch({ type: VALUE_CHANGED, value: -1 })
} else {
setData(data);
setLoading(true)
}
// console.log(data.balance);
dispatch({ type: VALUE_CHANGED, value: data.balance })
......@@ -70,6 +76,7 @@ export function Credit() {
function logOut() {
data.balance = "";
// setData("")
//true
setShow(false);
dispatch({ type: VALUE_CHANGED, value: -1 })
......@@ -93,11 +100,14 @@ export function Credit() {
style={{ flex: 1 }}>
<ScrollView >
<View style={styles.style}>
{/* <Text>Nachadzas sa v Kredite</Text>
<View style={{ alignItems: "center", justifyContent: "center" }}>
<Button onPress={() => navigation.goBack()} title="Go back home" />
</View> */}
<Icon
name="local-dining"
type="material-icons"
......@@ -120,6 +130,7 @@ export function Credit() {
</View>
{/* <View style={{ display: show ? "none" : "flex" }}> */}
<View style={{ display: show ? "flex" : "none" }}>
<ActivityIndicator size="large" color="#00ff00" style={{ display: isLoaded ? "none" : "flex" }} />
<Text style={{
display: data.balance === "Bad username or password!" ? "none" : "flex", marginTop: "10%", marginBottom: "5%", fontSize: 25, textAlign: "center",
textAlign: "center",
......@@ -172,6 +183,7 @@ export function Credit() {
</TouchableOpacity>
)}
</View>
</ScrollView>
</KeyboardAvoidingView>
......
......@@ -115,10 +115,47 @@ var categories = [
},
{
key: 9,
isChecked: true,
text: "Nápoje",
type: "Nápoje",
typeValue: 9,
icon: {
name: "local-drink",
type: "ionicons",
color: "#bada55",
},
},
{
key: 10,
isChecked: true,
text: "Vlastná výroba",
type: "Vlastná výroba",
typeValue: 10,
icon: {
name: "hand",
type: "material-community",
color: "#bada55",
},
},
{
key: 11,
isChecked: true,
text: "Zákusky",
type: "Zákusky",
typeValue: 11,
icon: {
name: "cupcake",
type: "material-community",
color: "#bada55",
},
},
{
key: 12,
isChecked: false,
text: "Ignorované",
type: "ignored",
typeValue: 9,
typeValue: 12,
icon: {
name: "emoji-sad",
type: "entypo",
......@@ -132,6 +169,7 @@ export function FoodList({ route }) {
const [filteredData, setFilteredData] = useState([]);
const [ignoreList, setIgnoreList] = useState([]);
const [scrollPosition, setScrollPosition] = useState(0);
const [random, setRandom] = useState(Math.random());
const [filteredCategories, setFilteredCategories] = useState(null);
......@@ -143,12 +181,11 @@ export function FoodList({ route }) {
.then((response) => { return response.json() })
.then((json) => {
setData(json);
setFilteredData(search(categories));
setFilteredData(json);
})
.catch((error) => console.error(error));
}, []); //<--- prazdna zatvorka tam musi byt aby sa to zavolalo len raz
const getData = async (key) => {
console.log("getting");
try {
......@@ -195,33 +232,50 @@ export function FoodList({ route }) {
setFilteredData(search(categories));
}
}
const reRender = () => setRandom(Math.random());
function search(categories) {
setFilteredCategories(categories.filter(item => item.isChecked === true).map(item => item.type));
let filCats = categories.filter(item => item.isChecked === true).map(item => item.type);
let filteredData = data;
var dd = data;
console.log(route);
if (typeof route !== 'undefined' && typeof route.params !== 'undefined' && typeof route.params.cname !== 'undefined') {
setCname(route.params.cname);
filteredData = filteredData.filter((item) => {
dd = dd.filter((item) => {
return (cname === item.canteenName);
});
}
}/* else {
setFilteredData(data);
} */
console.log(filCats);
var filtered = dd.filter((item) => {
if (filCats === null) {
return true;
}/*
return filteredData.filter((item) => {
if (filteredCategories.indexOf('favorite') >= 0) {
if (filCats.indexOf('favorite') >= 0) {
// TODO: Favorized Item
return false;
}
if (filteredCategories.indexOf('ignored') >= 0) {
if (filCats.indexOf('ignored') >= 0) {
// TODO: Ignored Item
return false;
}
} */
return filteredCategories.indexOf(item.type) >= 0;
return filCats.indexOf(item.type) >= 0;
});
setFilteredData(filtered);
reRender();
return filtered;
}
return (
......
import React, { useEffect, useState } from "react";
import { Button, View, Image, Text, StyleSheet, TextInput, ScrollView } from "react-native";
import { getDistance, getPreciseDistance } from "geolib";
import { ActivityIndicator, Button, View, Image, Text, StyleSheet, TextInput, ScrollView } from "react-native";
import Icon from "react-native-elements";
import * as Location from "expo-location";
import HomeScreenBox from './HomeScreenBox';
// components
import HomeScreenBox from './HomeScreenBox';
import HomeScreenISIC from './HomeScreenISIC';
......@@ -13,8 +13,15 @@ import { useSelector } from "react-redux";
import { Provider } from "react-redux";
import { createStore } from "redux";
import { fakeStore } from './fakeRedux/fakeStore'
import { LAT_CHANGED, LONG_CHANGED } from './fakeRedux/fakeActions'
//needed for location
import { useDispatch } from "react-redux";
import * as IntentLauncher from "expo-intent-launcher";
import { getDistance, getPreciseDistance } from "geolib";
import * as Permissions from "expo-permissions";
import * as Location from "expo-location";
// NOOB REDUX IMPORT ENDS HERE
//services
// import { testF } from './services/helper'
......@@ -24,9 +31,6 @@ import { fakeStore } from './fakeRedux/fakeStore'
// export const store = createStore(Reducer)
// var canteens = ["Pizzéria Forte Jedlíkova 7", "Bistro Němcovej 32", "Jedáleň Němcovej 1", "Jedáleň Jedlíkova 7",
// "Jedáleň Vysokoškolská 4", "Bistro Urbánkova 2", "Jedáleň Budovateľská 31 Prešov", "Bistro ZP, Němcovej 9"]
//zoradit zostupne
//my: 69,933325094
let canteens = [
......@@ -115,11 +119,6 @@ export function HomeScreen({ navigation }) {
const [data, setData] = useState([]);
// for (let index = 0; index < array.length; index++) {
// const element = array[index];
// }
// GET MY ACTUAL LOCATION TO SORT CANTEENS BY DISTANCE
const myActualLat = useSelector(function (state) {
return state.latitude
......@@ -190,9 +189,75 @@ export function HomeScreen({ navigation }) {
// }
// const store = createStore(Reducer)
// LOCATION
const dispatch = useDispatch()
const [location, setLocation] = useState({});
// const [
// permission,
// askForPermission,
// ] = Permissions.usePermissions(Permissions.LOCATION, { ask: true });
var getLocationInterval = null;
var requestWasSent = false;
const __getDistance = async () => {
const locationStatus = await Location.getProviderStatusAsync({});
if (Platform.OS !== "android" || locationStatus.networkAvailable) {
clearInterval(getLocationInterval);
Location.watchPositionAsync(
{
distanceInterval: 1,
enableHighAccuracy: true,
},
(loc) => {
if (typeof loc !== "undefined") {
setLocation(loc);
// console.log(loc);
dispatch({ type: LAT_CHANGED, latitude: loc.coords.latitude });
dispatch({ type: LONG_CHANGED, longitude: loc.coords.longitude });
}
}
);
}/* else {
if (Platform.OS === "android")
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_LOCATION_SOURCE_SETTINGS
);
} */
};
const __fetchLocation = async () => {
// if (!permission || permission.status !== "granted") {
// IntentLauncher.startActivityAsync(
// IntentLauncher.ACTION_LOCATION_SOURCE_SETTINGS
// );
// }
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== "granted") {
IntentLauncher.startActivityAsync(
IntentLauncher.ACTION_LOCATION_SOURCE_SETTINGS
);
}
__getDistance();
getLocationInterval = setInterval(__getDistance(), 10000);
};
// END OF LOCATION
useEffect(() => {
if (requestWasSent === false) {
requestWasSent = true;
__fetchLocation();
}
fetch("http://qvera.westeurope.cloudapp.azure.com/food/get")
.then((response) => response.json())
.then((json) => {
......@@ -258,10 +323,10 @@ export function HomeScreen({ navigation }) {
</View> */}
<View style={styles.head_border}></View>
<ScrollView horizontal={false}>
<ScrollView horizontal={false} style={{ width: "100%" }}>
<View style={styles.jedalne}>
<Provider store={fakeStore}>
<View>
<Provider store={fakeStore} style={styles.jedalne}>
<HomeScreenBox name={canteens[0]} nav={navigation}></HomeScreenBox>
<HomeScreenBox name={canteens[1]} nav={navigation}></HomeScreenBox>
<HomeScreenBox name={canteens[2]} nav={navigation}></HomeScreenBox>
......@@ -300,8 +365,10 @@ const styles = StyleSheet.create({
justifyContent: "flex-start",
},
jedalne: {
flexDirection: 'column',
// width: "100%"
flex: 1,
flexDirection: "row",
//flexDirection: 'column',
width: "100%",
//flexWrap: 'wrap',
//flex: 1,
paddingBottom: 0,
......
......@@ -12,7 +12,6 @@ import {
TouchableOpacity,
ImageBackground,
P,
} from "react-native";
import EntypoIcon from "react-native-vector-icons/Entypo";
import { useSelector, connect } from "react-redux";
......@@ -68,20 +67,38 @@ const HomeScreenBox = props => {
}
return (
<TouchableOpacity
style={styles.foodStyle}
activeOpacity={0.9}
activeOpacity={0.92}
tvParallaxProperties={{ pressMagnification: 50, pressMagnification: 50 }}
onPress={() => {
props.nav.navigate('FoodList', { cname: props.name.name });
//FoodList.routeSearch();
}}
>
<Card containerStyle={styles.foodCard}>
<Text numberOfLines={2} style={{ ...styles.kantinNejm, marginBottom: 0 }}>{props.name.name}</Text>
<Text numberOfLines={2} style={{ ...styles.distance, marginTop: 0, marginBottom: 0, paddingBottom: 0, fontSize: 10 }}>{myGetDistanceTest()}</Text>
<Card containerStyle={{ ...styles.foodCard }}>
<View style={{ flexDirection: 'row', alignSelf: "center", paddingVertical: 15, marginLeft: 10 }}>
<Text numberOfLines={2} style={{ ...styles.kantinNejm, marginBottom: 0 }}>{props.name.name}</Text>
<View style={{
flexDirection: "row",
textAlign: "right",
alignItems: "center",
width: "21%",
marginLeft: 20,
justifyContent: "flex-start",
}}>
<Icon
name="compass"
type="material-community"
size={15}
color="#8c8c8c"
iconStyle={{}}></Icon>
<Text style={{ ...styles.distance, marginLeft: 5, marginBottom: 0, paddingBottom: 0, fontSize: 10 }} numberOfLines={2}> {myGetDistanceTest()}</Text>
</View>
</View>
</Card>
</TouchableOpacity>
......@@ -106,57 +123,52 @@ const HomeScreenBox = props => {
<View style={styles.rect5}>
<View style={styles.box_background}>
<Text style={styles.distance}>0.00km</Text>
<Text style={styles.box_header}>{props.name}</Text>
<View style={styles.rect4}></View>
</View>
</View>
<ImageBackground
source={require("../assets/jedlikova7.jpg")}
resizeMode="cover"
style={styles.image1}
imageStyle={styles.image1_imageStyle}
>
<Image source={require("../assets/compass-icon-27.png")} style={styles.icon3}></Image>
</ImageBackground>
<View style={styles.box_third}>
<View style={styles.pol14Stack}>
<Text style={styles.box_header_third}>Šaláty</Text>
{renderSalads()}
</View>
</View>
<View style={styles.rect6}>
<View style={styles.polievky1Stack}>
<Text style={styles.box_header_first}>Polievky</Text>
{renderSoups()}
</View>
</View>
<View style={styles.rect5}>
<View style={styles.box_background}>
<Text style={styles.distance}>0.00km</Text>
<Text style={styles.box_header}>{props.name}</Text>
<View style={styles.rect4}></View>
</View>
</View>
<ImageBackground
source={require("../assets/jedlikova7.jpg")}
resizeMode="cover"
style={styles.image1}
imageStyle={styles.image1_imageStyle}
>
<Image source={require("../assets/compass-icon-27.png")} style={styles.icon3}></Image>
</ImageBackground>
<View style={styles.box_third}>
<View style={styles.pol14Stack}>
<Text style={styles.box_header_third}>Šaláty</Text>
{renderSalads()}
</View>
</View>
<View style={styles.rect6}>
<View style={styles.polievky1Stack}>
<Text style={styles.box_header_first}>Polievky</Text>
{renderSoups()}
</View>
</View>
<View style={styles.rect7}>
<View style={styles.hlavneJedla4Stack}>
<Text style={styles.box_header_second}>Hlavné jedlá</Text>
<ScrollView>
{renderMain()}
</ScrollView>
</View>
</View>
*/
<View style={styles.rect7}>
<View style={styles.hlavneJedla4Stack}>
<Text style={styles.box_header_second}>Hlavné jedlá</Text>
<ScrollView>
{renderMain()}
</ScrollView>
</View>
</View>
*/
}
const styles = StyleSheet.create({
foodStyle: {
justifyContent: 'center',
alignItems: 'center',
width: "100%",
marginHorizontal: "4%",
marginVertical: "3%",
width: "98%",
marginHorizontal: "1%",
marginVertical: "1%",
elevation: 0,
borderWidth: 0,
},
......@@ -164,7 +176,6 @@ const styles = StyleSheet.create({
foodCard: {
borderRadius: 10,
width: "100%",
flex: 2,
elevation: 2,
padding: 0,
margin: 0,
......@@ -204,36 +215,29 @@ const styles = StyleSheet.create({
justifyContent: "center"
},
kantinNejm: {
alignSelf: "center",
maxWidth: "100%",
width: "100%",
minHeight: 45,
marginVertical: 10,
marginBottom: 20,
paddingHorizontal: 10,
paddingTop: 8,
// NOTE pomocka
/*
alignSelf: "center",
alignContent: "center",
alignItems: "center",
justifyContent: "center",
textAlign: "center",
textAlignVertical: "center",
*/
kantinNejm: {
textAlign: "left",
textAlignVertical: "center",
width: "68%",
color: "#bada55",
//color: "#7c8a8f",
fontWeight: "bold",
fontSize: 15,
},
distance: {
alignSelf: "center",
maxWidth: "100%",
width: "100%",
minHeight: 45,
marginVertical: 10,
marginBottom: 5,
paddingHorizontal: 10,
paddingTop: 12,
textAlign: "center",
//color: "#bada55",
color: "#7c8a8f",
fontWeight: "bold",
fontSize: 15,
textAlignVertical: "center",
},
foodPrice: {
......
......@@ -93,54 +93,66 @@ const HomeScreenISIC = props => {
props.nav.navigate('Credit');
}
}
if (myActualCredit == "-1" || myActualCredit == "Bad username or password!") {
return (
<View style={styles.container_head}>
<View style={styles.head_top_border}>
<View style={styles.head_line1}></View>
<Icon
name="bank"
type="material-community"
size={45}
color="#8c8c8c"
iconStyle={styles.icon}
/>
<View style={styles.head_line2}></View>
</View>
<View style={styles.head_border}></View>
return (
<View style={styles.container_head}>
<View style={styles.head_top_border}>
<View style={styles.head_line1}></View>
{/* <Icon name="bank" type="entypo" style={styles.icon}></Icon> */}
<Icon
name="bank"
type="material-community"
size={45}
color="#8c8c8c"
iconStyle={styles.icon}
/>
{/* <Image source={require("../assets/bank.png")} style={styles.icon}></Image> */}
<View style={styles.head_line2}></View>
</View>
<View style={styles.head_border}></View>
<View style={styles.zostatok_div}>
<Text style={styles.zostatok_header}>Zostatok na ISIC:</Text>
{/* <Text style={styles.zostatok_header}>{myActualCredit} </Text> */}
{/* <Text style={styles.zostatok_price}>{props.zostatok.toFixed(2)} €</Text> */}
{myActualCredit == "-1" && (
<Pressable style={styles.zostatok_button} onPress={() => { loginButton() }}>
<View style={styles.div_text1}>
<Text style={styles.zostatok_text1}>Prihlás sa pre zobrazenie</Text>
</View>
<View style={styles.div_text2}>
<Text style={styles.zostatok_text2}>zostatku:</Text>
< Pressable style={styles.zostatok_button} onPress={() => { loginButton() }}>