Filter out coming soon from challenge blocks
This commit is contained in:
@ -104,6 +104,16 @@ function shouldShowNew(element, block) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// meant to be used with a filter method
|
||||||
|
// on an array or observable stream
|
||||||
|
// true if challenge should be passed through
|
||||||
|
// false if should filter challenge out of array or stream
|
||||||
|
function shouldNotFilterComingSoon({ isComingSoon, isBeta: challengeIsBeta }) {
|
||||||
|
return isDev ||
|
||||||
|
!isComingSoon ||
|
||||||
|
(isBeta && challengeIsBeta);
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = function(app) {
|
module.exports = function(app) {
|
||||||
const router = app.loopback.Router();
|
const router = app.loopback.Router();
|
||||||
|
|
||||||
@ -135,6 +145,7 @@ module.exports = function(app) {
|
|||||||
// create a stream of challenge blocks
|
// create a stream of challenge blocks
|
||||||
const blocks$ = challenge$
|
const blocks$ = challenge$
|
||||||
.map(challenge => challenge.toJSON())
|
.map(challenge => challenge.toJSON())
|
||||||
|
.filter(shouldNotFilterComingSoon)
|
||||||
// group challenges by block | returns a stream of observables
|
// group challenges by block | returns a stream of observables
|
||||||
.groupBy(challenge => challenge.block)
|
.groupBy(challenge => challenge.block)
|
||||||
// turn block group stream into an array
|
// turn block group stream into an array
|
||||||
@ -186,13 +197,9 @@ module.exports = function(app) {
|
|||||||
|
|
||||||
// find challenge
|
// find challenge
|
||||||
return challenge$
|
return challenge$
|
||||||
// filter out challenges coming soon
|
|
||||||
.filter(challenge => {
|
|
||||||
return isDev ||
|
|
||||||
!challenge.isComingSoon ||
|
|
||||||
(isBeta && challenge.isBeta);
|
|
||||||
})
|
|
||||||
.map(challenge => challenge.toJSON())
|
.map(challenge => challenge.toJSON())
|
||||||
|
// filter out challenges coming soon
|
||||||
|
.filter(shouldNotFilterComingSoon)
|
||||||
// filter out hikes
|
// filter out hikes
|
||||||
.filter(({ superBlock }) => !(/hikes/gi).test(superBlock))
|
.filter(({ superBlock }) => !(/hikes/gi).test(superBlock))
|
||||||
.filter(({ id }) => id === challengeId)
|
.filter(({ id }) => id === challengeId)
|
||||||
@ -216,6 +223,7 @@ module.exports = function(app) {
|
|||||||
.map(({ challenges = [] }) => challenges[0]);
|
.map(({ challenges = [] }) => challenges[0]);
|
||||||
|
|
||||||
return blocks$
|
return blocks$
|
||||||
|
.filter(shouldNotFilterComingSoon)
|
||||||
.elementAt(blockIndex)
|
.elementAt(blockIndex)
|
||||||
.flatMap(block => {
|
.flatMap(block => {
|
||||||
// find where our challenge lies in the block
|
// find where our challenge lies in the block
|
||||||
@ -284,11 +292,7 @@ module.exports = function(app) {
|
|||||||
challenge$
|
challenge$
|
||||||
.filter((challenge) => {
|
.filter((challenge) => {
|
||||||
return testChallengeName.test(challenge.name) &&
|
return testChallengeName.test(challenge.name) &&
|
||||||
(
|
shouldNotFilterComingSoon(challenge);
|
||||||
isDev ||
|
|
||||||
!challenge.isComingSoon ||
|
|
||||||
(isBeta && challenge.isBeta)
|
|
||||||
);
|
|
||||||
})
|
})
|
||||||
.last({ defaultValue: null })
|
.last({ defaultValue: null })
|
||||||
.flatMap(challenge => {
|
.flatMap(challenge => {
|
||||||
|
Reference in New Issue
Block a user