|
| 1 | +import React, {Component, PropTypes} from 'react'; |
| 2 | +import {View, Text, TextInput, TouchableOpacity} from 'react-native'; |
| 3 | +import {Actions} from 'react-native-router-flux'; |
| 4 | +import Icon from 'react-native-vector-icons/FontAwesome'; |
| 5 | + |
| 6 | +import Style from '../../../utilities/style'; |
| 7 | +import NodeListManager from '../../../utilities/node_list_manager'; |
| 8 | +import PageContainer from '../../common/PageContainer'; |
| 9 | + |
| 10 | +class NewTopicPage extends Component { |
| 11 | + static propTypes = { |
| 12 | + nodeSlug: PropTypes.string, |
| 13 | + }; |
| 14 | + state = { |
| 15 | + nodeName: '问与答(默认)', |
| 16 | + nodeSlug: 'qna', |
| 17 | + }; |
| 18 | + |
| 19 | + constructor(props) { |
| 20 | + super(props); |
| 21 | + } |
| 22 | + |
| 23 | + componentDidMount() { |
| 24 | + this.setUpNavigationBar(); |
| 25 | + this.setUpNode(); |
| 26 | + } |
| 27 | + |
| 28 | + setUpNode = () => { |
| 29 | + const { nodeSlug } = this.props; |
| 30 | + if (nodeSlug) { |
| 31 | + NodeListManager.getNodes().then(nodes => { |
| 32 | + const filteredNodes = nodes.filter((node) => { |
| 33 | + const { slug, name } = node; |
| 34 | + if (slug && name && (slug.toLowerCase().indexOf(nodeSlug) > -1 || name.toLowerCase().indexOf(nodeSlug) > -1)) { |
| 35 | + return true; |
| 36 | + } else { |
| 37 | + return false; |
| 38 | + } |
| 39 | + }); |
| 40 | + if (filteredNodes.length > 0) { |
| 41 | + const currentNode = filteredNodes[0]; |
| 42 | + const { slug, name } = currentNode; |
| 43 | + this.setState({ nodeName: name, nodeSlug: slug }); |
| 44 | + } else { |
| 45 | + this.setState({ nodeName: '(未知)', nodeSlug: null }); |
| 46 | + } |
| 47 | + }, error => { |
| 48 | + alert('Error getting nodes:' + error); |
| 49 | + }); |
| 50 | + } |
| 51 | + }; |
| 52 | + |
| 53 | + setUpNavigationBar = () => { |
| 54 | + Actions.refresh({ |
| 55 | + rightTitle: '发布', |
| 56 | + onRight: this.onRightButtonPress, |
| 57 | + rightButtonTextStyle: { color: 'white' }, |
| 58 | + }); |
| 59 | + }; |
| 60 | + |
| 61 | + onRightButtonPress = () => { |
| 62 | + this.refs['titleTextInput'].blur(); |
| 63 | + this.refs['contentTextInput'].blur(); |
| 64 | + }; |
| 65 | + |
| 66 | + async requestOnceCode() { |
| 67 | + // TODO: Implement get once code: $('input[name="once"]') |
| 68 | + } |
| 69 | + |
| 70 | + render() { |
| 71 | + const { nodeName } = this.state; |
| 72 | + return ( |
| 73 | + <PageContainer> |
| 74 | + <View style={styles.nodeSelectorWrapper}> |
| 75 | + <Text style={styles.nodeSelectorTitle}>节点:</Text> |
| 76 | + <TouchableOpacity style={styles.nodeSelectorTouchable}> |
| 77 | + <View style={styles.nodeSelectorTouchableInnerWrapper}> |
| 78 | + <Text style={styles.nodeSelectorText}>{nodeName}</Text> |
| 79 | + <Icon style={styles.nodeSelectorIcon} size={13} name="chevron-right" color="#329EED" /> |
| 80 | + </View> |
| 81 | + </TouchableOpacity> |
| 82 | + </View> |
| 83 | + <View style={styles.titleTextInputWrapper}> |
| 84 | + <TextInput |
| 85 | + ref="titleTextInput" |
| 86 | + returnKeyType="next" |
| 87 | + style={styles.titleTextInput} |
| 88 | + onSubmitEditing={this.onTitleTextInputSubmit} |
| 89 | + placeholder="标题" /> |
| 90 | + </View> |
| 91 | + <View style={styles.contentTextInputWrapper}> |
| 92 | + <TextInput |
| 93 | + ref="contentTextInput" |
| 94 | + style={styles.contentTextInput} |
| 95 | + multiline={true} |
| 96 | + placeholder="内容" /> |
| 97 | + </View> |
| 98 | + </PageContainer> |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + onTitleTextInputSubmit = () => { |
| 103 | + this.refs['contentTextInput'].focus(); |
| 104 | + }; |
| 105 | + |
| 106 | +} |
| 107 | + |
| 108 | +const styles = Style.create({ |
| 109 | + nodeSelectorWrapper: { |
| 110 | + backgroundColor: '#F7F8F9', |
| 111 | + height: 40, |
| 112 | + borderBottomColor: '#D8D8D8', |
| 113 | + borderBottomWidth: 1, |
| 114 | + alignItems: 'center', |
| 115 | + paddingLeft: 12, |
| 116 | + paddingRight: 12, |
| 117 | + flexDirection: 'row', |
| 118 | + }, |
| 119 | + nodeSelectorText: { |
| 120 | + color: '#329EED', |
| 121 | + fontSize: 14, |
| 122 | + flex: 1, |
| 123 | + }, |
| 124 | + nodeSelectorTitle: { |
| 125 | + color: '#A4A4A4', |
| 126 | + fontSize: 14, |
| 127 | + |
| 128 | + }, |
| 129 | + nodeSelectorTouchable: { |
| 130 | + flex: 1, |
| 131 | + }, |
| 132 | + nodeSelectorTouchableInnerWrapper: { |
| 133 | + flexDirection: 'row', |
| 134 | + }, |
| 135 | + nodeSelectorIcon: { |
| 136 | + marginTop: 2, |
| 137 | + }, |
| 138 | + |
| 139 | + titleTextInputWrapper: { |
| 140 | + borderBottomWidth: 1, |
| 141 | + borderBottomColor: '#D8E0E4', |
| 142 | + marginLeft: 12, |
| 143 | + marginRight: 12, |
| 144 | + marginTop: 10, |
| 145 | + }, |
| 146 | + titleTextInput: { |
| 147 | + flex: 1, |
| 148 | + height: 25, |
| 149 | + fontSize: 16, |
| 150 | + }, |
| 151 | + |
| 152 | + contentTextInputWrapper: { |
| 153 | + flex: 1, |
| 154 | + marginLeft: 12, |
| 155 | + marginRight: 12, |
| 156 | + marginTop: 10, |
| 157 | + marginBottom: 12, |
| 158 | + }, |
| 159 | + contentTextInput: { |
| 160 | + flex: 1, |
| 161 | + fontSize: 14, |
| 162 | + }, |
| 163 | +}); |
| 164 | + |
| 165 | +export default NewTopicPage; |
0 commit comments