basic source schema reading data in

This commit is contained in:
Lachlan Kermode
2018-12-12 17:00:22 +00:00
parent 0c54e07f8f
commit fb84d6883b
5 changed files with 47 additions and 16 deletions

View File

@@ -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
}
}

View File

@@ -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));
}
}

View File

@@ -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;

View File

@@ -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

View File

@@ -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)
}
}
}),