Skip to content

Commit a5b1483

Browse files
author
Robert S
committed
Add api request minimum delay to show loading indicator
1 parent f68dd93 commit a5b1483

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/utilities/HttpUtility.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ export default class HttpUtility {
7474
...oc(config).headers(undefined),
7575
},
7676
};
77-
const axiosResponse = await axios(axiosRequestConfig);
77+
78+
const [axiosResponse] = await Promise.all([axios(axiosRequestConfig), HttpUtility._delay()]);
7879

7980
const { status, data, request } = axiosResponse;
8081

@@ -154,4 +155,17 @@ export default class HttpUtility {
154155

155156
return model;
156157
}
158+
159+
/**
160+
* We want to show the loading indicator to the user but sometimes the api
161+
* request finished too quickly. This makes sure there the loading indicator is
162+
* visual for at least a given time.
163+
*
164+
* @param duration
165+
* @returns {Promise<unknown>}
166+
* @private
167+
*/
168+
static _delay(duration = 250) {
169+
return new Promise((resolve) => setTimeout(resolve, 250));
170+
}
157171
}

0 commit comments

Comments
 (0)