Skip to content

Instantly share code, notes, and snippets.

@jsmanifest
Created July 3, 2019 16:06
Show Gist options
  • Save jsmanifest/608adcc1e1437e4d695282c7158079a6 to your computer and use it in GitHub Desktop.
Save jsmanifest/608adcc1e1437e4d695282c7158079a6 to your computer and use it in GitHub Desktop.
import { createSelector } from 'reselect'
// supports passing in the whole obj or just the string to correct the video type
const fixVideoTypeNaming = (videoType) => {
let video = videoType
// If video is a video object
if (video && typeof video === 'object') {
const media = { ...video }
video = media.videoType
}
// If video is the actual videoType string
if (typeof video === 'string') {
// fix the typo because brian is an idiot
if (video === 'mp3') {
video = 'mp4'
}
}
return video
}
/* -------------------------------------------------------
---- Pre-selectors
-------------------------------------------------------- */
export const getOverallSelector = (state) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.total
.overall
export const getSpecificWeekSelector = (state, props) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.weekly[
props.date
]
/* -------------------------------------------------------
---- Selectors
-------------------------------------------------------- */
export const getWeeklyCycleSelector = createSelector(
getSpecificWeekSelector,
(weekCycle) => weekCycle || null,
)
export const getFetchingTotalStatusSelector = createSelector(
(state) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.total
.fetching,
(fetching) => fetching,
)
export const getFetchErrorSelector = createSelector(
(state) =>
state.app[fixVideoTypeNaming(state.app.media.video.videoType)].options.total
.fetchError,
(fetchError) => fetchError,
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment