Skip to content

Commit

Permalink
Add individual refresh for tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
robertying committed Apr 11, 2019
1 parent 5296191 commit 02bbc02
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions src/screens/CourseDetailScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ import Text from "../components/Text";
import Colors from "../constants/Colors";
import dayjs from "../helpers/dayjs";
import { shareFile } from "../helpers/share";
import { getAssignmentsForCourse } from "../redux/actions/assignments";
import { getFilesForCourse } from "../redux/actions/files";
import { getNoticesForCourse } from "../redux/actions/notices";
import { showToast } from "../redux/actions/toast";
import {
IAssignment,
Expand Down Expand Up @@ -50,9 +53,15 @@ interface ICourseDetailScreenStateProps {
readonly notices: ReadonlyArray<INotice>;
readonly files: ReadonlyArray<IFile>;
readonly assignments: ReadonlyArray<IAssignment>;
readonly isFetchingNotices: boolean;
readonly isFetchingFiles: boolean;
readonly isFetchingAssignments: boolean;
}

interface ICourseDetailScreenDispatchProps {
readonly getNoticesForCourse: (courseId: string) => void;
readonly getFilesForCourse: (courseId: string) => void;
readonly getAssignmentsForCourse: (courseId: string) => void;
readonly showToast: (text: string, duration: number) => void;
}

Expand All @@ -67,7 +76,13 @@ const CourseDetailScreen: INavigationScreen<
notices: rawNotices,
files: rawFiles,
assignments: rawAssignments,
showToast
showToast,
isFetchingAssignments,
isFetchingFiles,
isFetchingNotices,
getAssignmentsForCourse,
getFilesForCourse,
getNoticesForCourse
} = props;

const courseId = navigation.getParam("courseId");
Expand Down Expand Up @@ -125,32 +140,38 @@ const CourseDetailScreen: INavigationScreen<
const NoticesRoute = useMemo(
() => (
<NoticesView
isFetching={false}
isFetching={isFetchingNotices}
notices={notices}
onNoticeCardPress={onNoticeCardPress}
// tslint:disable-next-line: jsx-no-lambda
onRefresh={() => getNoticesForCourse(courseId)}
/>
),
[notices.length, onNoticeCardPress]
[notices.length, isFetchingNotices]
);
const FilesRoute = useMemo(
() => (
<FilesView
isFetching={false}
isFetching={isFetchingFiles}
files={files}
onFileCardPress={onFileCardPress}
// tslint:disable-next-line: jsx-no-lambda
onRefresh={() => getFilesForCourse(courseId)}
/>
),
[files.length]
[files.length, isFetchingFiles]
);
const AssignmentsRoute = useMemo(
() => (
<AssignmentsView
isFetching={false}
isFetching={isFetchingAssignments}
assignments={assignments}
onAssignmentCardPress={onAssignmentCardPress}
// tslint:disable-next-line: jsx-no-lambda
onRefresh={() => getAssignmentsForCourse(courseId)}
/>
),
[assignments.length]
[assignments.length, isFetchingAssignments]
);

const renderScene = ({ route }: SceneRendererProps<any> & Scene<any>) => {
Expand Down Expand Up @@ -228,13 +249,24 @@ CourseDetailScreen.navigationOptions = ({ navigation }) => {
};
};

const mapStateToProps = (state: IPersistAppState) => ({
notices: state.notices.items,
files: state.files.items,
assignments: state.assignments.items
});
function mapStateToProps(
state: IPersistAppState
): ICourseDetailScreenStateProps {
return {
notices: state.notices.items,
files: state.files.items,
assignments: state.assignments.items,
isFetchingNotices: state.notices.isFetching,
isFetchingFiles: state.files.isFetching,
isFetchingAssignments: state.assignments.isFetching
};
}

const mapDispatchToProps: ICourseDetailScreenDispatchProps = {
getNoticesForCourse: (courseId: string) => getNoticesForCourse(courseId),
getFilesForCourse: (courseId: string) => getFilesForCourse(courseId),
getAssignmentsForCourse: (courseId: string) =>
getAssignmentsForCourse(courseId),
showToast: (text: string, duration: number) => showToast(text, duration)
};

Expand Down

0 comments on commit 02bbc02

Please sign in to comment.