Skip to content

Commit

Permalink
fix: covert code output
Browse files Browse the repository at this point in the history
  • Loading branch information
koladilip committed Jun 14, 2024
1 parent bc963dd commit d070812
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/Playground.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ const PlayGround = (props: {
return;
}
try {
setResult({ output: props.convert(code) });
setResult({ output: props.convert(code), langugage: 'javascript' });
} catch (error: any) {
setResult({ error: error.message });
}
Expand Down
15 changes: 13 additions & 2 deletions src/ShowResult.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,17 @@ import Editor from '@monaco-editor/react';
import './ShowResult.css';
import { Result } from './types';

function getResultValue(result: Result) {
if(result.langugage === 'javascript') {
return result.output;
}
return JSON.stringify(result.output, null, 2);
}

function getCodeLanguage(result: Result) {
return result.langugage || 'json';
}

const ShowResult = (props: { result?: Result }) => {
const result = props.result;
if (!result) {
Expand All @@ -15,8 +26,8 @@ const ShowResult = (props: { result?: Result }) => {
}
return (
<Editor
defaultLanguage="json"
value={JSON.stringify(result.output, null, 2)}
defaultLanguage={getCodeLanguage(result)}
value={getResultValue(result)}
options={{ readOnly: true }}
/>
);
Expand Down
1 change: 1 addition & 0 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ export const DEFAULT_BINDINGS = `const bindings = {
export type Result = {
output?: any;
error?: string;
langugage?: string;
};

0 comments on commit d070812

Please sign in to comment.