Skip to content

Commit b385373

Browse files
authored
fix: spreadsheet not updating when switching from and to a black spreadsheet (#54)
* fix: update dev cycle * chore: lint files * fix: spreadsheet not updating when switching from and to a black spreadsheet * chore: build * chore: increment version * chore: increment version Co-authored-by: Johnny Almonte <[email protected]>
1 parent 00cbf5c commit b385373

File tree

14 files changed

+6347
-13520
lines changed

14 files changed

+6347
-13520
lines changed

.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/**
2+
dist/**
3+
webpack.*

.eslintrc

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
{
2+
"env": {
3+
"browser": true,
4+
"es6": true
5+
},
6+
"extends": [
7+
"@standardnotes/eslint-config-extensions",
8+
"plugin:react/recommended"
9+
],
10+
"parser": "@babel/eslint-parser",
11+
"parserOptions": {
12+
"ecmaVersion": 11,
13+
"ecmaFeatures": {
14+
"jsx": true
15+
},
16+
"sourceType": "module"
17+
},
18+
"plugins": [
19+
"react"
20+
],
21+
"settings": {
22+
"react": {
23+
"version": "detect"
24+
}
25+
},
26+
"globals": {
27+
"$": true
28+
}
29+
}

app/components/Home.js

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,28 @@ export default class Home extends React.Component {
1717

1818
componentDidMount() {
1919
$(function() {
20-
$("#spreadsheet").kendoSpreadsheet({
20+
$('#spreadsheet').kendoSpreadsheet({
2121
rows: this.numRows,
2222
columns: this.numColumns,
2323
change: this.onChange,
2424
changeFormat: this.onChange, // triggered when cell structure changes (currency, date, etc)
2525
excelImport: (event) => {
2626
// Excel import functionality has been disabled completely.
2727
// We'll keep this code around below incase we enable it again in the future.
28-
if(!confirm("Importing will completely overwrite any existing data. Are you sure you want to continue?")) {
28+
if (!confirm('Importing will completely overwrite any existing data. Are you sure you want to continue?')) {
2929
event.preventDefault();
3030
return;
3131
}
3232

33-
if(!confirm("Note that importing from Excel may cause very large file sizes within Standard Notes, which may affect performance. You may continue with import, but if you notice performance issues, it is recommended you manually import data instead.")) {
33+
if (!confirm('Note that importing from Excel may cause very large file sizes within Standard Notes, which may affect performance. You may continue with import, but if you notice performance issues, it is recommended you manually import data instead.')) {
3434
event.preventDefault();
3535
return;
3636
}
3737

3838
event.promise.done(() => {
39-
console.log("Import complete");
39+
console.log('Import complete');
4040
this.onChange();
41-
})
41+
});
4242

4343
},
4444
insertSheet: this.onChange,
@@ -50,12 +50,12 @@ export default class Home extends React.Component {
5050
hideRow: this.onChange,
5151
deleteColumn: this.onChange,
5252
deleteRow: this.onChange,
53-
insertColumn: (event) => {
53+
insertColumn: (_event) => {
5454
this.numColumns++;
5555
this.sheetSizeUpdated = true;
5656
this.onChange();
5757
},
58-
insertRow: (event) => {
58+
insertRow: () => {
5959
this.numRows++;
6060
this.sheetSizeUpdated = true;
6161
this.onChange();
@@ -77,23 +77,23 @@ export default class Home extends React.Component {
7777

7878
this.reloadSpreadsheetContent();
7979

80-
$(".k-item, .k-button").click((e) => {
80+
$('.k-item, .k-button').click(() => {
8181
setTimeout(() => {
8282
this.onChange();
8383
}, 10);
8484
});
8585

8686
// remove import option
87-
$(".k-upload-button").remove();
87+
$('.k-upload-button').remove();
8888
}.bind(this));
8989
}
9090

9191
getSpreadsheet() {
92-
return $("#spreadsheet").getKendoSpreadsheet();
92+
return $('#spreadsheet').getKendoSpreadsheet();
9393
}
9494

95-
onChange = (event) => {
96-
if(!this.note) {
95+
onChange = () => {
96+
if (!this.note) {
9797
return;
9898
}
9999

@@ -108,33 +108,32 @@ export default class Home extends React.Component {
108108

109109
this.componentManager.saveItemWithPresave(note, () => {
110110
note.content.preview_html = null;
111-
note.content.preview_plain = "Created with Secure Spreadsheets";
111+
note.content.preview_plain = 'Created with Secure Spreadsheets';
112112

113-
var json = this.getJSON();
114-
var content = JSON.stringify(json);
113+
let json = this.getJSON();
114+
let content = JSON.stringify(json);
115115
note.content.text = content;
116116
});
117117
}
118118

119119
getJSON() {
120-
var json = this.getSpreadsheet().toJSON();
120+
const json = this.getSpreadsheet().toJSON();
121121
json.rows = this.numRows;
122122
json.columns = this.numColumns;
123123
return json;
124124
}
125125

126-
127126
connectToBridge() {
128-
var permissions = [
127+
const permissions = [
129128
{
130-
name: "stream-context-item"
129+
name: 'stream-context-item'
131130
}
132-
]
131+
];
133132

134133
this.componentManager = new ComponentManager(permissions, () => {
135134
// on ready
136-
var platform = this.componentManager.platform;
137-
if(platform) {
135+
const platform = this.componentManager.platform;
136+
if (platform) {
138137
document.body.classList.add(platform);
139138
}
140139
});
@@ -144,8 +143,8 @@ export default class Home extends React.Component {
144143
this.componentManager.streamContextItem((note) => {
145144
this.note = note;
146145

147-
// Only update UI on non-metadata updates.
148-
if(note.isMetadataUpdate) {
146+
// Only update UI on non-metadata updates.
147+
if (note.isMetadataUpdate) {
149148
return;
150149
}
151150

@@ -154,24 +153,36 @@ export default class Home extends React.Component {
154153
}
155154

156155
reloadSpreadsheetContent() {
157-
if(!this.note) {
156+
if (!this.note) {
158157
return;
159158
}
160159

161-
var text = this.note.content.text;
162-
if(text.length == 0) {
163-
return;
160+
const text = this.note.content.text;
161+
162+
/**
163+
* If the note's text is empty, we want to save the note
164+
* so that the empty string is replaced with a JSON string
165+
* that is readable by the editor.
166+
*/
167+
if (text.length === 0) {
168+
this.saveSpreadsheet();
164169
}
165170

166-
var json = JSON.parse(text);
167-
if(json.rows) { this.numRows = json.rows; }
168-
if(json.columns) { this.numColumns = json.columns; }
171+
const json = JSON.parse(text);
172+
if (json.rows) {
173+
this.numRows = json.rows;
174+
}
175+
176+
if (json.columns) {
177+
this.numColumns = json.columns;
178+
}
169179
this.getSpreadsheet().fromJSON(json);
180+
this.getSpreadsheet().refresh();
170181
}
171182

172183
render() {
173184
return (
174185
<div></div>
175-
)
186+
);
176187
}
177188
}

dist/dist.css

Lines changed: 2 additions & 2332 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dist.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dist.js

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/dist.js.LICENSE.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ object-assign
1313
* LICENSE file in the root directory of this source tree.
1414
*/
1515

16-
/** @license React v16.13.1
16+
/** @license React v16.14.0
1717
* react-dom.production.min.js
1818
*
1919
* Copyright (c) Facebook, Inc. and its affiliates.
@@ -22,7 +22,7 @@ object-assign
2222
* LICENSE file in the root directory of this source tree.
2323
*/
2424

25-
/** @license React v16.13.1
25+
/** @license React v16.14.0
2626
* react.production.min.js
2727
*
2828
* Copyright (c) Facebook, Inc. and its affiliates.

dist/dist.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)