diff --git a/src/actions/index.js b/src/actions/index.js index ce48225..1264aa2 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -81,8 +81,21 @@ export function fetchDomain () { .catch(handleError('tags')) } - return Promise.all([eventPromise, catPromise, narPromise, - sitesPromise, tagsPromise]) + let sourcesPromise = Promise.resolve([]) + if (process.env.features.USE_SOURCES) { + sourcesPromise = fetch(SOURCES_URL) + .then(response => response.json()) + .catch(handleError('sources')) + } + + return Promise.all([ + eventPromise, + catPromise, + narPromise, + sitesPromise, + tagsPromise, + sourcesPromise + ]) .then(response => { dispatch(toggleFetchingDomain()) const result = { @@ -91,6 +104,7 @@ export function fetchDomain () { narratives: response[2], sites: response[3], tags: response[4], + sources: response[5], notifications } return result @@ -114,14 +128,7 @@ export const UPDATE_DOMAIN = 'UPDATE_DOMAIN' export function updateDomain(domain) { return { type: UPDATE_DOMAIN, - domain: { - events: domain.events, - categories: domain.categories, - tags: domain.tags, - sites: domain.sites, - narratives: domain.narratives, - notifications: domain.notifications - } + domain } } diff --git a/src/components/Dashboard.jsx b/src/components/Dashboard.jsx index ef5e0d5..479be0a 100644 --- a/src/components/Dashboard.jsx +++ b/src/components/Dashboard.jsx @@ -32,7 +32,7 @@ class Dashboard extends React.Component { componentDidMount() { if (!this.props.app.isMobile) { this.props.actions.fetchDomain() - .then((domain) => this.props.actions.updateDomain(domain)); + .then(domain => this.props.actions.updateDomain(domain)); } } diff --git a/src/reducers/schema/sourceSchema.js b/src/reducers/schema/sourceSchema.js new file mode 100644 index 0000000..81c99f5 --- /dev/null +++ b/src/reducers/schema/sourceSchema.js @@ -0,0 +1,17 @@ +import Joi from 'joi'; + +const sourceSchema = Joi.object().keys({ + id: Joi.string().required(), + path: Joi.string().required(), + type: Joi.string().allow(''), + affil_1: Joi.string().allow(''), + affil_2: Joi.string().allow(''), + url: Joi.string().allow(''), + title: Joi.string().allow(''), + parent: Joi.string(), + author: Joi.string().allow(''), + date: Joi.string(), + notes: Joi.string().allow('') +}); + +export default sourceSchema; diff --git a/src/reducers/utils/validators.js b/src/reducers/utils/validators.js index ecc8f87..9831962 100644 --- a/src/reducers/utils/validators.js +++ b/src/reducers/utils/validators.js @@ -1,9 +1,10 @@ import Joi from 'joi'; -import eventSchema from '../schema/eventSchema.js'; -import categorySchema from '../schema/categorySchema.js'; -import siteSchema from '../schema/siteSchema.js'; -import narrativeSchema from '../schema/narrativeSchema.js'; +import eventSchema from '../schema/eventSchema'; +import categorySchema from '../schema/categorySchema'; +import siteSchema from '../schema/siteSchema'; +import narrativeSchema from '../schema/narrativeSchema'; +import sourceSchema from '../schema/sourceSchema' import { capitalize } from './helpers.js'; @@ -59,6 +60,7 @@ export function validateDomain (domain) { categories: [], sites: [], narratives: [], + sources: [], notifications: domain.notifications, tags: {} } @@ -68,6 +70,7 @@ export function validateDomain (domain) { categories: [], sites: [], narratives: [], + sources: [], } function validateItem(item, domainClass, schema) { @@ -95,6 +98,9 @@ export function validateDomain (domain) { domain.narratives.forEach(narrative => { validateItem(narrative, 'narratives', narrativeSchema); }); + domain.sources.forEach(source => { + validateItem(source, 'sources', sourceSchema); + }) // Message the number of failed items in domain diff --git a/webpack.config.js b/webpack.config.js index 4706f03..768e021 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -64,7 +64,8 @@ const config = { 'features': { 'USE_TAGS': JSON.stringify(userConfig.features.USE_TAGS), 'USE_SEARCH': JSON.stringify(userConfig.features.USE_SEARCH), - 'USE_SITES': JSON.stringify(userConfig.features.USE_SITES) + 'USE_SITES': JSON.stringify(userConfig.features.USE_SITES), + 'USE_SOURCES': JSON.stringify(userConfig.features.USE_SOURCES) } } }),