MCPcopy Index your code
hub / github.com/microsoft/SandDance / readFile

Method readFile

docs/app/js/sanddance-app.js:52102–52134  ·  view source on GitHub ↗
(e)

Source from the content-addressed store, hash-verified

52100 };
52101 }
52102 readFile(e) {
52103 if (e.target.files) {
52104 this.setState({
52105 working: true
52106 });
52107 const file = e.target.files[0];
52108 const reader = new FileReader();
52109 reader.onload = ()=>{
52110 const rawText = reader.result;
52111 let snapshots;
52112 try {
52113 snapshots = JSON.parse(rawText);
52114 } catch (e) {
52115 this.setState({
52116 fileFormatError: (0, _language.strings).errorInvalidFileFormat,
52117 working: false
52118 });
52119 }
52120 //validate these are snapshots
52121 if (validSnapshots(snapshots)) {
52122 this.props.onImportSnapshot(snapshots);
52123 this.setState({
52124 working: false
52125 });
52126 this.props.onDismiss();
52127 } else this.setState({
52128 fileFormatError: (0, _language.strings).errorInvalidFileFormat,
52129 working: false
52130 });
52131 };
52132 reader.readAsText(file);
52133 }
52134 }
52135 render() {
52136 return /*#__PURE__*/ _react.createElement("div", null, /*#__PURE__*/ _react.createElement((0, _sanddanceExplorer.controls).Dialog, {
52137 hidden: false,

Callers 6

renderMethod · 0.95
pFunction · 0.45
activateFunction · 0.45
fileLoaderFunction · 0.45
fileLoaderFunction · 0.45
fileLoaderFunction · 0.45

Calls 1

validSnapshotsFunction · 0.70

Tested by

no test coverage detected