From 36a64a25b59b905f2471c182734fe632e27ba2aa Mon Sep 17 00:00:00 2001 From: M10T Date: Fri, 6 Nov 2020 20:39:39 -0500 Subject: [PATCH] Added reloading to calendar and clubs data --- app/Announcements.js | 17 +++++++----- app/Calendar.js | 65 ++++++++++++++++++++++++++++++++++++++++++-- app/Clubs.js | 30 +++++++++++--------- app/More.js | 6 ++-- app/Staff.js | 21 ++++++++------ 5 files changed, 107 insertions(+), 32 deletions(-) diff --git a/app/Announcements.js b/app/Announcements.js index e0ac1fc..2d06c8d 100644 --- a/app/Announcements.js +++ b/app/Announcements.js @@ -54,7 +54,7 @@ function TeacherButton(props) { const [color, setColor] = useState(props.color?props.color:'lightgrey') return ( - props.navigation.navigate('TeacherList',{data:props.data,name:props.name})} activeOpacity={0.8}> + {props.navigation.navigate('TeacherList',{data:props.data,name:props.name})}} activeOpacity={0.8}> {props.name} {props.icon?{setColor(color=='#dba309'?'lightgrey':'#dba309');props.addFavorite(props.name)}}/>:<>} @@ -89,6 +89,15 @@ class Announcements extends React.Component { } componentDidMount() { + this.getData() + AsyncStorage.getItem(STORAGE_KEY) + .then(value=>value==null?[]:JSON.parse(value).map(x=>({name:x}))) + .then(names=>this.setState({favoriteNames:names})) + .catch(console.log) + .done() + } + + getData() { fetch(`${url}/api/en/announcements`,{ headers: { 'Cache-Control': 'no-cache' @@ -105,12 +114,6 @@ class Announcements extends React.Component { this.setState({data: data, teacherNames: teacherNames.map(x=>({name:x})),isLoading:false}); }) .catch((error) => console.error(error)) - - AsyncStorage.getItem(STORAGE_KEY) - .then(value=>value==null?[]:JSON.parse(value).map(x=>({name:x}))) - .then(names=>this.setState({favoriteNames:names})) - .catch(console.log) - .done() } render() { diff --git a/app/Calendar.js b/app/Calendar.js index 9de683f..9aa4914 100644 --- a/app/Calendar.js +++ b/app/Calendar.js @@ -1,4 +1,4 @@ -import React from 'react'; +import React, {useState} from 'react'; import { SafeAreaView, StyleSheet, @@ -6,6 +6,8 @@ import { View, Text, StatusBar, + FlatList, + TouchableOpacity } from 'react-native'; import { @@ -16,11 +18,70 @@ import { ReloadInstructions, } from 'react-native/Libraries/NewAppScreen'; +import styles from './styles/liststyles' +import { url } from './resources/fetchInfo.json' + +const Event = ({item}) => { + const [visible, setVisible] = useState(false) + const date = item.item.date.split('-') + const extra = ( + <> + {item.item.text} + Location: {item.item.location} + Date: {`${date[1]}/${date[2]}/${date[0]}`} + + ) + return ( + setVisible(!visible)} activeOpacity={0.8}> + {item.item.title} + {visible?extra:<>} + + ) +} + class Calendar extends React.Component { + + constructor(props) { + super(props) + this.state = { + data: [] + } + } + + componentDidMount() { + this.getData() + this.props.navigation.addListener( + 'focus', + () => { + this.getData() + } + ); + } + + getData() { + fetch(`${url}/api/en/events`,{ + headers: { + 'Cache-Control': 'no-cache' + } }) + .then((response) => { + return response.text(); + }) + .then((json) => { + const data = JSON.parse(json).data + data.sort((a,b)=>new Date(b.date).getTime()-new Date(a.date).getTime()) + this.setState({data: data}); + }) + .catch((error) => console.error(error)) + } + render() { return ( - + } + keyExtractor={item=>JSON.stringify(item)} + /> ) } diff --git a/app/Clubs.js b/app/Clubs.js index be9ff88..926058e 100644 --- a/app/Clubs.js +++ b/app/Clubs.js @@ -37,15 +37,15 @@ export const ClubInfo = ({route}) => { Meeting Time and Day: - {item.meeting} + {item.meeting} Zoom Link: - Linking.openURL(item.link)}>{item.link} + Linking.openURL(item.link)}>{item.link} Sponsor: - {item.sponsor} + {item.sponsor} ) @@ -97,14 +97,22 @@ class Clubs extends React.Component { this.state = { data: [], dataSearch:[], - isLoading: true, search:"" }; } componentDidMount() { - - fetch(`${url}/api/en/clubs`,{ + this.getData() + this.props.navigation.addListener( + 'focus', + () => { + this.getData() + } + ); + } + + getData() { + fetch(`${url}/api/en/clubs`,{ headers: { 'Cache-Control': 'no-cache' } }) @@ -112,15 +120,11 @@ class Clubs extends React.Component { return response.text(); }) .then((json) => { - this.setState({data: JSON.parse(json).clubs}); - this.setState({dataSearch:JSON.parse(json).clubs }); + this.setState({data: JSON.parse(json).clubs,dataSearch:JSON.parse(json).clubs }); }) .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; @@ -132,7 +136,7 @@ class Clubs extends React.Component { this.setState({dataSearch:ds}) } render() { - const { data , dataSearch, isLoading,search} = this.state; + const { data , dataSearch,search} = this.state; return ( diff --git a/app/More.js b/app/More.js index 99fcf3d..8b825ee 100644 --- a/app/More.js +++ b/app/More.js @@ -143,7 +143,8 @@ class More extends React.Component { component={LunchInfo} options={({route})=>({ headerTitleStyle:[styles.headerTitle,{alignSelf:'center'}], - title:route.params.name + title:route.params.name, + headerRight:()=>(<>) })} /> ({ headerTitleStyle:[styles.headerTitle,{alignSelf:'center'}], - title:route.params.name + title:route.params.name, + headerRight:()=>(<>) })} /> diff --git a/app/Staff.js b/app/Staff.js index ef10cb9..fd80445 100644 --- a/app/Staff.js +++ b/app/Staff.js @@ -48,14 +48,22 @@ class Staff extends React.Component { this.state = { data: [], dataSearch:[], - isLoading: true, search:"" }; } componentDidMount() { - - fetch(`${url}/api/en/teachers`,{ + this.getData() + this.props.navigation.addListener( + 'focus', + () => { + this.getData() + } + ); + } + + getData() { + fetch(`${url}/api/en/teachers`,{ headers: { 'Cache-Control': 'no-cache' } }) @@ -67,11 +75,8 @@ class Staff extends React.Component { this.setState({dataSearch:JSON.parse(json).data}); }) .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; @@ -83,7 +88,7 @@ class Staff extends React.Component { this.setState({dataSearch:ds}) } render() { - const { data , dataSearch, isLoading,search} = this.state; + const { data , dataSearch,search} = this.state; return (