@wandelbots/wandelbots-js-react-components
Version:
React UI toolkit for building applications on top of the Wandelbots platform
88 lines (87 loc) • 2.71 kB
JavaScript
import { A as a, j as t } from "./index-CAib4NKw.js";
import { useTheme as c, Stack as i, CircularProgress as m, capitalize as g } from "@mui/material";
import { lowerFirst as d } from "lodash-es";
import { useState as u, useEffect as f } from "react";
function h(e) {
try {
return JSON.stringify(e);
} catch {
return;
}
}
function S(e, r) {
throw new Error(r + ` ${JSON.stringify(e)}`);
}
function x(e) {
var r, s, o, n;
return e instanceof a && e.code === "ERR_NETWORK" ? "Failed to connect to the server. Please check your internet connection." : e instanceof a && e.response ? `${(r = e.response) == null ? void 0 : r.status} ${(s = e.response) == null ? void 0 : s.statusText} from ${(o = e.response) == null ? void 0 : o.config.url}: ${JSON.stringify((n = e.response) == null ? void 0 : n.data)}` : e instanceof Error ? e.message : `Unexpected error: ${h(e) || e}`;
}
const T = (e) => {
const r = e.softTimeout || 3e3, [s, o] = u(!1), n = c();
return f(() => {
const l = setTimeout(() => {
o(!0);
}, r);
return () => clearTimeout(l);
}), /* @__PURE__ */ t.jsx(
i,
{
width: "100%",
height: "100%",
alignItems: "center",
justifyContent: "center",
sx: { color: n.palette.text.primary },
children: e.error ? /* @__PURE__ */ t.jsx(
w,
{
loadingMessage: e.message,
error: e.error
}
) : /* @__PURE__ */ t.jsxs(t.Fragment, { children: [
/* @__PURE__ */ t.jsx(m, { sx: { marginBottom: "24px" } }),
!!e.message && /* @__PURE__ */ t.jsx("div", { children: e.message }),
/* @__PURE__ */ t.jsx(
i,
{
sx: {
visibility: s ? "visible" : "hidden",
marginTop: "1rem",
color: n.palette.text.secondary
},
children: "This is taking longer than expected..."
}
)
] })
}
);
}, w = (e) => {
const r = x(e.error), s = e.error instanceof Error ? e.error.stack : null, o = c();
return /* @__PURE__ */ t.jsxs(
i,
{
sx: {
maxHeight: "100%",
maxWidth: "min(100%, 800px)",
padding: 2,
overflow: "auto",
color: o.palette.error.main,
"& pre": {
whiteSpace: "pre-wrap",
wordBreak: "break-word",
paddingBottom: "3rem"
}
},
children: [
(e.loadingMessage ? `Error while ${d(g(e.loadingMessage))} - ` : "") + r,
/* @__PURE__ */ t.jsx("br", {}),
s && /* @__PURE__ */ t.jsx("pre", { children: s })
]
}
);
};
export {
T as L,
w as a,
S as b
};
//# sourceMappingURL=LoadingCover-Dr9hDTku.js.map