mirror of
https://github.com/bellingcat/ukraine-timemap.git
synced 2026-06-11 21:08:36 +03:00
allow loading multiple events
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
import { urlFromEnv } from '../common/utilities'
|
||||
|
||||
// TODO: relegate these URLs entirely to environment variables
|
||||
const CONFIG_URL = urlFromEnv('CONFIG_EXT')
|
||||
const EVENT_DATA_URL = urlFromEnv('EVENTS_EXT')
|
||||
const CATEGORY_URL = urlFromEnv('CATEGORIES_EXT')
|
||||
const FILTERS_URL = urlFromEnv('FILTERS_EXT')
|
||||
@@ -27,9 +28,20 @@ export function fetchDomain () {
|
||||
const features = getState().features
|
||||
dispatch(toggleFetchingDomain())
|
||||
|
||||
const eventPromise = fetch(EVENT_DATA_URL)
|
||||
.then(response => response.json())
|
||||
.catch(() => handleError('events'))
|
||||
let configPromise = Promise.resolve([])
|
||||
if (features.USE_REMOTE_CONFIG) {
|
||||
configPromise = fetch(CONFIG_URL)
|
||||
.then(response => response.json())
|
||||
.catch(() => handleError("Couldn't find data at the config URL you specified."))
|
||||
}
|
||||
|
||||
// NB: EVENT_DATA_URL is a list, and so results are aggregated
|
||||
const eventPromise = Promise.all(
|
||||
EVENT_DATA_URL.map(url => fetch(url)
|
||||
.then(response => response.json())
|
||||
.catch(() => handleError('events'))
|
||||
)
|
||||
).then(results => results.flatMap(t => t))
|
||||
|
||||
let catPromise = Promise.resolve([])
|
||||
if (features.USE_CATEGORIES) {
|
||||
|
||||
@@ -103,7 +103,9 @@ export function injectSource (id) {
|
||||
|
||||
export function urlFromEnv (ext) {
|
||||
if (process.env[ext]) {
|
||||
return `${process.env.SERVER_ROOT}${process.env[ext]}`
|
||||
if (!Array.isArray(process.env[ext])) { return [`${process.env.SERVER_ROOT}${process.env[ext]}`] } else {
|
||||
return process.env[ext].map(suffix => `${process.env.SERVER_ROOT}${suffix}`)
|
||||
}
|
||||
} else {
|
||||
return null
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user