From c473e4a998a7097b2c931c1ebe66b0780a67d06c Mon Sep 17 00:00:00 2001 From: Lachlan Kermode Date: Mon, 8 Jun 2020 16:17:12 +0200 Subject: [PATCH] make USE_CATEGORIES optional --- src/actions/index.js | 9 ++++++--- src/components/Card.jsx | 4 ++-- src/components/CardStack.jsx | 4 +++- src/components/Layout.js | 7 +++++-- src/components/Timeline.jsx | 11 ++++++++--- src/components/TimelineCategories.jsx | 5 ++++- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/actions/index.js b/src/actions/index.js index 5bcdd85..505ec28 100644 --- a/src/actions/index.js +++ b/src/actions/index.js @@ -31,9 +31,12 @@ export function fetchDomain () { .then(response => response.json()) .catch(() => handleError('events')) - const catPromise = fetch(CATEGORY_URL) - .then(response => response.json()) - .catch(() => handleError(domainMsg('categories'))) + let catPromise = Promise.resolve([]) + if (features.USE_CATEGORIES) { + catPromise = fetch(CATEGORY_URL) + .then(response => response.json()) + .catch(() => handleError(domainMsg('categories'))) + } let narPromise = Promise.resolve([]) if (features.USE_NARRATIVES) { diff --git a/src/components/Card.jsx b/src/components/Card.jsx index f56ad2d..b63c525 100644 --- a/src/components/Card.jsx +++ b/src/components/Card.jsx @@ -145,12 +145,12 @@ class Card extends React.Component { } renderCaret () { - return ( + return this.props.features.USE_SOURCES ? ( this.toggle()} isOpen={this.state.isOpen} /> - ) + ) : null } render () { diff --git a/src/components/CardStack.jsx b/src/components/CardStack.jsx index a57932a..634648a 100644 --- a/src/components/CardStack.jsx +++ b/src/components/CardStack.jsx @@ -73,6 +73,7 @@ class CardStack extends React.Component { onViewSource={this.props.onViewSource} onHighlight={this.props.onHighlight} onSelect={this.props.onSelect} + features={this.props.features} />) }) } @@ -176,7 +177,8 @@ function mapStateToProps (state) { sourceError: state.app.errors.source, language: state.app.language, isCardstack: state.app.flags.isCardstack, - isLoading: state.app.flags.isFetchingSources + isLoading: state.app.flags.isFetchingSources, + features: state.features } } diff --git a/src/components/Layout.js b/src/components/Layout.js index fcc20bf..f9af24b 100644 --- a/src/components/Layout.js +++ b/src/components/Layout.js @@ -16,6 +16,7 @@ import Notification from './Notification.jsx' import StaticPage from './StaticPage' import TemplateCover from './TemplateCover' +import colors from '../common/global' import { binarySearch } from '../common/utilities' import { isMobile } from 'react-device-detect' @@ -87,6 +88,8 @@ class Dashboard extends React.Component { } getCategoryColor (category) { + if (!this.props.features.USE_CATEGORIES) { return colors.fallbackEventColor } + const cat = this.props.ui.style.categories[category] if (cat) { return cat @@ -168,7 +171,7 @@ class Dashboard extends React.Component { methods={{ onSelect: ev => this.handleSelect(ev, 0), onUpdateTimerange: actions.updateTimeRange, - getCategoryColor: category => this.getCategoryColor(category) + getCategoryColor: this.getCategoryColor }} /> actions.updateSelected([])} getNarrativeLinks={event => this.getNarrativeLinks(event)} - getCategoryColor={category => this.getCategoryColor(category)} + getCategoryColor={this.getCategoryColor} /> this.getY({ category, project: null })} onDragStart={() => { this.onDragStart() }} onDrag={() => { this.onDrag() }} onDragEnd={() => { this.onDragEnd() }} diff --git a/src/components/TimelineCategories.jsx b/src/components/TimelineCategories.jsx index c4b17f7..5cc8db8 100644 --- a/src/components/TimelineCategories.jsx +++ b/src/components/TimelineCategories.jsx @@ -53,10 +53,13 @@ class TimelineCategories extends React.Component { render () { const { dims } = this.props + const categories = this.props.features.USE_CATEGORIES + ? this.props.categories.map((cat, idx) => this.renderCategory(cat, idx)) + : this.renderCategory('Events', 0) return ( - {this.props.categories.map((cat, idx) => this.renderCategory(cat, idx))} + {categories}