Commit cb7660cc authored by Sebastian Trebunak's avatar Sebastian Trebunak
Browse files

changes

parent 334af4f0
......@@ -4,14 +4,17 @@ import { AppLoading, Asset, Font, Icon } from "expo";
import AppNavigator from "./navigation/AppNavigator";
import { NOTIFICATIONS } from "./constants/Data";
const API_CALL_TIMEOUT = 60000;
export default class App extends React.Component {
state = {
isLoadingComplete: false,
notifications: NOTIFICATIONS
notifications: []
};
componentDidMount() {
this.timer = setInterval(this.getNotifications, 7500);
this.getNotifications();
this.timer = setInterval(this.getNotifications, API_CALL_TIMEOUT);
}
componentWillUnmount() {
......@@ -24,10 +27,19 @@ export default class App extends React.Component {
console.log("Get Notifications now!!");
// const notifications treba nahradit za fetch a setState spustit iba v pripade ze sa data zmenia
// pretoze by default to re-renderuje celu aplikaciu
const notifications = [
...this.state.notifications,
NOTIFICATIONS[this.state.notifications.length - 5]
];
if (this.state.notifications.length === 0) {
return this.setState({ notifications: NOTIFICATIONS });
}
let nextItem = NOTIFICATIONS[this.state.notifications.length - 4];
if (!nextItem) {
nextItem = NOTIFICATIONS[0];
}
const notifications = [...this.state.notifications, nextItem];
console.log(notifications);
console.log("===================");
this.setState({ notifications });
};
......
import React, { PureComponent } from "react";
import { StyleSheet } from "react-native";
// import { withNavigation } from "react-navigation";
import { StyleSheet, View, ActivityIndicator } from "react-native";
import MapView, { Marker } from "react-native-maps";
class BranchesMap extends PureComponent {
render() {
const initialRegion = {
latitude: this.props.data.lat,
longitude: this.props.data.long,
get markerLocation() {
const { branch } = this.props;
return { latitude: branch.lat, longitude: branch.long };
}
get initialRegion() {
const { branch } = this.props;
return {
latitude: branch.lat,
longitude: branch.long,
latitudeDelta: 0.0922,
longitudeDelta: 0.0421
};
}
get markerTitle() {
const { branch } = this.props;
return `${branch.address}, ${branch.zip} ${branch.city}`;
}
render() {
if (!this.props.branch) {
return (
<View style={styles.map}>
<ActivityIndicator />
</View>
);
}
return (
<MapView style={styles.map} initialRegion={initialRegion} loadingEnabled>
<MapView style={styles.map} initialRegion={this.initialRegion}>
<Marker
key="marker"
coordinate={{ latitude: data.lat, longitude: data.long }}
title={`${data.address}, ${data.zip} ${data.city}`}
coordinate={this.markerLocation}
title={this.markerTitle}
description="Pobočka Tatra banky"
/>
</MapView>
......
......@@ -4,7 +4,7 @@ import NotificationListItem from "./NotificationListItem";
import NotificationListEmptyItem from "./NotificationListEmptyItem";
export default class NotificationScreen extends PureComponent {
_keyExtractor = item => `notification-${item.id}`;
_keyExtractor = (item, index) => `notification-${index}`;
_renderItem = ({ item }) => <NotificationListItem item={item} />;
......
......@@ -6,7 +6,6 @@ import {
InteractionManager,
Text
} from "react-native";
import { NOTIFICATIONS } from "../constants/Data";
import { iOSUIKit } from "react-native-typography";
import NotificationList from "../components/notifications/NotificationList";
import BranchesMap from "../components/branches/BranchesMap";
......@@ -33,7 +32,9 @@ export default class BranchInfoScreen extends Component {
const branchID = this.state.branch.id;
this.setState({
isLoaded: true,
data: NOTIFICATIONS.filter(item => item.branchId === branchID)
data: this.props.screenProps.notifications.filter(
item => item.branchId === branchID
)
});
});
}
......@@ -42,7 +43,7 @@ export default class BranchInfoScreen extends Component {
return (
<ScrollView style={styles.container}>
<View style={styles.mapContainer}>
{this.state.isLoaded && <BranchesMap data={this.state.branch} />}
{this.state.isLoaded && <BranchesMap branch={this.state.branch} />}
</View>
<View style={styles.innerContainer}>
<Text style={styles.title}>Notifikácie</Text>
......
......@@ -9,10 +9,16 @@ export default class BranchesScreen extends Component {
};
state = {
data: BRANCHES,
data: [],
mapView: true
};
componentDidMount() {
// tu pojde request na branches....
// fetch(URL, blabla)
this.setState({ data: BRANCHES });
}
_keyExtractor = item => `branch-${item.id}`;
_renderItem = ({ item }) => <BranchListItem item={item} />;
......
......@@ -4,7 +4,7 @@ import { ButtonGroup } from "react-native-elements";
import { withNavigationFocus } from "react-navigation";
import NotificationList from "../components/notifications/NotificationList";
import { iOSColors } from "react-native-typography";
import { NOTIFICATIONS } from "../constants/Data";
class NotificationScreen extends Component {
static navigationOptions = {
title: "Upozornenia"
......@@ -15,7 +15,7 @@ class NotificationScreen extends Component {
this.state = {
selectedIndex: 0,
data: NOTIFICATIONS
data: []
};
}
......@@ -23,6 +23,10 @@ class NotificationScreen extends Component {
return this.props.isFocused;
}
componentDidMount() {
this.setState({ data: this.props.screenProps.notifications || [] });
}
componentDidUpdate(prevProps) {
const lastNotifications = prevProps.screenProps.notifications;
const currentNotifications = this.props.screenProps.notifications;
......
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