blazerapp/app/Staff.js

126 lines
3.5 KiB
JavaScript
Raw Normal View History

2020-08-18 21:29:44 -04:00
import React, { useState } from 'react';
import {
SafeAreaView,
StyleSheet,
ScrollView,
View,
Text,
StatusBar,
2020-09-12 19:22:17 -04:00
ActivityIndicator,
2020-08-18 21:29:44 -04:00
FlatList,
2020-10-20 23:12:33 -04:00
TouchableOpacity,
Image,
Linking
2020-08-18 21:29:44 -04:00
} from 'react-native';
import {
Header,
LearnMoreLinks,
Colors,
DebugInstructions,
ReloadInstructions,
} from 'react-native/Libraries/NewAppScreen';
2020-09-12 19:22:17 -04:00
import { SearchBar } from 'react-native-elements';
2020-08-18 21:29:44 -04:00
import styles from './styles/liststyles'
2020-09-12 19:22:17 -04:00
import { url } from './resources/fetchInfo.json'
2021-01-01 00:23:17 -05:00
import I18n from './i18n';
2020-08-18 21:29:44 -04:00
2020-09-12 19:22:17 -04:00
const StaffElement = ({item}) => {
const [visible, setVisible] = useState(false)
2020-12-24 01:35:25 -05:00
const extra = (
[
...item.item.emails.map(email=>(
<View style={{display: 'flex', flexDirection: 'row', alignItems: 'center', marginTop: '2%', paddingHorizontal: '1%'}}>
2020-12-24 02:34:47 -05:00
<View style={{width: '10%', display: 'flex', justifyContent: 'center'}}>
<Image source={require('./assets/email.png')} style={{height: 22, width: 22}}/>
</View>
<View style={{width: '90%'}}>
<Text key={email}><Text style={styles.linktext} onPress={()=>Linking.openURL("mailto:"+email)}><Text></Text>{email}</Text></Text>
</View>
2020-12-24 01:35:25 -05:00
</View>
2020-12-24 19:25:25 -05:00
))
2020-12-24 01:35:25 -05:00
]
)
//const extra = [...item.item.emails.map(email=>(<Text key={email}>{'\n'}Email: <Text style={styles.linktext} onPress={()=>Linking.openURL("mailto:"+email)}>{email}</Text></Text>))]
2020-08-18 21:29:44 -04:00
return(
<View>
2020-10-20 23:12:33 -04:00
<TouchableOpacity style={styles.item1} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
<View style = {{display: 'flex', flexDirection: 'row', alignItems: 'center'}}>
<Image source = {require('./assets/staff.png')} style = {{height: 40, width: 40, marginRight: 10}}/>
2020-11-20 02:44:02 -05:00
<Text style={styles.title3}>{item.item.name}</Text>
2020-10-20 23:12:33 -04:00
</View>
{visible?extra:<></>}
2020-08-18 21:29:44 -04:00
</TouchableOpacity>
</View>
)
}
class Staff extends React.Component {
2020-09-12 19:22:17 -04:00
2020-08-18 21:29:44 -04:00
constructor(props) {
2020-09-12 19:22:17 -04:00
super(props);
this.state = {
data: [],
dataSearch:[],
search:""
};
}
componentDidMount() {
this.getData()
this.props.navigation.addListener(
'focus',
() => {
this.getData()
}
);
}
getData() {
fetch(`${url}/api/en/teachers`,{
2020-09-12 19:22:17 -04:00
headers: {
'Cache-Control': 'no-cache'
} })
.then((response) => {
return response.text();
})
.then((json) => {
this.setState({data: JSON.parse(json).data});
this.setState({dataSearch:JSON.parse(json).data});
2020-09-12 19:22:17 -04:00
})
.catch((error) => console.error(error))
}
2020-09-12 19:22:17 -04:00
updateSearch = (search) => {
this.setState({ search:search });
const searchPool = search.startsWith(this.state.search)?this.state.dataSearch:this.state.data;
const ds = searchPool.filter((thing)=>{return thing.name.toLowerCase().split(' ').some(x=>x.startsWith(search.toLowerCase()))})
2020-09-12 19:22:17 -04:00
this.setState({dataSearch: ds})
};
clearSearch = (search)=>{
const ds = this.state.data;
this.setState({dataSearch:ds})
}
render() {
const { data , dataSearch,search} = this.state;
2020-09-12 19:22:17 -04:00
return (
<SafeAreaView style={styles.container}>
<SearchBar
lightTheme
2021-01-01 00:23:17 -05:00
placeholder={I18n.t('staff.searchStaff')}
2020-09-12 19:22:17 -04:00
onChangeText={this.updateSearch}
onCancel={this.clearSearch}
onClear={this.clearSearch}
value={this.state.search}/>
<FlatList
data={dataSearch}
renderItem={item => <StaffElement item={item}/>}
keyExtractor={item => JSON.stringify(item)}
/>
</SafeAreaView>
);
}
2020-08-18 21:29:44 -04:00
}
export default Staff;