Review.js
9.44 KB
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
import React, { Component } from 'react';
import {Image, View, Text, StyleSheet,ScrollView,TouchableOpacity,Dimensions } from 'react-native';
import Star from '../../Star'
import { TextInput } from 'react-native-gesture-handler';
import ImagePicker from 'react-native-image-picker';
import Camera_big from '../../../assets/Camera_big.svg'
import AsyncStorage from '@react-native-community/async-storage';
import {post }from 'axios'
import { SERVER } from '../../../common/servername';
const options = {
storageOptions: {
skipBackup: true,
path: 'images',
},
};
export default class AddTab extends Component {
static navigationOptions = {
headerShown: false
}
state = {
current:1,
star:0,
img1:null,
img2:null,
img3:null,
comment:"",
user:{},
id:null,
file:null,
file2:null,
file3:null,
}
constructor(props) {
super(props)
}
ImagePick = (i) => {
ImagePicker.launchImageLibrary(options, (response) => {
if (response.didCancel) {
console.log('User cancelled image picker');
} else if (response.error) {
console.log('ImagePicker Error: ', response.error);
} else if (response.customButton) {
console.log('User tapped custom button: ', response.customButton);
} else {
const source = { uri: response.uri };
if(i ===0) {
this.setState({
img1:source,
file:response
})
}
else if(i ===1) {
this.setState({
img2:source,
file2:response
})
}
else if(i ===2) {
this.setState({
img3:source,
file3:response
})
}
// You can also display the image using data:
// const source = { uri: 'data:image/jpeg;base64,' + response.data };
//this.setState({
//avatarSource: source,
//});
}
});
}
componentDidMount() {
AsyncStorage.getItem("user",(err,res) => {
if(res) {
this.setState({
user:JSON.parse(res)
})
}
else {
this.props.navigation.goBack(null)
alert("로그인 후 이용해주세요.")
}
})
if(!this.props.navigation.state.params) {
this.props.navigation.goBack(null)
alert("잘못된 접근입니다.")
}
else {
this.setState({
id:this.props.navigation.state.params.id
})
}
}
onSubmit= () => {
if(!this.state.star) return alert("별점을 선택해주세요.")
if(!this.state.comment) return alert("리뷰를 입력해주세요.")
var formData = new FormData()
//if(this.state.img1) {
// formData.append("image",{uri:this.state.file.uri,name:"jpeg",type:'image/jpeg'})
//
//formData.append('comment',this.state.comment)
//formData.append('nickname',this.state.user.nickname)
//formData.append('grade',this.state.star)
//formData.append('StoreId',this.state.id)
//post(`http://${SERVER}/reviews/${this.state.user.id}`,formData).then(res => {
// if(res.data.success) {
// this.props.navigation.goBack(null)
// alert("리뷰가 등록되었습니다.")
// }
// console.log(res.data)
//})
//}else if(this.state.img2) {
// formData.append("image",{uri:this.state.file2.uri,name:"jpeg",type:'image/jpeg'})
//
//formData.append('comment',this.state.comment)
//formData.append('nickname',this.state.user.nickname)
//formData.append('grade',this.state.star)
//formData.append('StoreId',this.state.id)
//post(`http://${SERVER}/reviews/${this.state.user.id}`,formData).then(res => {
// if(res.data.success) {
// this.props.navigation.goBack(null)
// alert("리뷰가 등록되었습니다.")
// }
//})
//}else if(this.state.img3) {
// formData.append("image",{uri:this.state.file3.uri,name:"jpeg",type:'image/jpeg'})
//
//formData.append('comment',this.state.comment)
//formData.append('nickname',this.state.user.nickname)
//formData.append('grade',this.state.star)
//formData.append('StoreId',this.state.id)
//post(`http://${SERVER}/reviews/${this.state.user.id}`,formData).then(res => {
// if(res.data.success) {
// this.props.navigation.goBack(null)
// alert("리뷰가 등록되었습니다.")
// }
//})
//}
//else {
post(`http://${SERVER}/reviews/${this.state.user.id}`,{comment:this.state.comment,nickname:this.state.user.nickname,grade:this.state.star,StoreId:this.state.id}).then(res => {
if(res.data.success) {
this.props.navigation.goBack(null)
alert("리뷰가 등록되었습니다.")
}
})
//}
}
render() {
return (
<View style={{backgroundColor:"white",height:"100%"}}>
<View style={{width:"100%",flexDirection:"row",paddingTop:16,paddingBottom:16,paddingLeft:16,backgroundColor:"#615F5F"}}>
<TouchableOpacity onPress={() => this.props.navigation.goBack(null)}>
<Image source={require('../../../assets/back.png')}/>
</TouchableOpacity>
<Text style={{color:"white",fontSize:16,marginLeft:16}}>
평점 및 리뷰
</Text>
</View>
<ScrollView style={{padding:16}}>
<View style={{flexDirection:"row"}}>
<Text style={{width:"10%",color:"#615F5F",marginRight:12,alignSelf:"center",fontSize:12}}>
별점
</Text>
<Star Edit={true} item={this.state.star} setItem={(e) => this.setState({star:e})} style={{flexDirection:"row"}} width={26} height={23.55}/>
</View>
<View style={{flexDirection:"row",marginTop:14,marginBottom:17}}>
<Text style={{width:"10%",color:"#615F5F",marginRight:12,alignSelf:"center",fontSize:12}}>
닉네임
</Text>
<Text style={{fontSize:12,color:"#615F5F"}}>
{this.state.user.nickname}
</Text>
</View>
<TextInput value={this.state.comment} onChangeText={e => this.setState({comment:e})} style={{textAlignVertical:"top",paddingTop:13,paddingLeft:16,paddingRight:16,paddingBottom:13,height:Dimensions.get('screen').height*0.3,borderColor:"#FFD63A",borderWidth:1}} placeholder="이벤트 덕분에 슬기로운 야식생활 즐겼습니다."/>
<View style={{flexDirection:"row",marginTop:16.5,justifyContent:"space-between"}}>
<TouchableOpacity onPress={() => this.ImagePick(0)} style={{borderWidth:1,borderColor:"#615F5F",width:Dimensions.get('screen').width*0.25,height:Dimensions.get('screen').width*0.25,justifyContent:"center"}}>
{this.state.img1?<Image resizeMode="stretch" style={{width:"100%",height:"100%"}} source={this.state.img1}/> :<Camera_big style={{alignSelf:"center"}}/>}
</TouchableOpacity>
<TouchableOpacity onPress={() => this.ImagePick(1)} style={{borderWidth:1,borderColor:"#615F5F",width:Dimensions.get('screen').width*0.25,height:Dimensions.get('screen').width*0.25,justifyContent:"center"}}>
{this.state.img2?<Image resizeMode="stretch" style={{width:"100%",height:"100%"}} source={this.state.img2}/> :<Camera_big style={{alignSelf:"center"}}/>}
</TouchableOpacity>
<TouchableOpacity onPress={() => this.ImagePick(2)} style={{borderWidth:1,borderColor:"#615F5F",width:Dimensions.get('screen').width*0.25,height:Dimensions.get('screen').width*0.25,justifyContent:"center"}}>
{this.state.img3?<Image resizeMode="stretch" style={{width:"100%",height:"100%"}} source={this.state.img3}/> :<Camera_big style={{alignSelf:"center"}}/>}
</TouchableOpacity>
</View>
</ScrollView>
<View style={{zIndex:10,marginTop:20,bottom:0,width:"100%"}}>
<TouchableOpacity onPress={() => this.onSubmit()} style={{backgroundColor:"#f4cd37",padding:20}}>
<Text style={{textAlign:"center",fontSize:15,fontWeight:"bold",color:"black"}}>
리뷰쓰기
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const style = StyleSheet.create({
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
}
});