blazerapp/app/Clubs.js

180 lines
5.2 KiB
JavaScript
Raw Normal View History

2020-08-10 15:25:00 -04:00
import React, { useState } from 'react';
2020-08-09 17:01:25 -04:00
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-08-10 00:51:06 -04:00
ActivityIndicator,
FlatList,
2020-10-20 23:12:33 -04:00
TouchableOpacity,
Image,
TouchableHighlight,
Linking
2020-08-09 17:01:25 -04:00
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-10-20 23:12:33 -04:00
import { NavigationContainer } from '@react-navigation/native'
import { createStackNavigator } from '@react-navigation/stack'
2020-08-10 09:14:23 -04:00
import { SearchBar } from 'react-native-elements';
2020-08-10 17:41:10 -04:00
import styles from './styles/liststyles'
import morestyles from './styles/morestyles'
import { url } from './resources/fetchInfo.json'
import LinearGradient from 'react-native-linear-gradient';
2021-01-01 00:23:17 -05:00
import I18n from './i18n';
2020-08-09 17:01:25 -04:00
2020-10-20 23:12:33 -04:00
const Stack = createStackNavigator();
export const ClubInfo = ({route}) => {
const item = route.params;
return (
2020-11-20 02:44:02 -05:00
<View style = {{padding: 10, backgroundColor: 'white', height: '100%'}}>
2020-12-24 02:34:47 -05:00
<View style ={[styles.infoContainer, {flexDirection: 'row', alignItems: 'center'}]}>
<View style={{width: '17%', display: 'flex', justifyContent: 'center'}}>
<Image source ={require('./assets/time.png')} style={{width: 50, height: 50}}/>
</View>
<View style={{width: '83%'}}>
<Text style = {{fontSize:20}}>{item.meeting}</Text>
</View>
</View>
2020-12-24 02:34:47 -05:00
<View style ={[styles.infoContainer, {flexDirection: 'row', alignItems: 'center'}]}>
<View style={{width: '17%', display: 'flex', justifyContent: 'center'}}>
<Image source ={require('./assets/zoom.png')} style={{width: 50, height: 50}}/>
</View>
<View style={{width: '83%'}}>
<Text style = {[styles.linktext,{fontSize:20}]} onPress={() => Linking.openURL(item.link)}>{item.link}</Text>
</View>
</View>
2020-12-24 02:34:47 -05:00
<View style ={[styles.infoContainer, {flexDirection: 'row', alignItems: 'center'}]}>
<View style={{width: '17%', display: 'flex', justifyContent: 'center'}}>
<Image source ={require('./assets/sponsor.png')} style={{width: 50, height: 50}}/>
</View>
<View style={{width: '83%'}}>
<Text style = {{fontSize:20}}>{item.sponsor}</Text>
</View>
</View>
2020-10-20 23:12:33 -04:00
</View>
)
}
function ClubElement (props) {
const item = props.item;
2020-08-10 00:51:06 -04:00
return(
2020-08-10 15:25:00 -04:00
<View>
2020-10-20 23:12:33 -04:00
<TouchableOpacity style={styles.item1} onPress={()=>props.navigation.navigate('ClubInfo', {data:props.data,name:props.name,meeting:item.meeting,link:item.link,sponsor:item.sponsor})} activeOpacity={0.8}>
<View style = {{display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
<Image source = {require('./assets/clubs.png')} style = {{height: 40, width: 40, marginRight: 10}}/>
2020-11-20 02:44:02 -05:00
<Text style={styles.title3}>{props.item.name}</Text>
2020-10-20 23:12:33 -04:00
</View>
</TouchableOpacity>
2020-08-10 15:25:00 -04:00
</View>
2020-08-10 00:51:06 -04:00
)
2020-08-09 17:01:25 -04:00
}
2020-08-10 09:14:23 -04:00
2020-12-24 01:35:25 -05:00
const background = (<LinearGradient
colors={['#f99', 'white']}
style = {{flex:1,borderBottomColor:'black',borderBottomWidth:0.5}}
/>)
2020-10-20 23:12:33 -04:00
function Club () {
return (
<NavigationContainer independent={true}>
<Stack.Navigator>
<Stack.Screen
name = "Clubs"
component = {Clubs}
options={({
headerShown: false
})}
/>
<Stack.Screen
name = "ClubInfo"
component = {ClubInfo}
options={({route})=>({
title:route.params.name,
2020-12-24 01:35:25 -05:00
headerTitleStyle:[morestyles.headerTitle,{alignSelf:'center'}],
headerBackground: ()=>background
2020-10-20 23:12:33 -04:00
})}
/>
</Stack.Navigator>
</NavigationContainer>
)
}
class Clubs extends React.Component {
2020-08-10 00:51:06 -04:00
constructor(props) {
super(props);
this.state = {
data: [],
2020-08-10 09:14:23 -04:00
dataSearch:[],
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() {
this.getData()
this.props.navigation.addListener(
'focus',
() => {
this.getData()
}
);
}
getData() {
fetch(`${url}/api/en/clubs`,{
2020-08-10 00:51:06 -04:00
headers: {
'Cache-Control': 'no-cache'
} })
.then((response) => {
return response.text();
})
.then((json) => {
this.setState({data: JSON.parse(json).clubs,dataSearch:JSON.parse(json).clubs });
2020-08-10 00:51:06 -04:00
})
.catch((error) => console.error(error))
2020-08-10 09:14:23 -04:00
}
2020-08-10 09:14:23 -04:00
updateSearch = (search) => {
this.setState({ search:search });
2020-08-10 15:25:00 -04:00
const searchPool = search.startsWith(this.state.search)?this.state.dataSearch:this.state.data;
const ds = searchPool.filter((thing)=>{return thing.name.toLowerCase().startsWith(search.toLowerCase())})
2020-08-10 09:14:23 -04:00
this.setState({dataSearch: ds})
};
clearSearch = (search)=>{
2020-08-10 15:25:00 -04:00
const ds = this.state.data;
2020-08-10 09:14:23 -04:00
this.setState({dataSearch:ds})
2020-08-10 00:51:06 -04:00
}
render() {
const { data , dataSearch,search} = this.state;
2020-08-10 00:51:06 -04:00
return (
<SafeAreaView style={styles.container}>
2020-08-10 09:14:23 -04:00
<SearchBar
lightTheme
2021-01-01 00:23:17 -05:00
placeholder={I18n.t('clubs.searchClubs')}
2020-08-10 09:14:23 -04:00
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-10-20 23:12:33 -04:00
renderItem={({item}) => <ClubElement item={item} name={item.name} navigation={this.props.navigation}/>}
2020-08-10 00:51:06 -04:00
keyExtractor={item => JSON.stringify(item)}
/>
2020-10-20 23:12:33 -04:00
2020-08-10 00:51:06 -04:00
</SafeAreaView>
2020-10-20 23:12:33 -04:00
2020-08-10 00:51:06 -04:00
);
}
}
2020-08-10 17:41:10 -04:00
2020-10-20 23:12:33 -04:00
export default Club;