Add exhaustive switch checks
This commit is contained in:
parent
e16df483f3
commit
b6ad3baa31
|
@ -10,6 +10,7 @@ import MediaSidebar from '../../components/sidebar/MediaSidebar'
|
|||
import { useTranslation } from 'react-i18next'
|
||||
import { SharePageToken_shareToken_media } from './__generated__/SharePageToken'
|
||||
import { MediaType } from '../../../__generated__/globalTypes'
|
||||
import { exhaustiveCheck } from '../../helpers/utils'
|
||||
|
||||
const DisplayPhoto = styled(ProtectedImage)`
|
||||
width: 100%;
|
||||
|
@ -39,6 +40,8 @@ const MediaView = ({ media }: MediaViewProps) => {
|
|||
case MediaType.Video:
|
||||
return <DisplayVideo media={media} />
|
||||
}
|
||||
|
||||
exhaustiveCheck(media.type)
|
||||
}
|
||||
|
||||
type MediaSharePageType = {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import React from 'react'
|
||||
import styled from 'styled-components'
|
||||
import { MediaType } from '../../../../__generated__/globalTypes'
|
||||
import { exhaustiveCheck } from '../../../helpers/utils'
|
||||
import {
|
||||
ProtectedImage,
|
||||
ProtectedVideo,
|
||||
|
@ -62,6 +63,8 @@ const PresentMedia = ({
|
|||
case MediaType.Video:
|
||||
return <StyledVideo media={media} />
|
||||
}
|
||||
|
||||
exhaustiveCheck(media.type)
|
||||
}
|
||||
|
||||
export default PresentMedia
|
||||
|
|
|
@ -37,3 +37,7 @@ export function debounce<T extends (...args: any[]) => any>(
|
|||
export function isNil(value: any): value is undefined | null {
|
||||
return value === undefined || value === null
|
||||
}
|
||||
|
||||
export function exhaustiveCheck(value: never) {
|
||||
throw new Error(`Exhaustive check failed with value: ${value}`)
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import i18n from 'i18next'
|
|||
import { initReactI18next, TFunction } from 'react-i18next'
|
||||
import { LanguageTranslation } from '../__generated__/globalTypes'
|
||||
import { authToken } from './helpers/authentication'
|
||||
import { exhaustiveCheck } from './helpers/utils'
|
||||
|
||||
export type TranslationFn = TFunction<'translation'>
|
||||
|
||||
|
@ -56,25 +57,27 @@ export const loadTranslations = () => {
|
|||
return
|
||||
}
|
||||
|
||||
switch (data?.myUserPreferences.language) {
|
||||
switch (language) {
|
||||
case LanguageTranslation.Danish:
|
||||
import('../extractedTranslations/da/translation.json').then(danish => {
|
||||
i18n.addResourceBundle('da', 'translation', danish)
|
||||
i18n.changeLanguage('da')
|
||||
})
|
||||
break
|
||||
return
|
||||
case LanguageTranslation.English:
|
||||
import('../extractedTranslations/en/translation.json').then(english => {
|
||||
i18n.addResourceBundle('en', 'translation', english)
|
||||
i18n.changeLanguage('en')
|
||||
})
|
||||
break
|
||||
return
|
||||
case LanguageTranslation.French:
|
||||
import('../extractedTranslations/fr/translation.json').then(english => {
|
||||
i18n.addResourceBundle('fr', 'translation', english)
|
||||
i18n.changeLanguage('fr')
|
||||
})
|
||||
break
|
||||
return
|
||||
}
|
||||
|
||||
exhaustiveCheck(language)
|
||||
}, [data?.myUserPreferences.language])
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue