Skip to content

Commit

Permalink
Fix : The related item in the item preview is not updated [SDESK-6830] (
Browse files Browse the repository at this point in the history
#4204)

* Fix : The related item in the item preview is not updated [SDESK-6830]

* fix lint

* create a throttle function to avoid fire a network request on any property change
  • Loading branch information
devketanpro authored and petrjasek committed Feb 27, 2023
1 parent 467251d commit 213b689
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions scripts/apps/archive/directives/RelatedItemsPreview.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {IArticle, IArticleField, IRendition} from 'superdesk-api';
import {gettext} from 'core/utils';
import {getThumbnailForItem} from 'core/helpers/item';
import {throttle} from 'lodash';

/**
* @ngdoc directive
Expand Down Expand Up @@ -38,11 +39,19 @@ export function RelatedItemsPreview(relationsService) {
scope.gettext = gettext;
scope.getThumbnailForItem = getThumbnailForItem;

relationsService.getRelatedItemsForField(scope.item, scope.field._id)
.then((items) => {
scope.relatedItems = items;
scope.loading = false;
});
// Define the throttled function
const getRelatedItems = throttle((item) => {
relationsService.getRelatedItemsForField(item, scope.field._id)
.then((items) => {
scope.relatedItems = items;
scope.loading = false;
});
}, 1000);

scope.$watch('item', (item) => {
scope.loading = true;
getRelatedItems(item);
});
},
};
}

0 comments on commit 213b689

Please sign in to comment.