Skip to content

Commit

Permalink
Fix notification update logic
Browse files Browse the repository at this point in the history
  • Loading branch information
robertying committed May 6, 2020
1 parent 01ef37c commit 8705ec2
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 70 deletions.
50 changes: 24 additions & 26 deletions src/screens/AssignmentScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -268,19 +268,18 @@ const AssignmentScreen: INavigationScreen = (props) => {
const assignment = JSON.parse(
data.assignment as string,
) as WithCourseInfo<IAssignment>;
if (!assignments.find((n) => n.id === assignment.id)) {
dispatch(
getAssignmentsForCourseAction.success({
assignments: [
assignment,
...assignments.filter(
(i) => i.courseId === assignment.courseId,
),
],
courseId: assignment.courseId,
}),
);
}
dispatch(
getAssignmentsForCourseAction.success({
assignments: [
assignment,
...assignments.filter(
(i) =>
i.courseId === assignment.courseId && i.id !== assignment.id,
),
],
courseId: assignment.courseId,
}),
);
}
});
return () => sub.remove();
Expand All @@ -295,19 +294,18 @@ const AssignmentScreen: INavigationScreen = (props) => {
const assignment = JSON.parse(
data.assignment as string,
) as WithCourseInfo<IAssignment>;
if (!assignments.find((n) => n.id === assignment.id)) {
dispatch(
getAssignmentsForCourseAction.success({
assignments: [
assignment,
...assignments.filter(
(i) => i.courseId === assignment.courseId,
),
],
courseId: assignment.courseId,
}),
);
}
dispatch(
getAssignmentsForCourseAction.success({
assignments: [
assignment,
...assignments.filter(
(i) =>
i.courseId === assignment.courseId && i.id !== assignment.id,
),
],
courseId: assignment.courseId,
}),
);
Navigation.mergeOptions(props.componentId, {
bottomTabs: {
currentTabIndex: 2,
Expand Down
44 changes: 22 additions & 22 deletions src/screens/FileScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -221,17 +221,17 @@ const FileScreen: INavigationScreen = (props) => {
e.request.content.data ?? (e.request.trigger as any).remoteMessage.data;
if (data?.file) {
const file = JSON.parse(data.file as string) as WithCourseInfo<IFile>;
if (!files.find((n) => n.id === file.id)) {
dispatch(
getFilesForCourseAction.success({
files: [
file,
...files.filter((i) => i.courseId === file.courseId),
],
courseId: file.courseId,
}),
);
}
dispatch(
getFilesForCourseAction.success({
files: [
file,
...files.filter(
(i) => i.courseId === file.courseId && i.id !== file.id,
),
],
courseId: file.courseId,
}),
);
}
});
return () => sub.remove();
Expand All @@ -244,17 +244,17 @@ const FileScreen: INavigationScreen = (props) => {
(e.notification.request.trigger as any).remoteMessage.data;
if (data?.file) {
const file = JSON.parse(data.file as string) as WithCourseInfo<IFile>;
if (!files.find((n) => n.id === file.id)) {
dispatch(
getFilesForCourseAction.success({
files: [
file,
...files.filter((i) => i.courseId === file.courseId),
],
courseId: file.courseId,
}),
);
}
dispatch(
getFilesForCourseAction.success({
files: [
file,
...files.filter(
(i) => i.courseId === file.courseId && i.id !== file.id,
),
],
courseId: file.courseId,
}),
);
Navigation.mergeOptions(props.componentId, {
bottomTabs: {
currentTabIndex: 1,
Expand Down
44 changes: 22 additions & 22 deletions src/screens/NoticeScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -346,17 +346,17 @@ const NoticeScreen: INavigationScreen = (props) => {
const notice = JSON.parse(data.notice as string) as WithCourseInfo<
INotice
>;
if (!notices.find((n) => n.id === notice.id)) {
dispatch(
getNoticesForCourseAction.success({
notices: [
notice,
...notices.filter((i) => i.courseId === notice.courseId),
],
courseId: notice.courseId,
}),
);
}
dispatch(
getNoticesForCourseAction.success({
notices: [
notice,
...notices.filter(
(i) => i.courseId === notice.courseId && i.id !== notice.id,
),
],
courseId: notice.courseId,
}),
);
}
});
return () => sub.remove();
Expand All @@ -371,17 +371,17 @@ const NoticeScreen: INavigationScreen = (props) => {
const notice = JSON.parse(data.notice as string) as WithCourseInfo<
INotice
>;
if (!notices.find((n) => n.id === notice.id)) {
dispatch(
getNoticesForCourseAction.success({
notices: [
notice,
...notices.filter((i) => i.courseId === notice.courseId),
],
courseId: notice.courseId,
}),
);
}
dispatch(
getNoticesForCourseAction.success({
notices: [
notice,
...notices.filter(
(i) => i.courseId === notice.courseId && i.id !== notice.id,
),
],
courseId: notice.courseId,
}),
);
Navigation.mergeOptions(props.componentId, {
bottomTabs: {
currentTabIndex: 0,
Expand Down

0 comments on commit 8705ec2

Please sign in to comment.