blazerapp/app/Clubs.js

189 lines
6.0 KiB
JavaScript
Raw Permalink 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';
2021-08-17 21:18:32 -04:00
import Ionicons from 'react-native-vector-icons/Ionicons';
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 (
2021-08-17 21:18:32 -04:00
<ScrollView style = {{backgroundColor: 'white', flex:1, padding: '5%', paddingRight: '10%'}}>
<View style={{display: 'flex', flexDirection: 'row', marginBottom: '5%'}}>
<Ionicons name='location-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
<View style={{display: 'flex', marginLeft: -15, paddingHorizontal: '5%'}}>
<Text style={{fontSize: 16}}>Meeting Location </Text>
<Text style={[styles.title, styles.linktext, {fontSize: 16, fontWeight: '200'}]} onPress={() => Linking.openURL(item.link)}>{item.link}</Text>
2020-12-24 02:34:47 -05:00
</View>
</View>
2021-08-17 21:18:32 -04:00
<View style={{display: 'flex', flexDirection: 'row', marginBottom: '5%'}}>
<Ionicons name='time-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
<View style={{display: 'flex'}}>
<Text style={{fontSize: 16}}>Meeting Date</Text>
<Text style={[styles.title, {fontSize: 16, fontWeight: '200'}]}>{item.meeting}</Text>
2020-12-24 02:34:47 -05:00
</View>
</View>
2021-08-17 21:18:32 -04:00
<View style={{display: 'flex', flexDirection: 'row'}}>
<Ionicons name='person-circle-outline' size={28} color={'#323232'}style={{marginRight: 15, alignSelf: 'center'}}/>
<View style={{display: 'flex'}}>
<Text style={{fontSize: 16}}>Sponsor</Text>
<Text style={[styles.title, {fontSize: 16, fontWeight: '200'}]}>{item.sponsor}</Text>
2020-12-24 02:34:47 -05:00
</View>
</View>
2021-08-17 21:18:32 -04:00
</ScrollView>
2020-10-20 23:12:33 -04:00
)
}
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>
2021-08-17 21:18:32 -04:00
<TouchableOpacity style={[styles.listItem]} 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 = {[styles.container2, {justifyContent: 'space-between'}]}>
<View style={{display: 'flex', flexDirection: 'row'}}>
<Ionicons name = "ios-people-circle-outline" size={36} color={'#323232'} style={{marginRight: 15}} />
<Text style={[styles.title, {alignSelf:'center'}]}>{props.item.name}</Text>
</View>
<Image source = {require('./assets/forward.png')} style={{tintColor: '#b2b2b2'}}/>
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={({
2021-08-17 21:18:32 -04:00
headerShown: true,
headerTitleStyle:morestyles.headerTitle,
headerBackground: ()=>background,
//headerleft: null,
headerTitleAlign: 'center',
headerBackTitleVisible:false,
headerTintColor: 'black',
title:I18n.t('app.clubs'),
2020-10-20 23:12:33 -04:00
})}
/>
<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'}],
2021-08-17 21:18:32 -04:00
headerBackground: ()=>background,
headerBackTitleVisible:false,
headerTintColor: 'black',
headerTitleAlign: 'center',
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 (
2021-08-17 21:18:32 -04:00
<SafeAreaView style={styles.moreDefault}>
2020-08-10 09:14:23 -04:00
<SearchBar
lightTheme
2021-08-17 21:18:32 -04: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)}
/>
</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;