Commit 72013c72 authored by zarina's avatar zarina 🌊

#2, добавлен вывод полной информации по клику на контакт

parent 65024688
...@@ -5,7 +5,7 @@ const Contact = props => { ...@@ -5,7 +5,7 @@ const Contact = props => {
return ( return (
<TouchableOpacity style={styles.placeItem} onPress={props.showContact}> <TouchableOpacity style={styles.placeItem} onPress={props.showContact}>
<Image source={{uri: props.photo}} style={styles.image}/> <Image source={{uri: props.photo}} style={styles.image}/>
<Text style={{textTransform: 'uppercase'}}>{props.name}</Text> <Text style={styles.text}>{props.name}</Text>
</TouchableOpacity> </TouchableOpacity>
); );
}; };
...@@ -18,14 +18,17 @@ const styles = StyleSheet.create({ ...@@ -18,14 +18,17 @@ const styles = StyleSheet.create({
justifyContent: 'space-between', justifyContent: 'space-between',
alignItems: 'center', alignItems: 'center',
width: '100%', width: '100%',
backgroundColor: '#eee', backgroundColor: 'rgba(1,1,1,0.7)',
marginBottom: 10, marginBottom: 10,
padding: 10, padding: 10,
borderRadius: 5
}, },
image: { image: {
width: 60, width: 60,
height: 60, height: 60,
marginRight: 10 marginRight: 10
},
text: {
color: '#eee'
} }
}); });
import React from 'react';
import {StyleSheet, Image, Text, TouchableHighlight, View} from "react-native";
const FullContact = props => {
return (
<View style={{marginTop: 22, flex: 1}}>
<View>
<Image source={{uri: props.contact.photo}} style={styles.image}/>
<Text style={styles.contactProps}>Name: {props.contact.name}</Text>
<Text style={styles.contactProps}>Mail: {props.contact.email}</Text>
<Text style={styles.contactProps}>Phone: {props.contact.phone}</Text>
</View>
<TouchableHighlight
onPress={props.closeModal}
style={styles.btn}>
<Text style={styles.text}>Hide Modal</Text>
</TouchableHighlight>
</View>
);
};
export default FullContact;
const styles = StyleSheet.create({
image: {
width: 200,
height: 200,
marginRight: 10
},
btn: {
position: 'absolute',
bottom: 0,
padding: 20,
borderRadius: 5,
backgroundColor: 'rgba(0,0,0,0.7)',
width: '100%'
},
contactProps: {
fontWeight: 'bold',
fontSize: 18,
marginTop: 10,
},
text: {
fontSize: 24,
textAlign: 'center',
color: 'white'
}
});
\ No newline at end of file
...@@ -3,19 +3,24 @@ import {StyleSheet, Modal, View, Text, FlatList} from "react-native"; ...@@ -3,19 +3,24 @@ import {StyleSheet, Modal, View, Text, FlatList} from "react-native";
import {connect} from "react-redux"; import {connect} from "react-redux";
import {getContacts} from "../../store/actions"; import {getContacts} from "../../store/actions";
import Contact from "../../components/Contact/Contact"; import Contact from "../../components/Contact/Contact";
import ContactInfo from "../../components/FullContact/FullContact";
class Main extends Component { class Main extends Component {
state = { state = {
chosenContact: {} modalShow: false,
contact: {}
}; };
componentDidMount() { componentDidMount() {
this.props.getContacts(); this.props.getContacts();
} }
setModalShow(val) {
this.setState({modalShow: val});
}
chooseContact = (contact) => { chooseContact = (contact) => {
this.setState({chosenContact: contact, modalVisible: true}); this.setState({contact, modalShow: true});
}; };
render() { render() {
...@@ -33,7 +38,19 @@ class Main extends Component { ...@@ -33,7 +38,19 @@ class Main extends Component {
} }
return ( return (
<View style={styles.main}> <View style={styles.main}>
<Text style={styles.heading}> <Modal
animationType="slide"
transparent={false}
visible={this.state.modalShow}
onRequestClose={() => {
this.setModalShow(!this.state.modalShow);
}}>
<ContactInfo
contact={this.state.contact}
closeModal={() => this.setState({modalShow: false})}
/>
</Modal>
<Text style={styles.title}>
Contacts Contacts
</Text> </Text>
<FlatList <FlatList
...@@ -64,19 +81,16 @@ const mapDispatchToProps = dispatch => { ...@@ -64,19 +81,16 @@ const mapDispatchToProps = dispatch => {
}; };
export default connect(mapStateToProps, mapDispatchToProps)(Main); export default connect(mapStateToProps, mapDispatchToProps)(Main);
const styles = StyleSheet.create({ const styles = StyleSheet.create({
heading: { title: {
fontSize: 32, fontSize: 30,
borderColor: 'transparent', textTransform: 'uppercase',
borderStyle: 'solid',
borderWidth: 2,
borderBottomColor: 'black',
marginBottom: 20 marginBottom: 20
}, },
main: { main: {
height: '100%', backgroundColor: '#ccc',
marginTop: 150, flex: 1,
justifyContent: 'flex-start',
padding: 40 padding: 40
} }
}); });
\ No newline at end of file
import axios from '../axios-contacts'; import axios from '../axios-contacts';
import {FETCH_ERROR, FETCH_REQUEST, FETCH_SUCCESS} from "./actionsType";
export const FETCH_CONTACTS_REQUEST = 'FETCH_CONTACTS_REQUEST';
export const FETCH_CONTACTS_SUCCESS = 'FETCH_CONTACTS_SUCCESS';
export const FETCH_CONTACTS_ERROR = 'FETCH_CONTACTS_ERROR';
export const fetchContactsRequest = () => { export const fetchContactsRequest = () => {
return {type: FETCH_CONTACTS_REQUEST}; return {type: FETCH_REQUEST};
}; };
export const fetchContactsSuccess = contacts => { export const fetchContactsSuccess = contacts => {
return {type: FETCH_CONTACTS_SUCCESS, contacts}; return {type: FETCH_SUCCESS, contacts};
}; };
export const fetchContactsError = error => { export const fetchContactsError = error => {
return {type: FETCH_CONTACTS_ERROR, error}; return {type: FETCH_ERROR, error};
}; };
......
export const FETCH_REQUEST = 'FETCH_REQUEST';
export const FETCH_SUCCESS = 'FETCH_SUCCESS';
export const FETCH_ERROR = 'FETCH_ERROR';
\ No newline at end of file
import {FETCH_CONTACTS_ERROR, FETCH_CONTACTS_REQUEST, FETCH_CONTACTS_SUCCESS} from "./actions"; import {FETCH_ERROR, FETCH_REQUEST, FETCH_SUCCESS} from "./actionsType";
const initialState = { const initialState = {
loading: false, loading: false,
...@@ -8,11 +8,11 @@ const initialState = { ...@@ -8,11 +8,11 @@ const initialState = {
const reducer = (state = initialState, action) => { const reducer = (state = initialState, action) => {
switch (action.type) { switch (action.type) {
case FETCH_CONTACTS_REQUEST: case FETCH_REQUEST:
return {...state, loading: true}; return {...state, loading: true};
case FETCH_CONTACTS_SUCCESS: case FETCH_SUCCESS:
return {...state, loading: false, contacts: action.contacts}; return {...state, loading: false, contacts: action.contacts};
case FETCH_CONTACTS_ERROR: case FETCH_ERROR:
return {...state, loading: false, error: action.error}; return {...state, loading: false, error: action.error};
default: default:
return state; return state;
......
Markdown is supported
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