users/ryan/modules/simple-bar/simple-bar-source/lib/components/error.jsx
d06784958d73159b5e4abafe5114804662114ed7
· 1.4 KB · 42 lines
raw
| 1 | import * as Settings from "./settings/settings.jsx"; |
| 2 | import * as Utils from "../utils"; |
| 3 | |
| 4 | // Error messages for different types of errors |
| 5 | const message = { |
| 6 | error: "Something went wrong…", |
| 7 | yabaiError: "yabai is not running", |
| 8 | aerospaceError: "AeroSpace is either not running or outdated", |
| 9 | noOutput: "Loading…", |
| 10 | noData: "JSON error…", |
| 11 | }; |
| 12 | |
| 13 | /** |
| 14 | * Component to display error messages based on the type of error. |
| 15 | * @param {Object} props - The properties object. |
| 16 | * @param {string} props.type - The type of error. |
| 17 | * @param {string} props.classes - Additional CSS classes. |
| 18 | * @returns {JSX.Element} The error component. |
| 19 | */ |
| 20 | export function Component({ type, classes }) { |
| 21 | // Combine base class with additional classes and conditional loading class |
| 22 | const errorClasses = Utils.classNames("simple-bar--empty", classes, { |
| 23 | "simple-bar--loading": type === "noOutput", |
| 24 | }); |
| 25 | |
| 26 | // Refresh the component after 2 seconds for general errors and JSON errors |
| 27 | if (type === "error" || type === "noData") { |
| 28 | setTimeout(Utils.softRefresh, 2000); |
| 29 | } |
| 30 | |
| 31 | // Refresh the component after 15 seconds for yabai and aerospace errors |
| 32 | if (type === "yabaiError" || type === "aerospaceError") { |
| 33 | setTimeout(Utils.softRefresh, 15000); |
| 34 | } |
| 35 | |
| 36 | return ( |
| 37 | <div className={errorClasses}> |
| 38 | <span>simple-bar-index.jsx: {message[type]}</span> |
| 39 | <Settings.Wrapper /> |
| 40 | </div> |
| 41 | ); |
| 42 | } |