mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-08 03:18:36 +03:00
basic source schema reading data in
This commit is contained in:
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
17
src/reducers/schema/sourceSchema.js
Normal file
17
src/reducers/schema/sourceSchema.js
Normal 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;
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
Reference in New Issue
Block a user