import { BulbOutlined } from '@ant-design/icons'; import { useIntl } from '@umijs/max'; import { Button, Modal } from 'antd'; import React, { useEffect, useState } from 'react'; import CommandViewer from '../../_components/command-viewer'; type ViewModalProps = { title?: string; open: boolean; viewCodeContent: { curlCode: string; pythonCode: string; nodeJsCode: string; }; onCancel: () => void; }; const langMap = { shell: 'bash', python: 'python', javascript: 'javascript' }; const langOptions = [ { label: 'Curl', value: langMap.shell }, { label: 'Python', value: langMap.python }, { label: 'Node.js', value: langMap.javascript } ]; const ViewCodeModal: React.FC = (props) => { const { title, open, onCancel, viewCodeContent } = props || {}; const intl = useIntl(); const [codeValue, setCodeValue] = useState(viewCodeContent?.curlCode); const handleOnChangeLang = (value: string | number) => { if (value === langMap.shell) { setCodeValue(viewCodeContent?.curlCode); } if (value === langMap.javascript) { setCodeValue(viewCodeContent?.nodeJsCode); } if (value === langMap.python) { setCodeValue(viewCodeContent?.pythonCode); } }; const handleClose = () => { onCancel(); }; useEffect(() => { if (open) { setCodeValue(viewCodeContent?.curlCode); } }, [open]); return ( <>
{intl.formatMessage({ id: 'playground.viewcode.info' })}
{intl.formatMessage( { id: 'playground.viewcode.tips' }, { here: ( ) } )}
); }; export default ViewCodeModal;