File size: 1,007 Bytes
3c3f089
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import React, { useEffect } from "react";
import MonacoEditor from "@monaco-editor/react";
import { useMonaco } from "../../hooks";
import { useAppDispatch, useAppSelector } from "../../store/hook";
import {
  editor_state,
  update_editor_code,
} from "../../store/features/editorSlice";

type MonacoType = { monacoLanguage: string | undefined; tab: string };

export const Monaco = ({ monacoLanguage, tab }: MonacoType) => {
  const dispatch = useAppDispatch();
  const { monacoInputValue, options } = useAppSelector(editor_state);
  const { onChange, onMount, code } = useMonaco();

  useEffect(() => {
    if (code && code?.length >= 1)
      dispatch(update_editor_code({ type: tab, content: code }));
  }, [code, dispatch, tab]);

  return (
    <MonacoEditor
      onChange={onChange}
      onMount={onMount}
      language={monacoLanguage}
      theme="vs-dark"
      options={options}
      className="h-full"
      // @ts-ignore
      value={monacoInputValue.tabs[tab]?.data || ''}
    />
  );
};