Skip to content

Commit 635b7b4

Browse files
committed
Fix linting error
1 parent ef235b0 commit 635b7b4

File tree

4 files changed

+68
-133
lines changed

4 files changed

+68
-133
lines changed

src/CodeSnippetDisplay.tsx

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -399,23 +399,24 @@ export class CodeSnippetDisplay extends React.Component<
399399
new_element.onblur = async (): Promise<void> => {
400400
if (target.innerHTML !== new_element.value) {
401401
const newName = new_element.value;
402-
this.props.codeSnippetManager.renameSnippet(oldName, newName).then(async (res:boolean) => {
403-
if (res){
404-
console.log(target);
405-
console.log(new_element);
406-
target.innerHTML = new_element.value;
407-
}
408-
else{
409-
new_element.replaceWith(target);
410-
411-
await showDialog({
412-
title: 'Duplicate Name of Code Snippet',
413-
body: <p> {`"${newName}" already exists.`} </p>,
414-
buttons: [Dialog.okButton({ label: 'Dismiss' })]
415-
});
416-
return;
417-
}
418-
});
402+
this.props.codeSnippetManager
403+
.renameSnippet(oldName, newName)
404+
.then(async (res: boolean) => {
405+
if (res) {
406+
console.log(target);
407+
console.log(new_element);
408+
target.innerHTML = new_element.value;
409+
} else {
410+
new_element.replaceWith(target);
411+
412+
await showDialog({
413+
title: 'Duplicate Name of Code Snippet',
414+
body: <p> {`"${newName}" already exists.`} </p>,
415+
buttons: [Dialog.okButton({ label: 'Dismiss' })]
416+
});
417+
return;
418+
}
419+
});
419420
}
420421
new_element.replaceWith(target);
421422
};
@@ -1369,24 +1370,25 @@ export class CodeSnippetDisplay extends React.Component<
13691370
editor.dispose();
13701371
}
13711372
// deleting snippets when there is one snippet active
1372-
this.props.codeSnippetManager.deleteSnippet(codeSnippet.id).then((result: boolean) => {
1373-
if (result){
1374-
this.props.updateCodeSnippetWidget();
1375-
}
1376-
else{
1377-
console.log('Error in deleting the snippet');
1378-
return;
1379-
}
1373+
this.props.codeSnippetManager
1374+
.deleteSnippet(codeSnippet.id)
1375+
.then((result: boolean) => {
1376+
if (result) {
1377+
this.props.updateCodeSnippetWidget();
1378+
} else {
1379+
console.log('Error in deleting the snippet');
1380+
return;
1381+
}
13801382

1381-
// active tags after delete
1382-
// const activeTags = this.getActiveTags();
1383+
// active tags after delete
1384+
// const activeTags = this.getActiveTags();
13831385

1384-
// filterTags: only the tags that are still being used
1385-
// this.setState(state => ({
1386-
// codeSnippets: snippets,
1387-
// filterTags: state.filterTags.filter(tag => activeTags.includes(tag))
1388-
// }), () => console.log(this.state));
1389-
});
1386+
// filterTags: only the tags that are still being used
1387+
// this.setState(state => ({
1388+
// codeSnippets: snippets,
1389+
// filterTags: state.filterTags.filter(tag => activeTags.includes(tag))
1390+
// }), () => console.log(this.state));
1391+
});
13901392
// this.props._codeSnippetWidgetModel.deleteSnippet(codeSnippet.id);
13911393
// this.props._codeSnippetWidgetModel.reorderSnippet();
13921394
// this.props._codeSnippetWidgetModel.updateSnippetContents();

src/CodeSnippetEditor.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,12 +416,11 @@ export class CodeSnippetEditor extends ReactWidget {
416416
id: this._codeSnippetEditorMetaData.id,
417417
tags: this._codeSnippetEditorMetaData.selectedTags
418418
};
419-
420-
if (newName !== oldName){
421-
try{
419+
420+
if (newName !== oldName) {
421+
try {
422422
this.contentsService.duplicateNameExists(newName);
423-
}
424-
catch(e) {
423+
} catch (e) {
425424
await showDialog({
426425
title: e.message,
427426
body: <p> {`"${newName}" already exists.`} </p>,
@@ -435,25 +434,27 @@ export class CodeSnippetEditor extends ReactWidget {
435434
this.oldCodeSnippetName = this._codeSnippetEditorMetaData.name;
436435

437436
// add new snippet
438-
if(this._codeSnippetEditorMetaData.fromScratch){
437+
if (this._codeSnippetEditorMetaData.fromScratch) {
439438
this.contentsService.addSnippet(newSnippet).then((res: boolean) => {
440-
if (!res){
441-
console.log("Error in adding snippet");
439+
if (!res) {
440+
console.log('Error in adding snippet');
442441
return false;
443442
}
444443
});
445444
}
446445
// modify existing snippet
447-
else{
446+
else {
448447
console.log('modify existing snippet');
449448
console.log(oldName);
450449
console.log(newSnippet);
451-
this.contentsService.modifyExistingSnippet(oldName, newSnippet).then((res: boolean) => {
452-
if (!res){
453-
console.log("Error in modifying snippet");
454-
return false;
455-
}
456-
});
450+
this.contentsService
451+
.modifyExistingSnippet(oldName, newSnippet)
452+
.then((res: boolean) => {
453+
if (!res) {
454+
console.log('Error in modifying snippet');
455+
return false;
456+
}
457+
});
457458
}
458459

459460
this.saved = true;

src/CodeSnippetService.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class CodeSnippetService {
5252
console.log(this.codeSnippetList);
5353
}
5454

55-
private convertToICodeSnippetList(snippets: JSONArray) {
55+
private convertToICodeSnippetList(snippets: JSONArray): ICodeSnippet[] {
5656
const snippetList: ICodeSnippet[] = [];
5757

5858
snippets.forEach(snippet => {
@@ -77,7 +77,7 @@ export class CodeSnippetService {
7777
}
7878

7979
getSnippet(snippetName: string): ICodeSnippet[] {
80-
return this.codeSnippetList.filter(snippet => snippet.name == snippetName);
80+
return this.codeSnippetList.filter(snippet => snippet.name === snippetName);
8181
}
8282

8383
// isValidSnippet(): boolean {
@@ -120,7 +120,7 @@ export class CodeSnippetService {
120120
console.log('error in codeSnippetService');
121121
}
122122

123-
if (id == numSnippets - 1) {
123+
if (id === numSnippets - 1) {
124124
this.codeSnippetList.pop();
125125
} else {
126126
this.codeSnippetList.splice(id, 1);
@@ -176,7 +176,7 @@ export class CodeSnippetService {
176176
newSnippet: ICodeSnippet
177177
): Promise<boolean> {
178178
console.log(this.codeSnippetList);
179-
for (let snippet of this.codeSnippetList) {
179+
for (const snippet of this.codeSnippetList) {
180180
if (snippet.name === oldName) {
181181
this.codeSnippetList.splice(snippet.id, 1, newSnippet);
182182
break;

src/CodeSnippetWidget.tsx

Lines changed: 13 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,7 @@ import { Signal } from '@lumino/signaling';
2525
import { IDragEvent } from '@lumino/dragdrop';
2626
import { MimeData } from '@lumino/coreutils';
2727

28-
import {
29-
CodeSnippetService,
30-
ICodeSnippet
31-
} from './CodeSnippetService';
28+
import { CodeSnippetService, ICodeSnippet } from './CodeSnippetService';
3229
// import { CodeSnippetWidgetModel } from './CodeSnippetWidgetModel';
3330
import { CodeSnippetDisplay } from './CodeSnippetDisplay';
3431
import { CodeSnippetInputDialog } from './CodeSnippetInputDialog';
@@ -86,67 +83,6 @@ export class CodeSnippetWidget extends ReactWidget {
8683
this.node.setAttribute('data-lm-dragscroll', 'true');
8784
}
8885

89-
// Request code snippets from contents service
90-
// async fetchData(): Promise<ICodeSnippet[]> {
91-
// // const fileModels: Contents.IModel[] = [];
92-
// // const paths: string[] = [];
93-
94-
// const codeSnippets = this.codeSnippetManager.snippets;
95-
// return codeSnippets;
96-
97-
// // Clear the current snippets
98-
// this._codeSnippetWidgetModel.clearSnippets();
99-
100-
// await this.codeSnippetManager
101-
// .getData('snippets', 'directory')
102-
// .then(model => {
103-
// fileModels.push(...model.content);
104-
// });
105-
106-
// fileModels.forEach(fileModel => paths.push(fileModel.path));
107-
108-
// let newSnippet: ICodeSnippet = {
109-
// name: '',
110-
// description: '',
111-
// language: '',
112-
// code: [],
113-
// id: -1
114-
// };
115-
116-
// const codeSnippetList: ICodeSnippet[] = [];
117-
// for (let i = 0; i < paths.length; i++) {
118-
// await this.codeSnippetManager.getData(paths[i], 'file').then(model => {
119-
// const codeSnippet: ICodeSnippet = JSON.parse(model.content);
120-
121-
// // append a new snippet created from scratch to the end
122-
// if (codeSnippet.id === -1) {
123-
// codeSnippet.id = paths.length - 1;
124-
// newSnippet = codeSnippet;
125-
// }
126-
127-
// codeSnippetList.push(codeSnippet);
128-
// });
129-
// }
130-
131-
// // new list of snippets
132-
// this._codeSnippetWidgetModel.snippets = codeSnippetList;
133-
134-
// // sort codeSnippetList by ID
135-
// this._codeSnippetWidgetModel.sortSnippets();
136-
137-
// // update the content of the new snippet
138-
// if (newSnippet.name !== '') {
139-
// this.codeSnippetManager.save('snippets/' + newSnippet.name + '.json', {
140-
// type: 'file',
141-
// format: 'text',
142-
// content: JSON.stringify(newSnippet)
143-
// });
144-
// }
145-
146-
// this._codeSnippets = this._codeSnippetWidgetModel.snippets;
147-
// return this._codeSnippetWidgetModel.snippets;
148-
// }
149-
15086
updateCodeSnippetWidget(): void {
15187
console.log('updating code snippets');
15288
const newSnippets = this.codeSnippetManager.snippets;
@@ -158,7 +94,7 @@ export class CodeSnippetWidget extends ReactWidget {
15894
}
15995

16096
onAfterShow(msg: Message): void {
161-
console.log("onAfterShow");
97+
console.log('onAfterShow');
16298
this.updateCodeSnippetWidget();
16399
}
164100

@@ -344,8 +280,7 @@ export class CodeSnippetWidget extends ReactWidget {
344280
let idx;
345281
if (snippet !== undefined) {
346282
idx = parseInt(snippet.id);
347-
}
348-
else{
283+
} else {
349284
idx = this.codeSnippetManager.snippets.length;
350285
}
351286

@@ -366,11 +301,6 @@ export class CodeSnippetWidget extends ReactWidget {
366301
event.dropAction = 'move';
367302
if (event.mimeData.hasData('snippet/id')) {
368303
const srcIdx = event.mimeData.getData('snippet/id') as number;
369-
// if (idx === -1) {
370-
// this.fetchData().then(codeSnippets => {
371-
// idx = codeSnippets.length;
372-
// });
373-
// }
374304
this.moveCodeSnippet(srcIdx, idx);
375305
}
376306
} else {
@@ -381,8 +311,8 @@ export class CodeSnippetWidget extends ReactWidget {
381311

382312
// Reorder snippet just to make sure id's are in order.
383313
this.codeSnippetManager.orderSnippets().then((res: boolean) => {
384-
if(!res){
385-
console.log("Error in ordering snippets");
314+
if (!res) {
315+
console.log('Error in ordering snippets');
386316
return;
387317
}
388318
});
@@ -391,12 +321,14 @@ export class CodeSnippetWidget extends ReactWidget {
391321
// move code snippet within code snippet explorer
392322
private moveCodeSnippet(srcIdx: number, targetIdx: number): void {
393323
console.log('move snippet');
394-
this.codeSnippetManager.moveSnippet(srcIdx, targetIdx).then((res: boolean) => {
395-
if(!res) {
396-
console.log("Error in moving snippet");
397-
return;
398-
}
399-
});
324+
this.codeSnippetManager
325+
.moveSnippet(srcIdx, targetIdx)
326+
.then((res: boolean) => {
327+
if (!res) {
328+
console.log('Error in moving snippet');
329+
return;
330+
}
331+
});
400332
const newSnippets = this.codeSnippetManager.snippets;
401333
console.log(newSnippets);
402334
this.renderCodeSnippetsSignal.emit(newSnippets);

0 commit comments

Comments
 (0)