diff --git a/src/components/Card.jsx b/src/components/Card.jsx index d53bc31..00f06e5 100644 --- a/src/components/Card.jsx +++ b/src/components/Card.jsx @@ -1,5 +1,5 @@ import copy from '../js/data/copy.json'; -import {isNotNullNorUndefined} from '../js/data/utilities'; +import {isNotNullNorUndefined} from '../js/utilities'; import React from 'react'; import Spinner from './presentational/Spinner'; diff --git a/src/components/CardStack.jsx b/src/components/CardStack.jsx index f5bc36e..99492ed 100644 --- a/src/components/CardStack.jsx +++ b/src/components/CardStack.jsx @@ -6,7 +6,7 @@ import Card from './Card.jsx'; import copy from '../js/data/copy.json'; import { isNotNullNorUndefined -} from '../js/data/utilities.js'; +} from '../js/utilities.js'; class CardStack extends React.Component { diff --git a/src/components/NarrativeCard.js b/src/components/NarrativeCard.js index b017226..bdc9862 100644 --- a/src/components/NarrativeCard.js +++ b/src/components/NarrativeCard.js @@ -64,7 +64,6 @@ class NarrativeCard extends React.Component { } function mapStateToProps(state) { - console.log(state) return { narrative: state.app.narrative } diff --git a/src/components/Viewport.jsx b/src/components/Viewport.jsx index 363a652..3bcc808 100644 --- a/src/components/Viewport.jsx +++ b/src/components/Viewport.jsx @@ -2,7 +2,7 @@ import React from 'react' import { connect } from 'react-redux' import * as selectors from '../selectors' import Map from '../js/map/map.js' -import { areEqual } from '../js/data/utilities.js' +import { areEqual } from '../js/utilities.js' class Viewport extends React.Component { constructor(props) { diff --git a/src/components/presentational/CardLocation.js b/src/components/presentational/CardLocation.js index 7dd26c0..a798a5e 100644 --- a/src/components/presentational/CardLocation.js +++ b/src/components/presentational/CardLocation.js @@ -1,7 +1,7 @@ import React from 'react'; import copy from '../../js/data/copy.json'; -import {isNotNullNorUndefined} from '../../js/data/utilities'; +import { isNotNullNorUndefined } from '../../js/utilities'; const CardLocation = ({ language, location }) => { diff --git a/src/components/presentational/CardTimestamp.js b/src/components/presentational/CardTimestamp.js index d645e82..4c4d594 100644 --- a/src/components/presentational/CardTimestamp.js +++ b/src/components/presentational/CardTimestamp.js @@ -1,7 +1,7 @@ import React from 'react'; import copy from '../../js/data/copy.json'; -import {isNotNullNorUndefined} from '../../js/data/utilities'; +import { isNotNullNorUndefined } from '../../js/utilities'; const CardTimestamp = ({ makeTimelabel, language, timestamp }) => { diff --git a/src/js/map/map.js b/src/js/map/map.js index f9b3c96..3e30e93 100644 --- a/src/js/map/map.js +++ b/src/js/map/map.js @@ -1,7 +1,7 @@ import { areEqual, isNotNullNorUndefined -} from '../data/utilities'; +} from '../utilities'; import hash from 'object-hash'; import 'leaflet-polylinedecorator'; @@ -363,16 +363,19 @@ Stop and start the development process in terminal after you have added your tok .attr('class', 'narrative') .attr('d', sequenceLine) .style('stroke-width', d => { + if (!d[0]) return 0; // Note: [0] is a non-elegant way to get the narrative id out of the first // event in the narrative sequence const styleProps = getNarrativeStyle(d[0].narrative); return styleProps.strokeWidth; }) .style('stroke-dasharray', d => { + if (!d[0]) return 'none'; const styleProps = getNarrativeStyle(d[0].narrative); return (styleProps.style === 'dotted') ? "2px 5px" : 'none'; }) .style('stroke', d => { + if (!d[0]) return 'none'; const styleProps = getNarrativeStyle(d[0].narrative); return styleProps.stroke; }) diff --git a/src/js/timeline/timeline.js b/src/js/timeline/timeline.js index d8fb792..e189f3e 100644 --- a/src/js/timeline/timeline.js +++ b/src/js/timeline/timeline.js @@ -6,7 +6,7 @@ */ import { areEqual -} from '../data/utilities'; +} from '../utilities'; import esLocale from '../data/es-MX.json'; import copy from '../data/copy.json'; diff --git a/src/js/data/utilities.js b/src/js/utilities.js similarity index 76% rename from src/js/data/utilities.js rename to src/js/utilities.js index da8462d..49c701c 100644 --- a/src/js/data/utilities.js +++ b/src/js/utilities.js @@ -35,3 +35,17 @@ export function areEqual(arr1, arr2) { export function isNotNullNorUndefined(variable) { return (typeof variable !== 'undefined' && variable !== null); } + +/** +* Return a Date object given a datetime string of the format: "2016-09-10T07:00:00" +* @param {string} datetime +*/ +export function parseDate(datetime) { + return new Date(datetime.slice(0, 4), + datetime.slice(5, 7) - 1, + datetime.slice(8, 10), + datetime.slice(11, 13), + datetime.slice(14, 16), + datetime.slice(17, 19) + ); +} diff --git a/src/reducers/app.js b/src/reducers/app.js index 0b17716..16784a3 100644 --- a/src/reducers/app.js +++ b/src/reducers/app.js @@ -1,5 +1,7 @@ import initial from '../store/initial.js'; +import { parseDate } from '../js/utilities.js'; + import { UPDATE_HIGHLIGHTED, UPDATE_SELECTED, @@ -26,9 +28,25 @@ function updateSelected(appState, action) { } function updateNarrative(appState, action) { - return Object.assign({}, appState, { - narrative: action.narrative - }); + if (action.narrative === null) { + return Object.assign({}, appState, { + narrative: action.narrative, + }); + } else { + const dates = action.narrative.steps.map(n => parseDate(n.timestamp).getTime()) + let minDate = Math.min(...dates); + let maxDate = Math.max(...dates); + // Add some margin to the datetime extent + minDate = minDate - ((maxDate - minDate) / 20); + maxDate = maxDate + ((maxDate - minDate) / 20); + + return Object.assign({}, appState, { + narrative: action.narrative, + filters: Object.assign({}, appState.filters, { + timerange: [new Date(minDate), new Date(maxDate)] + }), + }); + } } function updateTagFilters(appState, action) { diff --git a/src/selectors/index.js b/src/selectors/index.js index 44809cc..c994e2a 100644 --- a/src/selectors/index.js +++ b/src/selectors/index.js @@ -94,10 +94,11 @@ export const selectNarratives = createSelector( const isTimeRanged = isTimeRangedIn(evt, timeRange); const isInNarrative = evt.narrative; - if (isTimeRanged && isTagged && isInNarrative) { - if (!narratives[evt.narrative]) { - narratives[evt.narrative] = { id: evt.narrative, steps: [], byId: {} }; - } + if (!narratives[evt.narrative]) { + narratives[evt.narrative] = { id: evt.narrative, steps: [], byId: {} }; + } + + if (/*isTimeRanged && isTagged && */isInNarrative) { narratives[evt.narrative].steps.push(evt); narratives[evt.narrative].byId[evt.id] = { next: null, prev: null }; } @@ -117,6 +118,7 @@ export const selectNarratives = createSelector( narratives[key] = Object.assign(narrativeMetadata.find(n => n.id === key), narratives[key]); }); + console.log(narrativeMetadata, narratives) return Object.values(narratives); }); diff --git a/webpack.config.js b/webpack.config.js index ba1c538..4706f03 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,7 +1,7 @@ const webpack = require('webpack'); const MiniCssExtractPlugin = require('mini-css-extract-plugin'); const HtmlWebpackPlugin = require('html-webpack-plugin'); -const userConfig = require('./dev.config'); +const userConfig = require('./config'); const userConfigJSON = {}; const devMode = process.env.NODE_ENV !== 'production';