-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.tsx
More file actions
66 lines (59 loc) · 1.92 KB
/
App.tsx
File metadata and controls
66 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import React, { Fragment } from "react";
import FlashMessage from "react-native-flash-message";
import { createStackNavigator, createAppContainer } from "react-navigation";
import RealEstateListContainer from "./src/containers/RealEstateListContainer";
import RealEstateSingleViewContainer from "./src/containers/RealEstateSingleViewContainer";
import RealEstateAddNewContainer from "./src/containers/RealEstateAddNewContainer";
import { View } from "react-native";
import { Estate } from "./src/interfaces";
import { EstatesContext } from "./src/context/EstatesContext";
var RealEstateApi = require("./src/service/realestate");
const AppNavigator = createStackNavigator({
RealEstateList: {
screen: RealEstateListContainer
},
RealEstateSingleView: {
screen: RealEstateSingleViewContainer
},
RealEstateAddNew: {
screen: RealEstateAddNewContainer
}
});
const AppContainer = createAppContainer(AppNavigator);
interface MyState {
estates: Array<Estate>;
countries: Array<{ name: string; city_id: number }>;
fetchEstates(): void;
}
export default class App extends React.Component<any, MyState> {
fetchEstates = () => {
console.log("estates fetched");
RealEstateApi.getList().then((estates: Array<Estate>) => {
const countries = estates
.map((item: Estate) => {
return { name: item.city.country, city_id: item.city.id };
})
.filter(
(thing, index, self) =>
index === self.findIndex(t => t.name === thing.name)
);
this.setState({ estates, countries });
});
};
state = {
estates: [],
countries: [],
fetchEstates: this.fetchEstates
};
componentDidMount = () => this.fetchEstates();
render() {
return (
<View style={{ flex: 1 }}>
<EstatesContext.Provider value={this.state}>
<AppContainer />
</EstatesContext.Provider>
<FlashMessage position="top" />
</View>
);
}
}