-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSearch.js
188 lines (167 loc) · 5.84 KB
/
Search.js
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
import React, { Component } from 'react';
import { Image, View, AsyncStorage, LogBox, Dimensions, StatusBar, StyleSheet, TouchableOpacity } from 'react-native';
import { Container, Header, Title, Content, Card, Footer, Icon, Spinner, FooterTab, List, ListItem, CardItem, Thumbnail, Text, Button, Left, Body, Right, Item, Input} from 'native-base';
import * as Font from 'expo-font';
import { Ionicons } from '@expo/vector-icons';
import api from './DbConfig';
StatusBar.setBackgroundColor('#0099ff',true);
const {width, height} = Dimensions.get("window");
export default class Search extends Component {
state = {
loading: true
}
constructor(props){
super(props);
this.state = {
searchtxt:'',
btnsnipper:0,
users:[],
}
}
checking=()=>{
if(this.state.searchtxt.length<2){
}
else{
this.setState({btnsnipper:1});
this.searchuser();
}
}
_retrieveData = async () => {
try{
const useruid = await AsyncStorage.getItem('userid').then((value) => {
this.checkUser();
});
}
catch(err){
console.log('Profile Page store error: '+err);
}
};
checkUser = async ()=>{
try{
const useruid = await AsyncStorage.getItem('userid');
if (useruid!==null) {
}
else{
this.props.navigation.replace("Login");
}
}
catch(err){
console.log('Profile Page store error: '+err);
}
}
searchuser=()=>{
var InsertAPI = api+'search.php';
var Data={search:this.state.searchtxt};
var headers={
'Accept':'application/json',
'Content-Type':'application.json'
}
fetch(InsertAPI,{
method:'POST',
headers:headers,
body:JSON.stringify(Data),
}).then((response)=>response.json()).then((response)=>{
if(response===null){
this.setState({users:null});
this.setState({btnsnipper:0});
}
else{
this.setState({users:response});
this.setState({btnsnipper:0});
}
})
.catch(err=>{
console.log(err);
this.setState({btnsnipper:0});
})
}
async componentDidMount() {
this._retrieveData();
await Font.loadAsync({
'Roboto': require('native-base/Fonts/Roboto.ttf'),
'Roboto_medium': require('native-base/Fonts/Roboto_medium.ttf'),
...Ionicons.font,
})
this.setState({ loading: false })
}
render() {
if (this.state.loading) {
return (
<View></View>
);
}
return (
<Container>
<Header style={{backgroundColor:'#0099ff'}} androidStatusBarColor='#0099ff'>
<Left>
<Button transparent onPress={()=>{this.props.navigation.goBack()}}>
<Icon name='arrow-back' />
</Button>
</Left>
<Body>
<Title>SEARCH</Title>
</Body>
<Right />
</Header>
<View style={{backgroundColor:'#0099ff', padding:10}}>
<Item regular style={{height:40, backgroundColor:'#fff', borderRadius:20}}>
<Input placeholder='Search creator'
onChangeText={(searchtxt) =>{this.setState({searchtxt}); this.checking()}}/>
<Icon name="search"/>
</Item>
</View>
{this.state.btnsnipper==0?
<View>
{this.state.users==null?
<Text style={{textAlign:'center', marginTop:50}}>User not found !</Text>:<List dataArray={this.state.users} renderRow={(item) =>
<ListItem thumbnail onPress={()=>{this.props.navigation.navigate("Userprofile",{userid:item.id, username:item.name, userimg:item.image, usertag:item.tagname,instagram:item.instagram,facebook:item.facebook,linkedin:item.linkedin,github:item.github})}}>
<Left>
<Thumbnail rounded source={{uri:item.image}} />
</Left>
<Body>
<Text>{item.name}</Text>
<Text note numberOfLines={1}>{item.tagname}</Text>
</Body>
</ListItem>}/>}
</View>:<Thumbnail source={require('./assets/searchprofile.gif')}
style={{height:height/3,width:width, resizeMode:'contain'}}
/>}
<Content>
</Content>
<Footer>
<FooterTab style={{backgroundColor:'#fff'}}>
<Button onPress={()=>{this.props.navigation.replace("Home")}}>
<Icon name="home" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Feed")}}>
<Icon name="grid" />
</Button>
<Button active style={{backgroundColor:'#0099ff'}}>
<Icon name="search" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Upload")}}>
<Icon active name="paper-plane" />
</Button>
<Button onPress={()=>{this.props.navigation.replace("Profile")}}>
<Icon name="person" />
</Button>
</FooterTab>
</Footer>
</Container>
);
}
}
const styles = StyleSheet.create({
myHeader:{
height:120,
backgroundColor:'#0099FF',
justifyContent:'center',
padding:15,
elevation:7,
},
headerText:{
fontSize:25,
fontWeight:'bold',
color:'#fff',
},
})