Skip to content

Commit 8152d5e

Browse files
committed
mg pseudo code for import export features
1 parent 68658d1 commit 8152d5e

File tree

3 files changed

+41
-18
lines changed

3 files changed

+41
-18
lines changed

src/app/components/StateRoute/PerformanceVisx/BarGraphComparison.tsx

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,21 +138,20 @@ const BarGraphComparison = (props: BarGraphComparisonProps): JSX.Element => {
138138
// const classes = useStyles();
139139

140140
const StyledFormControl = styled(FormControl)(({ theme }) => ({
141-
margin: theme.spacing(1),
142-
minWidth: 80,
143-
height: 30,
144-
}));
145-
146-
const StyledSelect = styled(Select)({
147-
minWidth: 80,
148-
fontSize: '.75rem',
149-
fontWeight: 200,
150-
border: '1px solid grey',
151-
borderRadius: 4,
152-
color: 'grey',
153-
height: 30,
154-
});
141+
margin: theme.spacing(1),
142+
minWidth: 80,
143+
height: 30,
144+
}));
155145

146+
const StyledSelect = styled(Select)({
147+
minWidth: 80,
148+
fontSize: '.75rem',
149+
fontWeight: 200,
150+
border: '1px solid grey',
151+
borderRadius: 4,
152+
color: 'grey',
153+
height: 30,
154+
});
156155

157156
const handleSeriesChange = (event: Event) => {
158157
if (!event) return;
@@ -247,7 +246,6 @@ const StyledSelect = styled(Select)({
247246
<StyledSelect
248247
style={{ color: 'white' }}
249248
labelId='simple-select-outlined-label'
250-
251249
open={open}
252250
onClose={handleClose}
253251
onOpen={handleOpen}
@@ -266,12 +264,11 @@ const StyledSelect = styled(Select)({
266264
</StyledSelect>
267265
</StyledFormControl>
268266
<h4 style={{ padding: '0 1rem' }}>Compare Actions </h4>
269-
<StyledFormControl variant='outlined' >
267+
<StyledFormControl variant='outlined'>
270268
<StyledSelect
271269
style={{ color: 'white' }}
272270
labelId='snapshot-select'
273271
id='snapshot-select'
274-
275272
open={picOpen}
276273
onClose={picHandleClose}
277274
onOpen={picHandleOpen}

src/app/containers/ButtonsContainer.tsx

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,31 +13,57 @@ import { useStoreContext } from '../store';
1313

1414
import Tutorial from '../components/Tutorial';
1515

16+
// function exportHandler takes in a parameter snapshots which is typed as an array
17+
// the function does not return anything so the type is void
1618
function exportHandler(snapshots: []): void {
1719
// create invisible download anchor link
20+
// fileDownload is typed as HTMLAnchorElement
21+
// HTML anchor element has the <a></a> tag
1822
const fileDownload: HTMLAnchorElement = document.createElement('a');
1923

2024
// set file in anchor link
25+
// href is the reference to the URL object created from the Blob
2126
fileDownload.href = URL.createObjectURL(
27+
// Blob obj is raw data, json is raw, stringify the snapshots as json so the Blob can access the raw data
2228
new Blob([JSON.stringify(snapshots)], { type: 'application/json' }),
2329
);
2430

2531
// set anchor as file download and click it
32+
// anchor element has a download attribute
33+
// snapshot.json is what the file name will be once the file is downloaded locally
2634
fileDownload.setAttribute('download', 'snapshot.json');
35+
// click is a method on all HTML elements
36+
// simulates a mouse click, triggering the element's click event
2737
fileDownload.click();
2838

2939
// remove file url
40+
// after file is downloaded, remove the href
3041
URL.revokeObjectURL(fileDownload.href);
3142
}
3243

3344
function importHandler(dispatch: (a: unknown) => void): void {
45+
// create input element
46+
// fileUpload is HTMLInputElement, which is an interface for HTML input elements
47+
// accepts data from user
3448
const fileUpload = document.createElement('input');
49+
// file is a type attribute on the input element, allows users to select a file
3550
fileUpload.setAttribute('type', 'file');
3651

52+
// onChange is when value of HTML element is changed
53+
// parameter for onChange is an event
3754
fileUpload.onchange = (e: Event) => {
55+
// FileReader is an object
56+
// reads contents of local files in async
57+
// can use file or blob objects
3858
const reader = new FileReader();
3959
reader.onload = () => {
60+
// once the local file has been loaded, result property on FileReader object returns the file's contents
61+
// then take contents and convert to a string
4062
const test = reader.result.toString();
63+
// dispatch sends the result of calling importSnapshots on the json parsed data from the file contents from the new FileReader object
64+
// importSnapshots defined in actions/actions.ts/line 71, it returns an action object with a type and payload, payload is newSnaps parameter
65+
// dispatch function is being called with that action object which gets sent to the reducer in reducers/mainReducer.js/line 203
66+
// this updates the current tab
4167
return dispatch(importSnapshots(JSON.parse(test)));
4268
};
4369
const eventFiles = e.target as HTMLInputElement;

src/extension/background.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
337337
reloaded[tabId] = false;
338338
} else {
339339
tabsObj[tabId].snapshots.push(request.payload);
340-
//! INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN!!!!
340+
// INVOKING buildHierarchy FIGURE OUT WHAT TO PASS IN
341341
if (!tabsObj[tabId][index]) {
342342
sendToHierarchy(tabsObj[tabId], new Node(request.payload, tabsObj[tabId]));
343343
}

0 commit comments

Comments
 (0)