Skip to content

Commit 78acf83

Browse files
committed
improve question & blink & comment add page.
1 parent 6a90159 commit 78acf83

File tree

6 files changed

+237
-64
lines changed

6 files changed

+237
-64
lines changed

source/common/index.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,7 @@ export function getFormatDate(date){
8080
export function splitStrToArray(str, char = ',', count = 3){
8181
return _.split(str, char, count);
8282
}
83+
84+
export function numberValidator(str){
85+
return true;
86+
}

source/component/header/home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ export const styles = StyleSheet.create({
158158
opacity: 0.8
159159
},
160160
drawerMenu:{
161-
top: StyleConfig.space_4 * 2,
161+
bottom: StyleConfig.space_4 * 2,
162162
left: StyleConfig.space_3
163163
}
164164
});

source/view/blinkAdd.js

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,23 @@ import {
33
View,
44
Text,
55
Image,
6+
Switch,
67
TextInput,
78
StyleSheet,
89
TouchableOpacity
910
} from 'react-native';
1011

12+
import _ from 'lodash';
1113
import { bindActionCreators } from 'redux';
1214
import { connect } from 'react-redux';
1315
import Icon from 'react-native-vector-icons/Ionicons';
14-
1516
import * as ConfigAction from '../action/config';
1617
import * as UserAction from '../action/user';
1718
import { getImageSource } from '../common';
1819
import { Base64 } from '../common/base64';
1920
import Navbar from '../component/navbar';
21+
import Toast from '../component/toast';
22+
import Spinner from '../component/spinner';
2023
import { StyleConfig, ComponentStyles, CommonStyles } from '../style';
2124

2225
const navTitle = "新增闪存";
@@ -27,12 +30,44 @@ class BlinkAddPage extends Component {
2730
constructor (props) {
2831
super(props);
2932
this.state = {
30-
commentContent:''
33+
blinkContent:'',
34+
blinkStatus: true,
35+
pending: false
36+
};
37+
}
38+
39+
blinkValidator(){
40+
let blinkContent = this.state.blinkContent;
41+
let message ;
42+
if(!_.trim(blinkContent)){
43+
message = "请输入闪存内容";
44+
}
45+
46+
if(message){
47+
this.refs.toast.show({
48+
message: message
49+
});
50+
return false;
3151
}
52+
53+
return {
54+
Content: blinkContent,
55+
IsPrivate: !this.state.blinkStatus
56+
};
3257
}
3358

3459
onBlinkSendPress(){
35-
this.props.router.pop();
60+
let blinkData = this.blinkValidator();
61+
if(blinkData){
62+
console.info("onBlinkSendPress");
63+
console.info(blinkData);
64+
}
65+
}
66+
67+
onBlinkStatusPress(val){
68+
this.setState({
69+
blinkStatus: val
70+
});
3671
}
3772

3873
renderNavbar(){
@@ -44,23 +79,35 @@ class BlinkAddPage extends Component {
4479
)
4580
}
4681

47-
renderBlinkInput(){
82+
renderBlinkContent(){
4883
return (
4984
<View style={[ CommonStyles.p_a_3 ]}>
5085
<TextInput
51-
ref="txtComment"
86+
ref="txtBlink"
87+
maxLength = { 1000 }
5288
multiline = { true }
53-
style={ [ComponentStyles.input, styles.input] }
54-
blurOnSubmit= {true}
89+
style={ [ComponentStyles.input, styles.txtBlinkContent] }
5590
placeholder={'请输入闪存内容...'}
5691
placeholderTextColor={ StyleConfig.color_gray }
5792
underlineColorAndroid = { 'transparent' }
58-
onChangeText = {(val)=>this.setState({commentContent: val})}
59-
value={ this.state.commentContent } />
93+
onChangeText = {(val)=>this.setState({blinkContent: val})}
94+
value={ this.state.blinkContent } />
6095
</View>
6196
)
6297
}
6398

99+
renderBlinkStatus(){
100+
return (
101+
<View style={[ CommonStyles.p_a_3, CommonStyles.flexRow, CommonStyles.flexItemsMiddle, CommonStyles.flexItemsBetween, ComponentStyles.panel_bg ]}>
102+
<Text style={[ CommonStyles.text_gray, CommonStyles.font_xs ]}>
103+
是否公开
104+
</Text>
105+
<Switch value={ this.state.blinkStatus }
106+
onValueChange={(value) => this.onBlinkStatusPress(value) }/>
107+
</View>
108+
)
109+
}
110+
64111
renderUserInfo(){
65112
return (
66113
<View style={[ CommonStyles.flexRow, CommonStyles.flexItemsMiddle ]}>
@@ -97,30 +144,30 @@ class BlinkAddPage extends Component {
97144
)
98145
}
99146

100-
renderBlinkMessage(){
101-
return (
102-
<View style={[CommonStyles.p_a_4]}>
103-
<Text style={[ CommonStyles.font_xs, CommonStyles.text_gray, CommonStyles.text_center ]}>
104-
请输入闪存内容
105-
</Text>
106-
</View>
107-
)
147+
renderPending(){
148+
if(this.state.pending === true){
149+
return (
150+
<Spinner style={ ComponentStyles.pending_container }/>
151+
)
152+
}
108153
}
109154

110155
render() {
111156
return (
112157
<View style={ ComponentStyles.container }>
113158
{ this.renderNavbar() }
114-
{ this.renderBlinkInput() }
159+
{ this.renderBlinkStatus() }
160+
{ this.renderBlinkContent() }
115161
{ this.renderBlinkOp() }
116-
{ this.renderBlinkMessage() }
162+
{ this.renderPending() }
163+
<Toast ref="toast"/>
117164
</View>
118165
);
119166
}
120167
}
121168

122169
const styles = StyleSheet.create({
123-
input:{
170+
txtBlinkContent:{
124171
width: StyleConfig.screen_width - ( StyleConfig.space_3 * 2 ),
125172
height: StyleConfig.screen_height / 5,
126173
textAlign: "left",

source/view/commentAdd.js

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,17 @@ import {
88
TouchableOpacity
99
} from 'react-native';
1010

11+
import _ from 'lodash';
1112
import { bindActionCreators } from 'redux';
1213
import { connect } from 'react-redux';
1314
import Icon from 'react-native-vector-icons/Ionicons';
14-
1515
import * as ConfigAction from '../action/config';
1616
import * as UserAction from '../action/user';
1717
import { getImageSource } from '../common';
1818
import { Base64 } from '../common/base64';
1919
import Navbar from '../component/navbar';
20+
import Toast from '../component/toast';
21+
import Spinner from '../component/spinner';
2022
import { StyleConfig, ComponentStyles, CommonStyles } from '../style';
2123

2224
const navTitle = "新增回应";
@@ -31,8 +33,29 @@ class CommentAddPage extends Component {
3133
}
3234
}
3335

36+
commentValidator(){
37+
let commentContent = this.props.commentContent,
38+
message;
39+
if(!_.trim(commentContent)){
40+
message = '请输入回应内容';
41+
}
42+
if(message){
43+
this.refs.toast.show({
44+
message: message
45+
});
46+
return false;
47+
}
48+
return {
49+
Content: commentContent
50+
};
51+
}
52+
3453
onCommentSendPress(){
35-
this.props.router.pop();
54+
let commentData = this.commentValidator();
55+
if(commentData){
56+
console.info("onCommentSendPress");
57+
console.info(commentData);
58+
}
3659
}
3760

3861
renderNavbar(){
@@ -58,7 +81,6 @@ class CommentAddPage extends Component {
5881
)
5982
}
6083

61-
6284
renderSourceContent(data){
6385
let sourceContent = data.Title || data.Content;
6486
return (
@@ -134,14 +156,12 @@ class CommentAddPage extends Component {
134156
)
135157
}
136158

137-
renderCommentMessage(){
138-
return (
139-
<View style={[CommonStyles.p_a_4]}>
140-
<Text style={[ CommonStyles.font_xs, CommonStyles.text_gray, CommonStyles.text_center ]}>
141-
请输入评论内容
142-
</Text>
143-
</View>
144-
)
159+
renderPending(){
160+
if(this.state.pending === true){
161+
return (
162+
<Spinner style={ ComponentStyles.pending_container }/>
163+
)
164+
}
145165
}
146166

147167
render() {
@@ -151,7 +171,8 @@ class CommentAddPage extends Component {
151171
{ this.renderSource() }
152172
{ this.renderCommentInput() }
153173
{ this.renderCommentOp() }
154-
{ this.renderCommentMessage() }
174+
{ this.renderPending() }
175+
<Toast ref="toast"/>
155176
</View>
156177
);
157178
}

source/view/login.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ class LoginPage extends Component {
5252
if(!_.trim(username)){
5353
message = "请输入登录用户名";
5454
}
55-
if(!_.trim(password)){
55+
else if(!_.trim(password)){
5656
message = "请输入登录密码";
5757
}
5858
if(message){
59-
this.refs.toast.show(message);
59+
this.refs.toast.show({
60+
message: message
61+
});
6062
return false;
6163
}
6264
username = this.encryptData(username);

0 commit comments

Comments
 (0)