You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// href is the reference to the URL object created from the Blob
22
-
newBlob([JSON.stringify(snapshots)],{type: 'application/json'}),// Blob obj is raw data. The tabs[currentTab] object is stringified so the Blob can access the raw data
fileDownload.setAttribute('download','snapshot.json');// We set a download attribute with snapshots.json as the file name. This allows us to download the file when the element is 'clicked.' The file will be named snapshots.json once the file is downloaded locally
26
-
fileDownload.click();// click is a method on all HTML elements that simulates a mouse click, triggering the element's click event
27
-
28
-
URL.revokeObjectURL(fileDownload.href);// after file is downloaded, remove the href
// function handles the importing of a tabs[currentTab] object when the upload button is selected
33
-
constfileUpload=document.createElement('input');// invisible HTML element that will hold our uploaded tabs[currentTab] object
34
-
fileUpload.setAttribute('type','file');// Attributes added to HTML element
22
+
constfileUpload=document.createElement('input');
23
+
fileUpload.setAttribute('type','file');
35
24
36
25
fileUpload.onchange=(e: Event)=>{
37
-
// onChange is when value of HTML element is changed
38
-
constreader=newFileReader();// FileReader is an object that reads contents of local files in async. It can use file or blob objects
39
-
consteventFiles=e.targetasHTMLInputElement;// uploaded tabs[currentTab] object is stored as the event.target
26
+
constreader=newFileReader();
27
+
consteventFiles=e.targetasHTMLInputElement;
40
28
41
29
if(eventFiles){
42
-
// if the fileUpload element has an eventFiles
43
-
reader.readAsText(eventFiles.files[0]);// the reader parses the file into a string and stores it within the reader object
30
+
reader.readAsText(eventFiles.files[0]);
44
31
}
45
32
46
33
reader.onload=()=>{
47
-
consttest=reader.result.toString();// once the local file has been loaded, result property on FileReader object returns the file's contents and then converts the file contents to a string
48
-
returndispatch(importSnapshots(JSON.parse(test)));// dispatch sends the result of of converting our tabs[currentTab] object => string => JSON Object. This updates the current tab
0 commit comments