diff --git a/scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx b/scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx index 5aa7b0c163..ca4a73dc97 100644 --- a/scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx +++ b/scripts/apps/highlights/components/SetHighlightsForMultipleArticlesModal.tsx @@ -1,10 +1,11 @@ import React from 'react'; -import {gettext} from 'core/utils'; +import {getArticleLabel, gettext} from 'core/utils'; import {connectServices} from 'core/helpers/ReactRenderAsync'; import {IDesk, IArticle} from 'superdesk-api'; import {getHighlightsLabel, IHighlight} from '../services/HighlightsService'; import {Modal} from 'superdesk-ui-framework/react/components/Modal'; import {Button, ButtonGroup} from 'superdesk-ui-framework/react'; +import {notify} from 'core/notify/notify'; interface IProps { closeModal(): void; @@ -28,6 +29,7 @@ export function getModalForMultipleHighlights(articles: Array, deskId: this.handleChange = this.handleChange.bind(this); this.markHighlights = this.markHighlights.bind(this); } + componentDidMount() { this.props.highlightsService.get(deskId).then((res) => { this.setState({ @@ -35,6 +37,7 @@ export function getModalForMultipleHighlights(articles: Array, deskId: }); }); } + markHighlights() { var promises = Promise.resolve(); @@ -42,6 +45,11 @@ export function getModalForMultipleHighlights(articles: Array, deskId: this.state.selectedHighlights.forEach((highlightId) => { if (article.highlights == null || article.highlights.includes(highlightId) === false) { promises.then(() => this.props.highlightsService.markItem(highlightId, article)); + } else { + notify.error(gettext( + 'Article {{slug}} is already marked for this highlight', + {slug: getArticleLabel(article)}, + )); } }); }); @@ -50,6 +58,7 @@ export function getModalForMultipleHighlights(articles: Array, deskId: this.props.closeModal(); }); } + handleChange(event: React.ChangeEvent) { const selected = []; const {options} = event.target; @@ -66,6 +75,7 @@ export function getModalForMultipleHighlights(articles: Array, deskId: selectedHighlights: selected, }); } + render() { if (this.state.highlightsForDesk == null) { return null; diff --git a/scripts/apps/highlights/services/HighlightsService.ts b/scripts/apps/highlights/services/HighlightsService.ts index f16e2d352e..2463fea6fe 100644 --- a/scripts/apps/highlights/services/HighlightsService.ts +++ b/scripts/apps/highlights/services/HighlightsService.ts @@ -1,8 +1,7 @@ import _ from 'lodash'; import {gettext} from 'core/utils'; import {IPackagesService} from 'types/Services/Packages'; -import {IBaseRestApiResponse} from 'superdesk-api'; -import {notify} from 'core/notify/notify'; +import {IArticle, IBaseRestApiResponse} from 'superdesk-api'; import {trackArticleActionProgress} from 'core/helpers/network'; export interface IHighlight extends IBaseRestApiResponse { @@ -112,17 +111,19 @@ export function HighlightsService(api, $q, $cacheFactory, packages: IPackagesSer }; /** - * Mark an item for a highlight + * Mark/Unmark an item for a highlight */ - service.markItem = function(highlight, markedItem) { + service.markItem = function(highlight: string, markedItem: IArticle) { + const addToHighlight = (markedItem.highlights ?? []).includes(highlight) === false; + return trackArticleActionProgress( () => api.save( 'marked_for_highlights', {highlights: [highlight], marked_item: markedItem._id}, ), markedItem._id, - gettext('Item marked'), - gettext('Couldn\'t mark item'), + addToHighlight ? gettext('Item marked') : gettext('Item unmarked'), + addToHighlight ? gettext('Couldn\'t mark item') : gettext('Couldn\'t unmark item'), ); };