summaryrefslogtreecommitdiff
path: root/src/Components/PortalPanel.tsx
blob: d49d88ab52c853449543187f7f0373c2f8b5b904 (plain) (blame)
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
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,
    }
});