2020-08-09 17:01:25 -04:00
|
|
|
import React from 'react';
|
|
|
|
import {
|
|
|
|
SafeAreaView,
|
|
|
|
StyleSheet,
|
|
|
|
ScrollView,
|
|
|
|
View,
|
|
|
|
Text,
|
|
|
|
StatusBar,
|
2020-08-10 00:51:06 -04:00
|
|
|
ActivityIndicator,
|
|
|
|
FlatList,
|
2020-08-09 17:01:25 -04:00
|
|
|
} from 'react-native';
|
|
|
|
|
|
|
|
import {
|
|
|
|
Header,
|
|
|
|
LearnMoreLinks,
|
|
|
|
Colors,
|
|
|
|
DebugInstructions,
|
|
|
|
ReloadInstructions,
|
|
|
|
} from 'react-native/Libraries/NewAppScreen';
|
2020-08-10 09:14:23 -04:00
|
|
|
import { SearchBar } from 'react-native-elements';
|
2020-08-09 17:01:25 -04:00
|
|
|
|
2020-08-10 00:51:06 -04:00
|
|
|
const ClubElement = ({item}) => {
|
2020-08-10 09:14:23 -04:00
|
|
|
//console.log(item)
|
2020-08-10 00:51:06 -04:00
|
|
|
return(
|
|
|
|
<View style={styles.item}>
|
|
|
|
<Text style={styles.title}>{item.item.name}</Text>
|
|
|
|
<Text>Location: {item.item.loc} {"\n"}Sponsor: {item.item.sponsor}</Text>
|
|
|
|
</View>
|
|
|
|
)
|
2020-08-09 17:01:25 -04:00
|
|
|
}
|
2020-08-10 00:51:06 -04:00
|
|
|
class Clubs extends React.Component {
|
2020-08-10 09:14:23 -04:00
|
|
|
|
2020-08-10 00:51:06 -04:00
|
|
|
|
|
|
|
constructor(props) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
data: [],
|
2020-08-10 09:14:23 -04:00
|
|
|
dataSearch:[],
|
|
|
|
isLoading: true,
|
|
|
|
search:""
|
2020-08-10 00:51:06 -04:00
|
|
|
};
|
|
|
|
}
|
2020-08-09 17:01:25 -04:00
|
|
|
|
2020-08-10 00:51:06 -04:00
|
|
|
componentDidMount() {
|
2020-08-10 09:14:23 -04:00
|
|
|
|
|
|
|
fetch('https://6dc2642ae9b3.ngrok.io/api/en/clubs',{
|
2020-08-10 00:51:06 -04:00
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'no-cache'
|
|
|
|
} })
|
|
|
|
.then((response) => {
|
|
|
|
//console.log(response.text());
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
2020-08-10 09:14:23 -04:00
|
|
|
//onsole.log("done bitch?")
|
|
|
|
//console.log(json);
|
2020-08-10 10:48:27 -04:00
|
|
|
this.setState({data: JSON.parse(json).clubs});
|
|
|
|
this.setState({dataSearch:JSON.parse(json).clubs });
|
2020-08-10 00:51:06 -04:00
|
|
|
})
|
|
|
|
.catch((error) => console.error(error))
|
|
|
|
.finally(() => {
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
});
|
2020-08-10 09:14:23 -04:00
|
|
|
|
|
|
|
}
|
|
|
|
updateSearch = (search) => {
|
|
|
|
this.setState({ search:search });
|
|
|
|
ds = this.state.dataSearch.filter((thing)=>{return thing.name.startsWith(search)})
|
|
|
|
this.setState({dataSearch: ds})
|
2020-08-10 09:21:05 -04:00
|
|
|
if (search == ""){
|
|
|
|
this.setState({dataSearch:this.state.data})
|
|
|
|
}
|
2020-08-10 09:14:23 -04:00
|
|
|
};
|
|
|
|
clearSearch = (search)=>{
|
|
|
|
ds = this.state.data;
|
|
|
|
this.setState({dataSearch:ds})
|
2020-08-10 00:51:06 -04:00
|
|
|
}
|
|
|
|
render() {
|
2020-08-10 09:14:23 -04:00
|
|
|
const { data , dataSearch, isLoading,search} = this.state;
|
2020-08-10 00:51:06 -04:00
|
|
|
|
|
|
|
return (
|
2020-08-10 09:14:23 -04:00
|
|
|
|
|
|
|
|
2020-08-10 00:51:06 -04:00
|
|
|
<SafeAreaView style={styles.container}>
|
2020-08-10 09:14:23 -04:00
|
|
|
<SearchBar
|
|
|
|
lightTheme
|
|
|
|
placeholder="Type Here..."
|
|
|
|
onChangeText={this.updateSearch}
|
2020-08-10 09:21:05 -04:00
|
|
|
onCancel={this.clearSearch}
|
2020-08-10 09:14:23 -04:00
|
|
|
onClear={this.clearSearch}
|
|
|
|
value={this.state.search}/>
|
2020-08-10 00:51:06 -04:00
|
|
|
<FlatList
|
2020-08-10 09:14:23 -04:00
|
|
|
data={dataSearch}
|
2020-08-10 00:51:06 -04:00
|
|
|
renderItem={item => <ClubElement item={item}/>}
|
|
|
|
keyExtractor={item => JSON.stringify(item)}
|
|
|
|
/>
|
|
|
|
</SafeAreaView>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
flex: 1,
|
|
|
|
marginTop: StatusBar.currentHeight || 0,
|
|
|
|
},
|
|
|
|
item: {
|
|
|
|
backgroundColor: '#bababa',
|
|
|
|
padding: 20,
|
|
|
|
marginVertical: 8,
|
|
|
|
marginHorizontal: 16,
|
|
|
|
},
|
|
|
|
title: {
|
|
|
|
fontSize: 32,
|
|
|
|
},
|
|
|
|
});
|
2020-08-09 17:01:25 -04:00
|
|
|
export default Clubs;
|