From 92b677baaa3bd8691aed83da6e3c2ad4093b6fbc Mon Sep 17 00:00:00 2001 From: M10T Date: Fri, 14 Aug 2020 20:03:40 -0400 Subject: [PATCH] Added teacher to UI for announcement --- app/Announcements.js | 42 +++++++++++++++++++++++++++++++++++------- app/More.js | 10 +++++++++- 2 files changed, 44 insertions(+), 8 deletions(-) diff --git a/app/Announcements.js b/app/Announcements.js index 85b41f9..7496b81 100644 --- a/app/Announcements.js +++ b/app/Announcements.js @@ -7,6 +7,7 @@ import { Text, StatusBar, FlatList, + TouchableOpacity, } from 'react-native'; import { @@ -32,12 +33,34 @@ const Announcement = ({item}) => { ) } +export const TeacherList = ({route}) => { + return + } + keyExtractor={item=>JSON.stringify(item)} + /> + +} + +function TeacherButton(props) { + return ( + + props.navigation.navigate('TeacherList',{data:props.data,name:props.name})} activeOpacity={0.8}> + {props.name} + + + ) +} + class Announcements extends React.Component { constructor(props) { super(props) this.state = { - data: [] + data: [], + teacherNames: [], + isLoading:true } } @@ -49,21 +72,26 @@ class Announcements extends React.Component { } ) .then((response) => { - return response.text(); + return response.text() }) - .then((json) => { - this.setState({data: JSON.parse(json).data}); + .then((txt) => { + const data = JSON.parse(txt).data; + const teacherNames = [...new Set(data.filter(x=>x.teacher!=null&&x.teacher.trim()!=='').map(x=>x.teacher))]; + teacherNames.sort() + this.setState({data: data, teacherNames: teacherNames.map(x=>({name:x})),isLoading:false}); }) .catch((error) => console.error(error)) } render() { + if (this.state.isLoading) return <> return ( + x.teacher==null||x.teacher.trim()==='')} name="No Teacher" navigation={this.props.navigation}/> } - keyExtractor={item=>JSON.stringify(item)} + data={this.state.teacherNames} + renderItem={({item})=>x.teacher===item.name)} name={item.name} navigation={this.props.navigation}/>} + keyExtractor={(item,index)=>item.name+index} /> ) diff --git a/app/More.js b/app/More.js index 9461c46..8b41d90 100644 --- a/app/More.js +++ b/app/More.js @@ -22,7 +22,7 @@ import { NavigationContainer } from '@react-navigation/native' import { createStackNavigator } from '@react-navigation/stack' import styles from './styles/morestyles' -import Announcements from './Announcements' +import Announcements, {TeacherList} from './Announcements' import Resources from './Resources' import StudentWeek from './StudentWeek' import SSLOps from './SSLOps' @@ -129,6 +129,14 @@ class More extends React.Component { headerLeft:null }} /> + ({ + headerTitleStyle:[styles.headerTitle,{alignSelf:'center',marginLeft:"-20%"}], + title:route.params.name + })} + /> )