BlackList.js
6.67 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 More from '../../assets/more_.svg'
import Store_Post from '../Store_Post'
import Checkbox from '@react-native-community/checkbox'
import * as Location from 'expo-location';
import {View,Text,RefreshControl,Image,ScrollView,Dimensions,TextInput,TouchableOpacity,StatusBar,StyleSheet} from 'react-native'
import { post,all, get, put, delete as remove } from 'axios'
import AsyncStorage from '@react-native-community/async-storage';
import { SERVER } from '../../common/servername';
class MainPage extends Component {
state = {
refreshing:false,
store_posts: [
],
location:null,
checkbox:[],
user:{}
}
constructor(props) {
super(props)
}
_onRefresh = () => {
this.setState({refreshing: true});
this.setState({
refreshing:false,
})
}
componentDidMount() {
(async () => {
let location = await Location.getCurrentPositionAsync({});
this.setState({
location,
},() => {
AsyncStorage.getItem("user",(err,res) => {
if(res) {
this.setState({
user:JSON.parse(res)
})
post(`http://${SERVER}/blacks/read`,{UserId:JSON.parse(res).id,latitude:this.state.location.coords.latitude, longitude:this.state.location.coords.longitude,sorting:"distance"}).then(res => {
this.setState({
checkbox:res.data.data.map((e,i) => {
return false
})
},() => {
})
this.setState({
store_posts:res.data.data
})
})
}
})
})
})();
}
handleCheckbox = (i) => {
this.setState((prev)=>({
checkbox:[
...prev.checkbox.slice(0,i),
!prev.checkbox[i],
...prev.checkbox.slice(i+1,prev.checkbox.length)
]
}),() => {
})
}
checkAll = () => {
this.setState({
checkbox:this.state.store_posts.map((e,i) => {
return true
})
})
}
cancel_black = () => {
all(this.state.checkbox.map((e,i) => {
if(e == true) {
remove(`http://${SERVER}/blacks/${this.state.store_posts[i].id}`)
}
})).then(() => {
alert("차단이 해제되었습니다.")
post(`http://${SERVER}/blacks/read`,{UserId:this.state.user.id,latitude:this.state.location.coords.latitude, longitude:this.state.location.coords.longitude,sorting:"distance"}).then(res => {
this.setState({
checkbox:res.data.data.map((e,i) => {
return false
})
},() => {
})
this.setState({
store_posts:res.data.data
})
})
})
}
render() {
return (
<View style={{width:"100%",height:"100%",backgroundColor:"#979292"}}>
<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>
<TouchableOpacity style={{marginLeft:"auto",marginRight:16}} onPress={() => this.props.navigation.navigate("EditLike")} >
<More />
</TouchableOpacity>
</View>
<ScrollView style={{paddingLeft:16,paddingRight:16,paddingTop:16,width:"100%"}}>
{this.state.store_posts.map((e,i) =>
<View style={{width:"80%",flexDirection:"row",marginBottom:16}}>
<Checkbox onChange={() => this.handleCheckbox(i)} value={this.state.checkbox[i]} tintColors={{true:'#f4cd37'}} style={{alignSelf:"center",marginRight:10}}/>
<Store_Post size="small" contentsVisible={false} navigation={this.props.navigation} index={null} item={e}/>
</View>
)}
<View style={{height:16}}>
</View>
</ScrollView>
<View style={{width:"100%",flexDirection:"row"}}>
<TouchableOpacity onPress={() => this.checkAll()} style={{backgroundColor:"white",width:"50%",paddingTop:21,paddingBottom:19}}>
<Text style={{fontWeight:"bold",textAlign:"center",color:"black",fontSize:15}}>
전체 선택
</Text>
</TouchableOpacity>
<TouchableOpacity onPress={() => this.cancel_black()} style={{backgroundColor:"#FFD63A",width:"50%",paddingTop:21,paddingBottom:19}}>
<Text style={{fontWeight:"bold",textAlign:"center",color:"black",fontSize:15}}>
차단 해제
</Text>
</TouchableOpacity>
</View>
</View>
);
}
}
const style=StyleSheet.create({
list_pick_event: {
paddingTop:17,
paddingBottom:17,
borderBottomColor:"#BBB9B9",
borderTopColor:"#BBB9B9",
borderBottomWidth:0.5,
},
container: {
flex: 1,
alignItems: 'center',
justifyContent: 'center',
},
avatar : {
width:32,
height:32,
borderRadius:100,
},
detail: {
marginLeft:15,
flex:1,
flexDirection:"row",
},
hit: {
fontSize:9,
fontWeight:"bold"
},
date: {
marginLeft:9,
fontSize:9,
color:"black"
},
userWrapper : {
flex:1,
flexDirection:"row",
paddingTop:13,
paddingBottom:17,
borderBottomColor:"#AEAEAE",
borderBottomWidth:1,
},
nickname : {
marginLeft:10,
fontSize:13,
fontWeight:"bold",
color:"black"
},
title : {
fontSize:13,
fontWeight:"bold",
color:"black"
},
like : {
marginTop:3,
fontSize:10,
color:"red",
marginLeft:5,
},
titleWrapper : {
marginTop:17,
paddingLeft:19,
flex:1,
flexDirection:"row"
}
})
export default MainPage