import React from 'react' import DebugIcon from '@material-ui/icons/PlayCircleOutline' import InfoIcon from '@material-ui/icons/Info' import WarningIcon from '@material-ui/icons/ErrorOutline' import ErrorIcon from '@material-ui/icons/HighlightOff' import Markdown from 'react-markdown' const Event = ({ type, event }) => { const formatError = (err) => (
{` \`\`\`js ${err.name}: ${err.message} \`\`\` `} {`Error in \`${err.fileName}\` line \`${err.lineNumber}:${err.columnNumber}\``} {` \`\`\`js ${err.stack} \`\`\` `}
) const formatObject = (obj) => ( {` \`\`\`json ${JSON.stringify(obj, null, 2)} \`\`\` `} ) const formatEvent = (e, data = false) => { if (!data) data = [] if (typeof e === 'object') { if (e instanceof Error === true) data.push(formatError(e)) else if (Array.isArray(e)) { for (const subevent of e) data.concat(formatEvent(subevent, data)) } else data.push(formatObject(e)) } else data.push({e}) return data } return (
{type === 'debug' && } {type === 'info' && } {type === 'warning' && } {type === 'error' && }
{formatEvent(event)}
) } export default Event