Codemirror initial value support

This commit is contained in:
Gregory Schier
2023-02-24 16:43:47 -08:00
parent a77e378730
commit 2b92b7ab01
4 changed files with 71 additions and 57 deletions

View File

@@ -3,15 +3,12 @@ import './Editor.css';
interface Props {
contentType: string;
value: string;
initialValue?: string;
value?: string;
onChange?: (value: string) => void;
}
export default function Editor(props: Props) {
const { ref } = useCodeMirror({
value: props.value,
contentType: props.contentType,
onChange: props.onChange,
});
const { ref } = useCodeMirror(props);
return <div ref={ref} className="cm-wrapper" />;
}

View File

@@ -1,30 +1,22 @@
import { HStack } from './Stacks';
import { DropdownMenuRadio } from './Dropdown';
import { Button } from './Button';
import { Input } from './Input';
import { FormEvent, useState } from 'react';
import { FormEvent } from 'react';
import { IconButton } from './IconButton';
interface Props {
sendRequest: () => Promise<void>;
sendRequest: () => void;
loading: boolean;
method: { label: string; value: string };
url: string;
onMethodChange: (method: { label: string; value: string }) => void;
onUrlChange: (url: string) => void;
}
export function UrlBar({ sendRequest, onMethodChange, method, onUrlChange, url }: Props) {
const [loading, setLoading] = useState(false);
export function UrlBar({ sendRequest, loading, onMethodChange, method, onUrlChange, url }: Props) {
const handleSendRequest = async (e: FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (loading) return;
setLoading(true);
try {
await sendRequest();
} finally {
setLoading(false);
}
sendRequest();
};
return (