diff --git a/src/main/dashboard/app.tsx b/src/main/dashboard/app.tsx index 6337464..adb3928 100644 --- a/src/main/dashboard/app.tsx +++ b/src/main/dashboard/app.tsx @@ -1,14 +1,12 @@ -/* eslint-disable */ - -import { createEffect, createSignal, Match, Setter, Show, Switch } from 'solid-js'; -import { render } from 'solid-js/web'; -import { eureka } from '../ctx'; +import {createEffect, createSignal, Match, Setter, Show, Switch, For, createMemo} from 'solid-js'; +import {render} from 'solid-js/web'; +import {eureka} from '../ctx'; import close from './assets/icon--close.svg'; import globalCss from './style.css'; import normalizeCss from './normalize.css'; -import styles, { stylesheet } from './style.module.css'; +import styles, {stylesheet} from './style.module.css'; import formatMessage from 'format-message'; -import { loadedExtensions } from '../middleware/index'; +import {loadedExtensions} from '../middleware/index'; import settingsAgent from '../util/settings'; export enum DashboardStatus { @@ -34,392 +32,469 @@ type LoaderType = 'URL' | 'Code' | 'File'; const settings = settingsAgent.getSettings(); +/** + * A component that formats and displays a message based on the provided id and default text. + * @param props - The properties for the formatted message. + * @param props.id - The message id. + * @param props.default - The default message text. + * @param props.values - Optional values to replace in the message. + * @returns A formatted message. + */ function FormattedMessage (props: { id: string, default: string, values?: Record }) { - return <>{formatMessage({ id: props.id, default: props.default }, props.values)}; + return <>{formatMessage({id: props.id, default: props.default}, props.values)}; } -function TabNav(props: { tabs: Tab[], active: DashboardStatus, onChange: (tab: DashboardStatus) => void }) { - return ( -
- {props.tabs.map(tab => ( -
props.onChange(tab.id)} - > - {tab.label} +/** + * A component that renders a tab navigation. + * @param props - The properties for the tab navigation. + * @param props.tabs - The list of tabs. + * @param props.active - The currently active tab. + * @param props.onChange - The function to call when a tab is clicked. + * @returns A tab navigation component. + */ +function TabNav (props: { tabs: Tab[], active: DashboardStatus, onChange: (tab: DashboardStatus) => void }) { + return ( +
+ {tab => ( +
props.onChange(tab.id)} + > + {tab.label} +
+ )}
- ))} -
- ); -} - -function classNames(...classes: (string | null | undefined)[]): string { - return classes.filter(Boolean).join(' '); + ); } -function utoa(data: string) { - return btoa(unescape(encodeURIComponent(data))); +/** + * Encodes a string to base64. + * @param data - The data to encode. + * @returns The base64 encoded string. + */ +function utoa (data: string) { + return btoa(unescape(encodeURIComponent(data))); } -function stringToDataURL(str: string) { - return `data:text/plain;base64,${utoa(str)}`; +/** + * Converts a string to a data URL. + * @param str - The string to convert. + * @returns The data URL. + */ +function stringToDataURL (str: string) { + return `data:text/plain;base64,${utoa(str)}`; } +/** + * A switch component that toggles between true and false states. + * @param props - The properties for the switch component. + * @param props.value - The current value of the switch. + * @param props.disabled - Whether the switch is disabled. + * @param props.onChange - The function to call when the switch is toggled. + * @returns A switch component. + */ function SwitchComponent (props: SwitchProps) { - const [value, setValue] = createSignal(props.value ?? false); - - const handleClick = () => { - if (!props.disabled) { - props.onChange(!value()); - setValue(!value()); - } - }; - - const handleKeyDown = (event: KeyboardEvent) => { - if (event.key === 'Enter' && !props.disabled) { - setValue(!value()); - props.onChange(!value()); - event.stopPropagation(); - } - }; - - return ( -
-
- -
- ); -} + const [value, setValue] = createSignal(false); + createEffect(() => { + setValue(props.value ?? false); + }); -function LoaderForm() { - const [loaderType, setLoaderType] = createSignal('URL'); - const [extensionURL, setURL] = createSignal(''); - const [errorMessage, setErrorMessage] = createSignal(''); - const [extensionCode, setCode] = createSignal(''); - const [extensionFile, setFile] = createSignal(null); - const [fileContent, setFileContent] = createSignal(null); // Store file content - const [loading, setLoading] = createSignal(false); - - function shouldDisable() { - if (loading()) return true; - switch (loaderType()) { - case 'URL': - return !extensionURL().trim(); - case 'Code': - return !extensionCode().trim(); - case 'File': - return !extensionFile(); // Ensure this returns false when a file is selected - default: - return true; // Default case to ensure safety - } - } - - return ( -
-
- {(['URL', 'Code', 'File'] as LoaderType[]).map(type => ( -
setLoaderType(type)} - > - {formatMessage({ id: `eureka.loader.${type.toLowerCase()}`, default: type })} -
- ))} -
- -
- - - setURL(e.currentTarget.value)} - value={extensionURL()} - class={styles.input} - /> - - -