Use missingCaseError in groupMediaItemsByDate

This commit is contained in:
Evan Hahn 2021-09-02 12:43:56 -05:00 committed by GitHub
parent 808ade2a8c
commit 8e0b94e720
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -4,10 +4,11 @@
import moment from 'moment'; import moment from 'moment';
import { compact, groupBy, sortBy } from 'lodash'; import { compact, groupBy, sortBy } from 'lodash';
import * as log from '../../../logging/log';
import { MediaItemType } from '../../../types/MediaItem'; import { MediaItemType } from '../../../types/MediaItem';
import { getMessageTimestamp } from '../../../util/getMessageTimestamp'; import { getMessageTimestamp } from '../../../util/getMessageTimestamp';
// import { missingCaseError } from '../../../util/missingCaseError'; import { missingCaseError } from '../../../util/missingCaseError';
type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth'; type StaticSectionType = 'today' | 'yesterday' | 'thisWeek' | 'thisMonth';
type YearMonthSectionType = 'yearMonth'; type YearMonthSectionType = 'yearMonth';
@ -54,13 +55,13 @@ const toSection = (
messagesWithSection: Array<MediaItemWithSection> | undefined messagesWithSection: Array<MediaItemWithSection> | undefined
): Section | undefined => { ): Section | undefined => {
if (!messagesWithSection || messagesWithSection.length === 0) { if (!messagesWithSection || messagesWithSection.length === 0) {
return; return undefined;
} }
const firstMediaItemWithSection: MediaItemWithSection = const firstMediaItemWithSection: undefined | MediaItemWithSection =
messagesWithSection[0]; messagesWithSection[0];
if (!firstMediaItemWithSection) { if (!firstMediaItemWithSection) {
return; return undefined;
} }
const mediaItems = messagesWithSection.map( const mediaItems = messagesWithSection.map(
@ -71,13 +72,11 @@ const toSection = (
case 'yesterday': case 'yesterday':
case 'thisWeek': case 'thisWeek':
case 'thisMonth': case 'thisMonth':
// eslint-disable-next-line consistent-return
return { return {
type: firstMediaItemWithSection.type, type: firstMediaItemWithSection.type,
mediaItems, mediaItems,
}; };
case 'yearMonth': case 'yearMonth':
// eslint-disable-next-line consistent-return
return { return {
type: firstMediaItemWithSection.type, type: firstMediaItemWithSection.type,
year: firstMediaItemWithSection.year, year: firstMediaItemWithSection.year,
@ -85,12 +84,8 @@ const toSection = (
mediaItems, mediaItems,
}; };
default: default:
// NOTE: Investigate why we get the following error: log.error(missingCaseError(firstMediaItemWithSection));
// error TS2345: Argument of type 'any' is not assignable to parameter return undefined;
// of type 'never'.
// return missingCaseError(firstMediaItemWithSection.type);
// eslint-disable-next-line no-useless-return
return;
} }
}; };