Skip to content

Commit

Permalink
Use missingCaseError in groupMediaItemsByDate
Browse files Browse the repository at this point in the history
  • Loading branch information
EvanHahn-Signal committed Sep 2, 2021
1 parent 808ade2 commit 8e0b94e
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions ts/components/conversation/media-gallery/groupMediaItemsByDate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
import moment from 'moment';
import { compact, groupBy, sortBy } from 'lodash';

import * as log from '../../../logging/log';
import { MediaItemType } from '../../../types/MediaItem';
import { getMessageTimestamp } from '../../../util/getMessageTimestamp';

// import { missingCaseError } from '../../../util/missingCaseError';
import { missingCaseError } from '../../../util/missingCaseError';

type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth';
type YearMonthSectionType = 'yearMonth';
Expand Down Expand Up @@ -54,13 +55,13 @@ const toSection = (
messagesWithSection: Array<MediaItemWithSection> | undefined
): Section | undefined => {
if (!messagesWithSection || messagesWithSection.length === 0) {
return;
return undefined;
}

const firstMediaItemWithSection: MediaItemWithSection =
const firstMediaItemWithSection: undefined | MediaItemWithSection =
messagesWithSection[0];
if (!firstMediaItemWithSection) {
return;
return undefined;
}

const mediaItems = messagesWithSection.map(
Expand All @@ -71,26 +72,20 @@ const toSection = (
case 'yesterday':
case 'thisWeek':
case 'thisMonth':
// eslint-disable-next-line consistent-return
return {
type: firstMediaItemWithSection.type,
mediaItems,
};
case 'yearMonth':
// eslint-disable-next-line consistent-return
return {
type: firstMediaItemWithSection.type,
year: firstMediaItemWithSection.year,
month: firstMediaItemWithSection.month,
mediaItems,
};
default:
// NOTE: Investigate why we get the following error:
// error TS2345: Argument of type 'any' is not assignable to parameter
// of type 'never'.
// return missingCaseError(firstMediaItemWithSection.type);
// eslint-disable-next-line no-useless-return
return;
log.error(missingCaseError(firstMediaItemWithSection));
return undefined;
}
};

Expand Down

0 comments on commit 8e0b94e

Please sign in to comment.