Skip to content

Commit 73feae3

Browse files
committed
chore: cleanup
1 parent 82f16c9 commit 73feae3

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

site/src/DynamicForm.tsx

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -239,21 +239,13 @@ export function DynamicForm() {
239239
<Controller
240240
name={param.name}
241241
control={methods.control}
242-
render={({ field }) => {
243-
const { debounced } = useDebouncedFunction(
244-
(e: React.ChangeEvent<HTMLInputElement>) => field.onChange(e),
245-
1000
246-
);
247-
248-
return (
249-
<Input
250-
onChange={debounced}
251-
className="w-[300px]"
252-
type={mapParamTypeToInputType(param.type)}
253-
defaultValue={param.default_value}
254-
/>
255-
);
256-
}}
242+
render={({ field }) => (
243+
<DebouncedInput
244+
field={field}
245+
type={mapParamTypeToInputType(param.type)}
246+
defaultValue={param.default_value}
247+
/>
248+
)}
257249
/>
258250
{renderDiagnostics(param.diagnostics)}
259251
</div>
@@ -273,6 +265,26 @@ export function DynamicForm() {
273265
);
274266
};
275267

268+
const DebouncedInput = ({ field, type, defaultValue }: {
269+
field: { onChange: (e: React.ChangeEvent<HTMLInputElement>) => void },
270+
type: string,
271+
defaultValue?: string
272+
}) => {
273+
const { debounced } = useDebouncedFunction(
274+
(e: React.ChangeEvent<HTMLInputElement>) => field.onChange(e),
275+
2000
276+
);
277+
278+
return (
279+
<Input
280+
onChange={debounced}
281+
className="w-[300px]"
282+
type={type}
283+
defaultValue={defaultValue}
284+
/>
285+
);
286+
};
287+
276288
if (isLoading && directories.length === 0) {
277289
return <div>Loading directories...</div>;
278290
}

site/src/useWebSocket.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ export function useWebSocket<T>(url: string, testdata: string) {
2525
console.log("Received message:", data);
2626
setMessage(data);
2727
} catch (err) {
28-
console.error("Invalid JSON from server:", event.data);
28+
console.error("Invalid JSON from server: ", event.data);
29+
console.error("Error: ", err);
2930
}
3031
};
3132

@@ -51,7 +52,6 @@ export function useWebSocket<T>(url: string, testdata: string) {
5152
setMessage(null);
5253
setConnectionStatus('connecting');
5354

54-
// Create new connection after a small delay to ensure cleanup completes
5555
const createConnection = () => {
5656
urlRef.current = url;
5757
connectWebSocket();

0 commit comments

Comments
 (0)