Skip to content

Interactive interface for browsing global, full-resolution satellite imagery

some cleanup, remove unused code

Jason Kentbd453f1363d3
diff --git a/web/js/map/natural-events/request.js b/web/js/map/natural-events/request.js
deleted file mode 100644
index d2aea15dc..000000000
--- a/web/js/map/natural-events/request.js
+++ /dev/null
@@ -1,121 +0,0 @@
-/* eslint-disable import/extensions */
-import lodashOrderBy from 'lodash/orderBy';
-import lodashUniqBy from 'lodash/uniqBy';
-import util from '../../util/util';
-
-const { events } = util;
-
-export default function naturalEventsRequest(models, ui, config) {
- const self = {};
-
- self.apiURL = config.features.naturalEvents.host;
- self.querySuccessFlag = false;
- const model = models.naturalEvents;
- self.ignored = config.naturalEvents.skip || [];
- model.data = {};
-
- const init = function() {
- events.on('natural-events:query-results', onQueryResults);
- self.query();
- };
-
- const onQueryResults = function() {
- if (model.data.sources && model.data.types && model.data.events) {
- self.querySuccessFlag = true;
-
- // Remove types and events for ignored event categories
- const removeIgnoredItems = function(item) {
- if (item.categories) {
- const category = Array.isArray(item.categories)
- ? item.categories[0]
- : item.categories;
- // Add slug to categories
- category.slug = category.title
- .toLowerCase()
- .split(' ')
- .join('-');
- return !self.ignored.includes(category.title);
- }
- return !self.ignored.includes(item.title);
- };
- model.data.events = model.data.events.filter(removeIgnoredItems);
- model.data.types = model.data.types.filter(removeIgnoredItems);
-
- // Sort event geometries by descending date
- model.data.events = model.data.events.map((e) => {
- e.geometry = lodashOrderBy(e.geometry, 'date', 'desc');
- // Discard duplicate geometry dates
- e.geometry = lodashUniqBy(e.geometry, (g) => g.date.split('T')[0]);
- return e;
- });
-
- // Sort events by descending date
- model.data.events = lodashOrderBy(
- model.data.events,
- (e) => e.geometry[0].date,
- 'desc',
- );
- ui.sidebar.renderEvents();
- }
- };
-
- const queryEvents = async () => {
- let url = `${self.apiURL}/events`;
- if (config.parameters.mockEvents) {
- console.warn(`Using mock events data: ${config.parameters.mockEvents}`);
- url = `mock/events_data.json-${config.parameters.mockEvents}`;
- }
- const response = await fetch(url);
- const json = await response.json();
- if (!response.ok) {
- throw Error('Request for events failed.');
- }
- return json;
- };
-
- const queryTypes = async () => {
- let url = `${self.apiURL}/categories`;
- if (config.parameters.mockCategories) {
- console.warn(
- `Using mock categories data: ${config.parameters.mockEvents}`,
- );
- url = `mock/categories_data.json-${config.parameters.mockCategories}`;
- }
- const response = await fetch(url);
- const json = await response.json();
- if (!response.ok) {
- throw Error('Request for event types failed.');
- }
- return json;
- };
-
- const querySources = async () => {
- let url = `${self.apiURL}/sources`;
- if (config.parameters.mockSources) {
- console.warn(
- `Using mock sources data: ${config.parameters.mockEvents}`,
- );
- url = `mock/sources_data.json-${config.parameters.mockSources}`;
- }
- const response = await fetch(url);
- if (!response.ok) {
- throw Error('Request for event sources failed.');
- }
- const json = await response.json();
- return json;
- };
-
- self.query = function() {
- Promise.all([queryTypes(), queryEvents(), querySources()]).then((
- res,
- ) => {
- model.data.types = res[0].categories;
- model.data.events = res[1].events;
- model.data.sources = res[2].sources;
- events.trigger('natural-events:query-results');
- });
- };
-
- init();
- return self;
-}
diff --git a/web/js/map/natural-events/ui.js b/web/js/map/natural-events/ui.js
index 3ae7008da..bf98460cf 100644
--- a/web/js/map/natural-events/ui.js
+++ b/web/js/map/natural-events/ui.js
@@ -20,7 +20,9 @@ const zoomLevelReference = {
Volcanoes: 6,
};
-export default function naturalEventsUI(ui, config, store, models) {
+// ui.map = state.map.ui
+
+export default function naturalEventsUI(ui, config, store) {
const self = {};
let map;
let view;
@@ -44,7 +46,6 @@ export default function naturalEventsUI(ui, config, store, models) {
const {
requestedEvents,
requestedEventSources,
- requestedEventCategories,
} = state;
switch (action.type) {
case LOCATION_POP_ACTION: {
@@ -67,11 +68,9 @@ export default function naturalEventsUI(ui, config, store, models) {
return;
case EVENT_CONSTANTS.REQUEST_EVENTS_SUCCESS:
case EVENT_CONSTANTS.REQUEST_SOURCES_SUCCESS:
- case EVENT_CONSTANTS.REQUEST_CATEGORIES_SUCCESS:
if (!isLoading) return;
isLoading = requestedEvents.isLoading
- || requestedEventSources.isLoading
- || requestedEventCategories.isLoading;
+ || requestedEventSources.isLoading;
if (!isLoading) {
self.eventsData = requestedEvents.response;
}
diff --git a/web/js/modules/combine-reducers.js b/web/js/modules/combine-reducers.js
index c9139f474..0ec06fd12 100644
--- a/web/js/modules/combine-reducers.js
+++ b/web/js/modules/combine-reducers.js
@@ -9,7 +9,6 @@ import { shortLink } from './link/reducers';
import {
requestedEvents,
requestedEventSources,
- requestedEventCategories,
eventsReducer,
eventRequestResponse,
} from './natural-events/reducers';
@@ -86,7 +85,6 @@ export function getInitialState(models, config, parameters) {
layers: getLayersInitialState(config),
requestedEvents: eventRequestResponse(eventsIgnoreArray),
requestedEventSources: eventRequestResponse(eventsIgnoreArray),
- requestedEventCategories: eventRequestResponse(eventsIgnoreArray),
palettes: getInitialPaletteState(config),
productPicker: getProductPickerInitialState(config),
vectorStyles: getInitialVectorStyleState(config),
@@ -123,7 +121,6 @@ const reducers = {
imageDownload: imageDownloadReducer,
requestedEvents,
requestedEventSources,
- requestedEventCategories,
modalAboutPage,
shortLink,
notificationsRequest,
diff --git a/web/js/modules/core/reducers.js b/web/js/modules/core/reducers.js
index 9828888d7..13d3e4cba 100644
--- a/web/js/modules/core/reducers.js
+++ b/web/js/modules/core/reducers.js
@@ -9,7 +9,7 @@ export const defaultRequestState = {
export function requestResponse(props = {}) {
return lodashAssign({}, defaultRequestState, props);
}
-export function requestReducer(actionName, state, action, callback) {
+export function requestReducer(actionName, state, action) {
const START = `${actionName}_START`;
const SUCCESS = `${actionName}_SUCCESS`;
const FAILURE = `${actionName}_FAILURE`;
diff --git a/web/js/modules/natural-events/actions.js b/web/js/modules/natural-events/actions.js
index 8ae929f00..769fecb6b 100644
--- a/web/js/modules/natural-events/actions.js
+++ b/web/js/modules/natural-events/actions.js
@@ -1,7 +1,6 @@
import {
REQUEST_EVENTS,
REQUEST_SOURCES,
- REQUEST_CATEGORIES,
SELECT_EVENT,
DESELECT_EVENT,
SHOW_ALL_EVENTS,
@@ -20,14 +19,7 @@ export function requestEvents(location) {
'application/json',
);
}
-export function requestCategories(location) {
- return (dispatch) => requestAction(
- dispatch,
- REQUEST_CATEGORIES,
- location,
- 'application/json',
- );
-}
+
export function requestSources(location) {
return (dispatch) => requestAction(
dispatch,
diff --git a/web/js/modules/natural-events/constants.js b/web/js/modules/natural-events/constants.js
index 9d36f7996..dfa3072ed 100644
--- a/web/js/modules/natural-events/constants.js
+++ b/web/js/modules/natural-events/constants.js
@@ -8,11 +8,6 @@ export const REQUEST_SOURCES_START = 'EVENTS/REQUEST_SOURCES_START';
export const REQUEST_SOURCES_FAILURE = 'EVENTS/REQUEST_SOURCES_FAILURE';
export const REQUEST_SOURCES_SUCCESS = 'EVENTS/REQUEST_SOURCES_SUCCESS';
-export const REQUEST_CATEGORIES = 'EVENTS/REQUEST_CATEGORIES';
-export const REQUEST_CATEGORIES_START = 'EVENTS/REQUEST_CATEGORIES_START';
-export const REQUEST_CATEGORIES_FAILURE = 'EVENTS/REQUEST_CATEGORIES_FAILURE';
-export const REQUEST_CATEGORIES_SUCCESS = 'EVENTS/REQUEST_CATEGORIES_SUCCESS';
-
export const DESELECT_EVENT = 'EVENTS/DESELECT_EVENT';
export const SELECT_EVENT = 'EVENTS/SELECT_EVENT';
export const SHOW_ALL_EVENTS = 'EVENTS/SHOW_ALL_EVENTS';
diff --git a/web/js/modules/natural-events/reducers.js b/web/js/modules/natural-events/reducers.js
index 777f34fa2..920c266c2 100644
--- a/web/js/modules/natural-events/reducers.js
+++ b/web/js/modules/natural-events/reducers.js
@@ -7,7 +7,6 @@ import {
ALL_CATEGORY,
REQUEST_EVENTS,
REQUEST_SOURCES,
- REQUEST_CATEGORIES,
SELECT_EVENT,
DESELECT_EVENT,
SELECT_CATEGORY,
@@ -142,11 +141,7 @@ export function eventsRequestReducer(actionName, state, action) {
response: null,
});
case SUCCESS: {
- const key = actionName === REQUEST_EVENTS
- ? 'events'
- : actionName === REQUEST_CATEGORIES
- ? 'categories'
- : 'sources';
+ const key = actionName === REQUEST_EVENTS ? 'events' : 'sources';
const filtered = action.response[key].filter((item) => formatResponse(item, state.ignore));
return eventRequestResponse({
response: actionName === REQUEST_EVENTS
@@ -170,10 +165,6 @@ export function requestedEvents(state = {}, action) {
return eventsRequestReducer(REQUEST_EVENTS, state, action);
}
-export function requestedEventCategories(state = {}, action) {
- return eventsRequestReducer(REQUEST_CATEGORIES, state, action);
-}
-
export function requestedEventSources(state = {}, action) {
return eventsRequestReducer(REQUEST_SOURCES, state, action);
}