import React from 'react'; import message from 'antd/lib/message'; import Typography from 'antd/lib/typography'; import Button from 'antd/lib/button'; import notification from 'antd/lib/notification'; import AceEditor from 'react-ace'; import 'brace/mode/javascript'; import 'brace/theme/tomorrow'; import { getBeforeAfterCode, saveBeforeAfterCode } from '../server/service'; import { aceEditorStyle } from './codeStyle'; import { ErrorHandler } from '../common/ErrorHandler'; import { useAsync } from '../hook/useAsync'; import { StorageType } from '../server/storage.typing'; import { Info } from '../common/Info'; import { BeforeAfterType } from '../server/typing'; const { Title, Paragraph } = Typography; const onSave = ( code: string, type: BeforeAfterType, projectId: string, storageType: StorageType, ) => async () => { try { const hide = message.loading('Saving...', 0); await saveBeforeAfterCode(storageType, projectId, type, code); hide(); message.success('Code saved.', 2); } catch (error) { notification['error']({ message: 'Something went wrong!', description: error.toString(), }); } } interface Props { type: BeforeAfterType; projectId: string; storageType: StorageType; title: string; info: string; codeParam?: string; } export const BeforeAfter = ({ type, projectId, storageType, title, info, codeParam = '', }: Props) => { const { error, result: code, setResult: setCode } = useAsync(() => getBeforeAfterCode(storageType, projectId, type)); if (error) { return ; } return ( <> {title} {info} ); }