Abort requests when quickly changing listing query
[MAILPOET-5395]
This commit is contained in:
@@ -250,17 +250,24 @@ export async function loadDynamicSegments(query?: Query) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
select(storeName).getDynamicSegmentsLoading().request?.abort();
|
||||||
|
|
||||||
const response = await MailPoet.Ajax.post({
|
const response = await MailPoet.Ajax.post({
|
||||||
api_version: 'v1',
|
api_version: 'v1',
|
||||||
endpoint: 'dynamic_segments',
|
endpoint: 'dynamic_segments',
|
||||||
action: 'listing',
|
action: 'listing',
|
||||||
data: segmentsQuery,
|
data: segmentsQuery,
|
||||||
|
onRequestStart: (request: XMLHttpRequest) =>
|
||||||
|
void dispatch(storeName).setDynamicSegmentsLoading(true, request),
|
||||||
});
|
});
|
||||||
const keys = Object.keys(response);
|
const keys = Object.keys(response);
|
||||||
if (keys.includes('data') && keys.includes('meta')) {
|
if (keys.includes('data') && keys.includes('meta')) {
|
||||||
data = response as DynamicSegmentsList;
|
data = response as DynamicSegmentsList;
|
||||||
}
|
}
|
||||||
} catch (res: unknown) {
|
} catch (res: unknown) {
|
||||||
|
if (res === 'abort') {
|
||||||
|
return { type: 'NOOP' };
|
||||||
|
}
|
||||||
if (isErrorResponse(res)) {
|
if (isErrorResponse(res)) {
|
||||||
const errors = res.errors.map((error) => error.message).join(', ');
|
const errors = res.errors.map((error) => error.message).join(', ');
|
||||||
void dispatch(noticesStore).createErrorNotice(errors);
|
void dispatch(noticesStore).createErrorNotice(errors);
|
||||||
|
Reference in New Issue
Block a user