diff --git a/src/JSReactApp/package.json b/src/JSReactApp/package.json index 917b069..51c5309 100644 --- a/src/JSReactApp/package.json +++ b/src/JSReactApp/package.json @@ -12,7 +12,10 @@ "dependencies": { "axios": "^0.19.0", "react": "16.9.0", - "react-native": "0.61.5" + "react-native": "0.61.5", + "react-native-gesture-handler": "^1.5.2", + "react-navigation": "^4.0.10", + "react-navigation-stack": "^1.10.3" }, "devDependencies": { "@babel/core": "^7.7.4", diff --git a/src/JSReactApp/src/App.js b/src/JSReactApp/src/App.js index 6233e1d..d1555a4 100644 --- a/src/JSReactApp/src/App.js +++ b/src/JSReactApp/src/App.js @@ -8,124 +8,148 @@ import React, {Component} from 'react'; import { - View, - Text, - FlatList, - StyleSheet, + View, + Text, + FlatList, + StyleSheet, + TouchableOpacity, } from 'react-native'; import Button from './components/Button'; import axios from 'axios'; +import defaults from "@babel/runtime/helpers/esm/defaults"; +import {get} from "react-native/Libraries/TurboModule/TurboModuleRegistry"; const API_BASE_PATH = 'https://jsonplaceholder.typicode.com/'; const POSTS_PATH = `${API_BASE_PATH}posts/`; const USER_PATH = `${API_BASE_PATH}users/`; +const COMMENTS_PATH = `${API_BASE_PATH}comments?postId=`; const postKeyExtractor = (item, index) => { - return `key-${index}`; + return `key-${index}`; }; export default class App extends Component { - constructor(props) { - super(props); - this.state = { - posts: [], - users: {}, - }; - } + constructor(props) { + super(props); + this.state = { + posts: [], + comments: [], + users: {}, + }; + } + + componentDidMount() { + axios.get(POSTS_PATH).then(({data}) => { + + this.setState({posts: data.sort(() => Math.random() - 0.5)}); + + Array.from(data.reduce((acc, item) => { + acc.add(item.userId); + return acc; + }, new Set())).forEach(id => { + axios.get(`${USER_PATH}${id}`).then(({data}) => { + this.setState({users: {...this.state.users, [data.id]: data}}); + }); + }); + }); + } + + render() { + const {posts} = this.state; + const {comments} = this.state; + const {rootContainer, headerButton, headerContainer} = styles; + return + +