From b35fb488600ba8bfd697407827a468fb5a5767ef Mon Sep 17 00:00:00 2001 From: efarooqui Date: Mon, 12 Oct 2020 11:15:34 -0700 Subject: [PATCH] Setting initial categories upon load; need to modify for timeline and related events --- src/actions/index.js | 9 +++++++++ src/components/Timeline.jsx | 2 +- src/reducers/app.js | 19 +++++++++++++++++++ 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/actions/index.js b/src/actions/index.js index 9137027..9d2b538 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -107,6 +107,7 @@ export function fetchDomain () { throw new Error('Some URLs returned negative. If you are in development, check the server is running') } dispatch(toggleFetchingDomain()) + dispatch(setInitialCategories(result.associations)) return result }) .catch(err => { @@ -212,6 +213,14 @@ export function setNotLoading () { } } +export const SET_INITIAL_CATEGORIES = 'SET_INITIAL_CATEGORIES' +export function setInitialCategories (values) { + return { + type: SET_INITIAL_CATEGORIES, + values + } +} + export const UPDATE_TIMERANGE = 'UPDATE_TIMERANGE' export function updateTimeRange (timerange) { return { diff --git a/src/components/Timeline.jsx b/src/components/Timeline.jsx index 93a2075..0c177b8 100644 --- a/src/components/Timeline.jsx +++ b/src/components/Timeline.jsx @@ -305,7 +305,7 @@ class Timeline extends React.Component { */ styleDatetime (timestamp, category) { return [null, null] - } + } render () { const { isNarrative, app } = this.props diff --git a/src/reducers/app.js b/src/reducers/app.js index 2e02c3a..3049e38 100644 --- a/src/reducers/app.js +++ b/src/reducers/app.js @@ -1,4 +1,5 @@ import initial from '../store/initial.js' +import { ASSOCIATION_MODES } from '../common/constants' import { toggleFlagAC } from '../common/utilities' import { @@ -22,6 +23,7 @@ import { FETCH_SOURCE_ERROR, SET_LOADING, SET_NOT_LOADING, + SET_INITIAL_CATEGORIES, UPDATE_SEARCH_QUERY } from '../actions' @@ -219,6 +221,21 @@ function setNotLoading (appState) { } } +function setInitialCategories (appState, action) { + const categories = action.values.reduce((acc, val) => { + if (val.mode === ASSOCIATION_MODES.CATEGORY) acc.push(val.id) + return acc + }, []) + + return { + ...appState, + associations: { + ...appState.associations, + categories: categories + } + } +} + function updateSearchQuery (appState, action) { return { ...appState, @@ -270,6 +287,8 @@ function app (appState = initial.app, action) { return setLoading(appState) case SET_NOT_LOADING: return setNotLoading(appState) + case SET_INITIAL_CATEGORIES: + return setInitialCategories(appState, action) case UPDATE_SEARCH_QUERY: return updateSearchQuery(appState, action) default: