From 4423e792ec47bdb948b4bc4214a78929cc8ee67a Mon Sep 17 00:00:00 2001 From: Franc Camps-Febrer Date: Fri, 14 Dec 2018 17:00:31 +0100 Subject: [PATCH] Make selectors compute narratives as arrays --- src/components/NarrativeCard.js | 1 - src/reducers/schema/eventSchema.js | 2 +- src/selectors/index.js | 19 +++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/components/NarrativeCard.js b/src/components/NarrativeCard.js index 2d16550..3a41abb 100644 --- a/src/components/NarrativeCard.js +++ b/src/components/NarrativeCard.js @@ -26,7 +26,6 @@ class NarrativeCard extends React.Component { componentDidUpdate() { if (this.props.narrative !== null) { const step = this.props.narrative.steps[this.state.step]; - console.log(step) this.props.onSelect([step]); } } diff --git a/src/reducers/schema/eventSchema.js b/src/reducers/schema/eventSchema.js index b497841..614eba2 100644 --- a/src/reducers/schema/eventSchema.js +++ b/src/reducers/schema/eventSchema.js @@ -11,7 +11,7 @@ const eventSchema = Joi.object().keys({ longitude: Joi.string().allow('').required(), type: Joi.string().allow(''), category: Joi.string().required(), - narrative: Joi.string().allow(''), + narratives: Joi.array(), sources: Joi.array(), tags: Joi.string().allow(''), comments: Joi.string().allow(''), diff --git a/src/selectors/index.js b/src/selectors/index.js index 32a4e49..30d65a9 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -95,16 +95,18 @@ export const selectNarratives = createSelector( events.forEach((evt) => { const isTagged = isTaggedIn(evt, tagFilters) || isNoTags(tagFilters); const isTimeRanged = isTimeRangedIn(evt, timeRange); - const isInNarrative = evt.narrative; + const isInNarrative = evt.narratives.length > 0; - if (!narratives[evt.narrative]) { - narratives[evt.narrative] = { id: evt.narrative, steps: [], byId: {} }; - } + evt.narratives.map(narrative => { + if (!narratives[narrative]) { + narratives[narrative] = { id: narrative, steps: [], byId: {} }; + } - if (/*isTimeRanged && isTagged && */isInNarrative) { - narratives[evt.narrative].steps.push(evt); - narratives[evt.narrative].byId[evt.id] = { next: null, prev: null }; - } + if (isInNarrative) { + narratives[narrative].steps.push(evt); + narratives[narrative].byId[evt.id] = { next: null, prev: null }; + } + }) }); Object.keys(narratives).forEach((key) => { @@ -161,6 +163,7 @@ export const selectLocations = createSelector( export const selectSelected = createSelector( [getSelected, getSources], (selected, sources) => { + console.log(selected, sources) if (selected.length === 0) { return [] }