Skip to content

Commit

Permalink
made functionality for exporting code to python using file-saver library
Browse files Browse the repository at this point in the history
  • Loading branch information
srivastava9 authored and orionpax00 committed Jul 5, 2020
1 parent b0cc7c0 commit e6252a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
3 changes: 3 additions & 0 deletions tensormap-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@
"last 1 firefox version",
"last 1 safari version"
]
},
"devDependencies": {
"@types/file-saver": "^2.0.1"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Tabs from "@material-ui/core/Tabs";
import Tab from "@material-ui/core/Tab";
import Typography from "@material-ui/core/Typography";
import { Button } from "@material-ui/core";

import Filesaver from "file-saver";
import GetAppIcon from "@material-ui/icons/GetApp";
interface TabContainerProps {
children?: React.ReactNode;
Expand Down Expand Up @@ -40,6 +40,10 @@ export default function SimpleTabs(props: SimpleTabsProps) {
let newText = props.code.split("\n").map((item, i) => {
return <p key={i}>{item}</p>;
});
function exportPython() {
var blob = new Blob([props.code], { type: "text/x-python;charset=utf-8" });
Filesaver.saveAs(blob, "hello-world.py");
}

return (
<div className="log_main">
Expand All @@ -54,7 +58,11 @@ export default function SimpleTabs(props: SimpleTabsProps) {
{value === 1 && (
<div className={props.divStyle}>
<TabContainer>{newText}</TabContainer>
<Button variant="contained" className={props.exportStyle}>
<Button
variant="contained"
className={props.exportStyle}
onClick={exportPython}
>
<GetAppIcon fontSize="small" /> Export to Python
</Button>
</div>
Expand Down

0 comments on commit e6252a1

Please sign in to comment.