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,
|
|
|
|
TouchableOpacity
|
|
|
|
} 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'
|
2020-08-18 21:29:44 -04:00
|
|
|
|
2020-09-12 19:22:17 -04:00
|
|
|
const StaffElement = ({item}) => {
|
2020-08-18 21:29:44 -04:00
|
|
|
const [visible, setVisible] = useState(0)
|
2020-10-09 21:10:34 -04:00
|
|
|
const extra = [...item.item.emails.map(email=>(<Text key={email}>Email: {email}</Text>))]
|
2020-08-18 21:29:44 -04:00
|
|
|
return(
|
|
|
|
<View>
|
|
|
|
<TouchableOpacity style={styles.item} onPress={()=>setVisible(!visible)} activeOpacity={0.8}>
|
|
|
|
<Text style={styles.title}>{item.item.name}</Text>
|
2020-10-09 21:10:34 -04:00
|
|
|
{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:[],
|
|
|
|
isLoading: true,
|
|
|
|
search:""
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
componentDidMount() {
|
|
|
|
|
|
|
|
fetch(`${url}/api/en/teachers`,{
|
|
|
|
headers: {
|
|
|
|
'Cache-Control': 'no-cache'
|
|
|
|
} })
|
|
|
|
.then((response) => {
|
|
|
|
return response.text();
|
|
|
|
})
|
|
|
|
.then((json) => {
|
2020-10-09 21:10:34 -04:00
|
|
|
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))
|
|
|
|
.finally(() => {
|
|
|
|
this.setState({ isLoading: false });
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
updateSearch = (search) => {
|
|
|
|
this.setState({ search:search });
|
|
|
|
const searchPool = search.startsWith(this.state.search)?this.state.dataSearch:this.state.data;
|
2020-10-09 21:10:34 -04:00
|
|
|
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, isLoading,search} = this.state;
|
|
|
|
return (
|
|
|
|
<SafeAreaView style={styles.container}>
|
|
|
|
<SearchBar
|
|
|
|
lightTheme
|
|
|
|
placeholder="Search Staff"
|
|
|
|
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;
|