Extensions load in background and show pending state (#1657)
Co-authored-by: Lily Delalande <119957291+lily-de@users.noreply.github.com>
This commit is contained in:
@@ -80,6 +80,9 @@ export async function addExtension(
|
|||||||
timeout: extension.timeout,
|
timeout: extension.timeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
let toastId;
|
||||||
|
if (!silent) toastId = toast.loading(`Adding ${extension.name} extension...`);
|
||||||
|
|
||||||
const response = await fetch(getApiUrl('/extensions/add'), {
|
const response = await fetch(getApiUrl('/extensions/add'), {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
headers: {
|
headers: {
|
||||||
@@ -93,6 +96,7 @@ export async function addExtension(
|
|||||||
|
|
||||||
if (!data.error) {
|
if (!data.error) {
|
||||||
if (!silent) {
|
if (!silent) {
|
||||||
|
if (toastId) toast.dismiss(toastId);
|
||||||
toast.success(`Successfully enabled ${extension.name} extension`);
|
toast.success(`Successfully enabled ${extension.name} extension`);
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
@@ -100,7 +104,9 @@ export async function addExtension(
|
|||||||
|
|
||||||
const errorMessage = `Error adding ${extension.name} extension ${data.message ? `. ${data.message}` : ''}`;
|
const errorMessage = `Error adding ${extension.name} extension ${data.message ? `. ${data.message}` : ''}`;
|
||||||
console.error(errorMessage);
|
console.error(errorMessage);
|
||||||
toast.error(errorMessage, { autoClose: false });
|
if (toastId) toast.dismiss(toastId);
|
||||||
|
toast.error(errorMessage);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMessage = `Failed to add ${extension.name} extension: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
const errorMessage = `Failed to add ${extension.name} extension: ${error instanceof Error ? error.message : 'Unknown error'}`;
|
||||||
|
|||||||
Reference in New Issue
Block a user