From d7a2efdde4dc1fc7b10b28f055c58302637cb808 Mon Sep 17 00:00:00 2001 From: Rui Ying Date: Fri, 24 May 2019 23:59:03 +0800 Subject: [PATCH] Make sure courses are updated after switching --- src/screens/AssignmentsScreen.tsx | 4 +--- src/screens/FilesScreen.tsx | 4 +--- src/screens/NoticesScreen.tsx | 4 +--- src/screens/SemestersSettingsScreen.tsx | 6 ++++-- 4 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/screens/AssignmentsScreen.tsx b/src/screens/AssignmentsScreen.tsx index df1091be..121fe979 100644 --- a/src/screens/AssignmentsScreen.tsx +++ b/src/screens/AssignmentsScreen.tsx @@ -129,9 +129,7 @@ const AssignmentsScreen: INavigationScreen = props => { const [searchResult, setSearchResult] = useState(assignments); useEffect(() => { - if (assignments.length) { - setSearchResult(assignments); - } + setSearchResult(assignments); }, [assignments.length]); useEffect(() => { diff --git a/src/screens/FilesScreen.tsx b/src/screens/FilesScreen.tsx index 11380fec..7398e621 100644 --- a/src/screens/FilesScreen.tsx +++ b/src/screens/FilesScreen.tsx @@ -131,9 +131,7 @@ const FilesScreen: INavigationScreen = props => { const [searchResult, setSearchResult] = useState(files); useEffect(() => { - if (files.length) { - setSearchResult(files); - } + setSearchResult(files); }, [files.length]); useEffect(() => { diff --git a/src/screens/NoticesScreen.tsx b/src/screens/NoticesScreen.tsx index 67c74ada..0d9dc268 100644 --- a/src/screens/NoticesScreen.tsx +++ b/src/screens/NoticesScreen.tsx @@ -121,9 +121,7 @@ const NoticesScreen: INavigationScreen = props => { const [searchResult, setSearchResult] = useState(notices); useEffect(() => { - if (notices.length) { - setSearchResult(notices); - } + setSearchResult(notices); }, [notices.length]); useEffect(() => { diff --git a/src/screens/SemestersSettingsScreen.tsx b/src/screens/SemestersSettingsScreen.tsx index 6df114a2..ac6f2fde 100644 --- a/src/screens/SemestersSettingsScreen.tsx +++ b/src/screens/SemestersSettingsScreen.tsx @@ -32,7 +32,7 @@ const SemestersSettingsScreen: INavigationScreen< return () => { store.dispatch(getCoursesForSemester(currentSemester as string)); }; - }, []); + }, [currentSemester]); const renderListItem: ListRenderItem = ({ item }) => { return ( @@ -41,7 +41,9 @@ const SemestersSettingsScreen: INavigationScreen< text={item as string} icon={currentSemester === item ? : null} // tslint:disable-next-line: jsx-no-lambda - onPress={() => setCurrentSemester(item)} + onPress={() => { + setCurrentSemester(item); + }} /> ); };