summaryrefslogblamecommitdiff
path: root/src/Components/PortalPanel.tsx
blob: d49d88ab52c853449543187f7f0373c2f8b5b904 (plain) (tree)
1
2
3
4
5
6
7
8
9
                                                        
                                                                                                       
                                                                  




                                               
                                            








                                                    
                                                            
          
      




                                                    









                                                  





















                                                                                                                                                                                         

















                                                                    





                             






                             






                           

     
import React, { Component, PureComponent } from 'react';
import { StyleSheet, View, Text, GestureResponderEvent, ActivityIndicator, Image } from 'react-native';
// import { Button } from 'react-native-vector-icons/FontAwesome';
import { getStatusBarHeight } from '../helper';
import { connect } from 'react-redux';
import actions from '../Actions/actions';
import { Portal } from '../Api/types';
import { bindActionCreators } from 'redux';
import { COLORS_FRACTION } from '../colors';

type Props = {
    guid: string
    portal?: Portal
}

class PortalPanel extends PureComponent<Props> {
    static navigationOptions = ({ navigation }) => {
        return {
            title: 'Информация о портале',
        };
    };
    componentDidMount() {
        this.props.getPortalDetails(this.props.guid)
    }
    componentWillReceiveProps(next: Props) {
        if (next.guid != this.props.guid) {
            this.props.getPortalDetails(next.guid)
        }
    }
    render() {
        const { portal } = this.props
        if (!portal) {
            return <ActivityIndicator />
        }
        return (
            <View style={styles.overlay}>
                <View style={styles.panelRow}>
                    <Image style={styles.photo} source={{ uri: portal.photo }} />
                    <View style={styles.panelRight}>
                        <Text style={[styles.title, { color: COLORS_FRACTION[portal.fraction] }]}>{portal.name}</Text>
                        <Text style={styles.subtitle}>Уровeнь: {portal.level}, здоровье: {portal.power}</Text>
                        <Text style={styles.subtitle}>Владелец: <Text style={[styles.user, { color: COLORS_FRACTION[portal.fraction] }]}>{portal.owner || 'нет'}</Text></Text>
                        <Text style={styles.subtitle}>Дата: {portal.timestamp && (new Date(portal.timestamp)).toLocaleString()}</Text>
                    </View>
                </View>
                <Text style={styles.title}>Резонаторы</Text>
                <View>
                    {portal.resonators && portal.resonators.map((r, idx) =>
                        r ? (<Text style={styles.subtitle}>{idx + 1}: {r[1]} [{r[2]}] - {r[0]}</Text>) : (<Text style={styles.subtitle}>{idx + 1}: нет</Text>)
                    )}
                    {(!portal.resonators || portal.resonators.length == 0) && (<Text style={styles.subtitle}>нет</Text>)}
                </View>
                <Text style={styles.title}>Моды</Text>
                <View>
                    {portal.mods && portal.mods.map((r, idx) =>
                        r ? (<Text style={styles.subtitle}>{idx + 1}: {r[1]} [{r[2]}] - {r[0]}</Text>) : (<Text style={styles.subtitle}>{idx + 1}: нет</Text>)
                    )}
                </View>
            </View>
        );
    }
}

export default connect((store, props: Props) => {
    const guid = props.navigation.getParam('guid')
    return {
        portal: store.entities.portals[guid],
        guid
    }
}, (dispatch) => bindActionCreators(actions, dispatch))(PortalPanel)

const styles = StyleSheet.create({
    overlay: {
        flex: 1,
        padding: 8,
    },
    panelRow: {
        flexDirection: 'row',
    },
    panelRight: {
        paddingLeft: 8
    },
    title: {
        fontWeight: 'bold',
        fontSize: 22,
    },
    subtitle: {
        fontWeight: 'normal',
        fontSize: 18,
    },
    user: {
        fontWeight: 'bold',
    },
    photo: {
        width: 100,
        height: 195,
    }
});