Skip to content

Commit

Permalink
remove listener
Browse files Browse the repository at this point in the history
  • Loading branch information
trinity-1686a committed May 16, 2024
1 parent 15be541 commit df5c376
Showing 1 changed file with 7 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ export function QueryEditor(props: SearchComponentProps) {
const runSearchRef = useRef(props.runSearch);
const searchRequestRef = useRef(props.searchRequest);
const defaultValue = props.searchRequest.query === null ? `// Select an index and type your query. Example: field_name:"phrase query"` : props.searchRequest.query;
let resize: () => void;

/* eslint-disable @typescript-eslint/no-explicit-any */
function handleEditorDidMount(editor: any, monaco: any) {
Expand All @@ -55,12 +56,16 @@ export function QueryEditor(props: SearchComponentProps) {
runSearchRef.current(searchRequestRef.current);
},
})
const resize = () => {
resize = () => {
editor.layout({width: Math.max(window.innerWidth - (260+180+2*24), 200), height: 84});
}
window.addEventListener('resize', resize);
}

function handleEditorWillUnmount() {
window.removeEventListener('resize', resize);
}

useEffect(() => {
const updatedLanguageId = getLanguageId(props.searchRequest.indexId);
if (monacoRef.current !== null && updatedLanguageId !== '' && props.index !== null) {
Expand Down Expand Up @@ -102,6 +107,7 @@ export function QueryEditor(props: SearchComponentProps) {
<MonacoEditor
editorWillMount={handleEditorWillMount}
editorDidMount={handleEditorDidMount}
editorWillUnmount={handleEditorWillUnmount}
onChange={handleEditorChange}
language={languageId}
value={defaultValue}
Expand Down

0 comments on commit df5c376

Please sign in to comment.