import React, { useState } from 'react'; import { SafeAreaView, StyleSheet, ScrollView, View, Text, StatusBar, ActivityIndicator, FlatList, TouchableOpacity, Image, TouchableHighlight, Linking } from 'react-native'; import { Header, LearnMoreLinks, Colors, DebugInstructions, ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; import { NavigationContainer } from '@react-navigation/native' import { createStackNavigator } from '@react-navigation/stack' import { SearchBar } from 'react-native-elements'; import styles from './styles/liststyles' import morestyles from './styles/morestyles' import { url } from './resources/fetchInfo.json' import LinearGradient from 'react-native-linear-gradient'; import Ionicons from 'react-native-vector-icons/Ionicons'; import I18n from './i18n'; const Stack = createStackNavigator(); export const StaffInfo = ({route}) => { const item = route.params; console.log(item); return ( /* {item.emails.map(email => {email} )} */ {item.name} {item.position || ""} {item.emails && {"Email"} {item.emails.map(email => {email} )} } {item.phone && {"Phone"} {item.phone.map(num => {num} )} } ) } function StaffElement (props) { const item = props.item; return( props.navigation.navigate('StaffInfo', {data:props.data,name:props.name,emails:item.emails})} activeOpacity={0.8}> {props.item.name} ) } const background = () function Staff () { return ( background, //headerleft: null, title:I18n.t('app.staff'), headerBackTitleVisible:false, headerTintColor: 'black', headerTitleAlign: 'center' })} /> ({ title:route.params.name, headerTitleStyle:[morestyles.headerTitle,{alignSelf:'center'}], headerBackground: ()=>background, headerBackTitleVisible:false, headerTintColor: 'black', headerTitleAlign: 'center', })} /> ) } class Staffs extends React.Component { constructor(props) { super(props); this.state = { data: [], dataSearch:[], search:"" }; } componentDidMount() { this.getData() this.props.navigation.addListener( 'focus', () => { this.getData() } ); } getData() { fetch(`${url}/api/`+String(I18n.locale).split('-')[0]+`/teachers`,{ headers: { 'Cache-Control': 'no-cache' } }) .then((response) => { return response.text(); }) .then((json) => { const data = JSON.parse(json) data.sort((a,b)=>a.id-b.id) this.setState({data: data}); this.setState({dataSearch: data}); }) .catch((error) => console.error(error)) } 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().startsWith(search.toLowerCase())}) this.setState({dataSearch: ds}) }; clearSearch = (search)=>{ const ds = this.state.data; this.setState({dataSearch:ds}) } render() { const { data , dataSearch,search} = this.state; if (this.state.isLoading) { return } else { return ( } keyExtractor={item => JSON.stringify(item)} /> );} } } export default Staff;