Skip to content

Commit

Permalink
Add UI feedback (#4679)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecalcc authored Oct 31, 2024
1 parent 5fac05b commit 95aa992
Show file tree
Hide file tree
Showing 6 changed files with 62 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React from 'react';
import HighlightBtn from '../components/HighlightBtn';
import {Loader, Spinner} from 'superdesk-ui-framework/react';

/**
* @ngdoc directive
Expand Down
24 changes: 18 additions & 6 deletions scripts/apps/highlights/services/HighlightsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ 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 {trackArticleActionProgress} from 'core/helpers/network';

export interface IHighlight extends IBaseRestApiResponse {
name: string;
Expand Down Expand Up @@ -54,11 +56,13 @@ export function HighlightsService(api, $q, $cacheFactory, packages: IPackagesSer
var criteria = {};

if (desk) {
criteria = {where: {$or: [
{desks: desk},
{desks: {$size: 0}},
],
},
criteria = {
where: {
$or: [
{desks: desk},
{desks: {$size: 0}},
],
},
};
}

Expand Down Expand Up @@ -111,7 +115,15 @@ export function HighlightsService(api, $q, $cacheFactory, packages: IPackagesSer
* Mark an item for a highlight
*/
service.markItem = function(highlight, markedItem) {
return api.save('marked_for_highlights', {highlights: [highlight], marked_item: markedItem._id});
return trackArticleActionProgress(
() => api.save(
'marked_for_highlights',
{highlights: [highlight], marked_item: markedItem._id},
),
markedItem._id,
gettext('Item marked'),
gettext('Couldn\'t mark item'),
);
};

/**
Expand Down
10 changes: 10 additions & 0 deletions scripts/apps/search/components/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ export class Item extends React.Component<IProps, IState> {
this.onDragStart = this.onDragStart.bind(this);
this.openAuthoringView = this.openAuthoringView.bind(this);
this.toggleNested = this.toggleNested.bind(this);
this.handleActionLoading = this.handleActionLoading.bind(this);
}

componentWillMount() {
Expand All @@ -119,13 +120,21 @@ export class Item extends React.Component<IProps, IState> {
}
}

handleActionLoading(e: CustomEvent) {
if (e.detail.itemId === this.props.item._id) {
this.setState({loading: e.detail.loading});
}
}

componentDidMount() {
addEventListener('article-action-loading', this.handleActionLoading);
this._mounted = true;
}

componentWillUnmount() {
this._mounted = false;
closeActionsMenu(this.props.item._id);
removeEventListener('article-action-loading', this.handleActionLoading);
}

componentWillReceiveProps(nextProps) {
Expand Down Expand Up @@ -358,6 +367,7 @@ export class Item extends React.Component<IProps, IState> {
default:
return (
<ListItemTemplate
loading={this.state.loading}
item={item}
relatedEntities={this.props.relatedEntities}
itemSelected={itemSelected}
Expand Down
2 changes: 2 additions & 0 deletions scripts/apps/search/components/ItemListTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface IPropsItemsListTemplate extends IPropsItemListInfo {
selectingDisabled: boolean;
getActionsMenu: () => any;
multiSelect: IMultiSelectNew | ILegacyMultiSelect;
loading?: boolean;
}

export class ListItemTemplate extends React.Component<IPropsItemsListTemplate> {
Expand All @@ -29,6 +30,7 @@ export class ListItemTemplate extends React.Component<IPropsItemsListTemplate> {
: null
}
<ListItemInfo
loading={this.props.loading}
item={item}
relatedEntities={this.props.relatedEntities}
openAuthoringView={this.props.openAuthoringView}
Expand Down
3 changes: 3 additions & 0 deletions scripts/apps/search/components/ListItemInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {flatMap} from 'lodash';
import {extensions} from 'appConfig';
import {IDesk, IArticle, IListViewFieldWithOptions} from 'superdesk-api';
import {IRelatedEntities} from 'core/getRelatedEntities';
import {Loader} from 'superdesk-ui-framework/react';

export interface IPropsItemListInfo {
item: IArticle;
Expand All @@ -14,6 +15,7 @@ export interface IPropsItemListInfo {
ingestProvider: any;
profilesById: any;
highlightsById: any;
loading?: boolean;
markedDesksById: any;
openAuthoringView: (rewrittenBy?: string) => void;
narrow: any;
Expand Down Expand Up @@ -69,6 +71,7 @@ export class ListItemInfo extends React.PureComponent<IPropsItemListInfo> {
className={className}
style={{display: 'flex', justifyContent: 'space-between', alignItems: 'center'}}
>
{this.props.loading && <Loader overlay />}
{listItems}
{
articleDisplayWidgets.length < 1 ? null : (
Expand Down
28 changes: 28 additions & 0 deletions scripts/core/helpers/network.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ng from 'core/services/ng';
import {appConfig} from '../../appConfig';
import {notify} from 'core/notify/notify';

interface IHttpRequestOptions {
method: 'GET' | 'POST' | 'PATCH' | 'PUT' | 'DELETE';
Expand Down Expand Up @@ -173,3 +174,30 @@ export function uploadFileWithProgress<T>(
});
});
}

export function trackArticleActionProgress<T>(
getPromise: () => Promise<T>,
itemId: string,
successMessage: string,
errorMessage: string,
): Promise<T> {
dispatchEvent(new CustomEvent('article-action-loading', {
detail: {loading: true, itemId},
}));

return getPromise()
.then((res) => {
notify.success(successMessage);

return res;
}).catch((error) => {
notify.error(errorMessage);

return error;
})
.finally(() => {
dispatchEvent(new CustomEvent('article-action-loading', {
detail: {loading: false, itemId},
}));
});
}

0 comments on commit 95aa992

Please sign in to comment.