Skip to content

Commit

Permalink
Merge pull request #362 from pavlovicnemanja/SWP-2324
Browse files Browse the repository at this point in the history
[SWP-2324] feat(publisher): Added recursive function for checking art…
  • Loading branch information
pavlovicnemanja authored Dec 19, 2024
2 parents f9a966e + 21b3dcb commit 700e528
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions client/components/ContentLists/Manual/Manual.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -324,13 +324,31 @@ class Manual extends React.Component {
format_type: "NINJSFormatter"
},
}).then((response) => {
const ninjs = this.props.publisher.publishSuperdeskArticle('new', response.export[item_id]).then((response) => {
resolve(response.article_ids[0]);
const ninjs = this.props.publisher.publishSuperdeskArticle('new', response.export[item_id]).then(async (response) => {
const article_id = await this.attemptFetch(10, item_id);
resolve(article_id);
});
});
});
}

attemptFetch = async (tries = 10, code) => {
if (tries === 0) {
return this.props.api.notify.error(
"Adding article to the content list failed, please try again. If the problem persists, please contact support."
);
}

const article = await this.props.publisher.getArticleByCode(code);
if (article) {
console.warn('Article added to the content list successfully.', article);
return article.id;
}

await new Promise(resolve => setTimeout(resolve, 3000)); // Wait for 3 seconds
return attemptFetch(tries - 1);
};

handleSourceChange = (source) => {
if (source && (source.id === 'scheduled' || source.id === 'in_progress')) {
this._querySuperdeskArticles(source.id, true);
Expand Down

0 comments on commit 700e528

Please sign in to comment.