diff --git a/src/components/FileFormControl.tsx b/src/components/FileFormControl.tsx
index af35f42..8c643ca 100644
--- a/src/components/FileFormControl.tsx
+++ b/src/components/FileFormControl.tsx
@@ -26,6 +26,8 @@ import TextField from "@mui/material/TextField"
import Tooltip from "@mui/material/Tooltip"
import styled from "@mui/system/styled"
+import { isNil } from "../common"
+
const HiddenInput = styled("input")({
display: "none",
})
@@ -83,6 +85,7 @@ interface IFileFormControlProps {
export const FileFormControl = (props: IFileFormControlProps) => {
const [fileContent, setFileContent] = React.useState(props.initialFileContent)
+ const [error, setError] = React.useState(false)
return (
@@ -94,6 +97,7 @@ export const FileFormControl = (props: IFileFormControlProps) => {
label={props.label}
helperText={props.helperText}
disabled={props.disabled ?? false}
+ error={error}
InputProps={{
readOnly: props.readOnly ?? false,
}}
@@ -108,9 +112,10 @@ export const FileFormControl = (props: IFileFormControlProps) => {
onFileChange={async (event) => {
let content = (await head(event.target.files)?.text()) ?? ""
content = props.contentPreprocessor?.(content) ?? content
- if (props.onFileChange(content)) {
- setFileContent(content)
- }
+ const result = props.onFileChange(content)
+ const isSuccessful = isNil(result) || result
+ setFileContent(content)
+ setError(!isSuccessful)
}}
/>
diff --git a/src/components/NumberFormControl.tsx b/src/components/NumberFormControl.tsx
index f17fb89..25aa4d9 100644
--- a/src/components/NumberFormControl.tsx
+++ b/src/components/NumberFormControl.tsx
@@ -40,6 +40,7 @@ interface INumberFormControlProps {
export const NumberFormControl = (props: INumberFormControlProps) => {
const [content, setContent] = React.useState(props.initialContent)
+ const [error, setError] = React.useState(false)
return (
{
max: props.max,
}}
disabled={props.disabled ?? false}
+ error={error}
onChange={(event) => {
const content = isNil(props.contentPreprocessor)
? event.target.value
: props.contentPreprocessor(event.target.value)
-
- if (props.onChange(content)) {
- setContent(content)
- }
+ const result = props.onChange(content)
+ const isSuccessful = isNil(result) || result
+ setContent(content)
+ setError(!isSuccessful)
}}
/>
)
diff --git a/src/pages/settings.tsx b/src/pages/settings.tsx
index c93001e..4e1b46f 100644
--- a/src/pages/settings.tsx
+++ b/src/pages/settings.tsx
@@ -68,7 +68,11 @@ const App = ({ data }: PageProps) => {
)
const jsonMinifyPreprocessor = (json: string): string => {
- return JSON.stringify(JSON.parse(json))
+ try {
+ return JSON.stringify(JSON.parse(json))
+ } catch (ex) {
+ return "{}"
+ }
}
return (