mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-13 09:46:22 +00:00
fixed eslint error
This commit is contained in:
@@ -1,13 +1,11 @@
|
||||
const { remote } = require('electron')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import crypto from 'crypto'
|
||||
import consts from 'browser/lib/consts'
|
||||
|
||||
function createSnippet(snippets) {
|
||||
function createSnippet (snippets) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const newSnippet = {
|
||||
id: crypto.randomBytes(16).toString('hex'),
|
||||
const newSnippet = {
|
||||
id: crypto.randomBytes(16).toString('hex'),
|
||||
name: 'Unnamed snippet',
|
||||
prefix: [],
|
||||
content: ''
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
const { remote } = require('electron')
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import consts from 'browser/lib/consts'
|
||||
|
||||
function deleteSnippet (snippets, snippetId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
for(let i = 0; i < snippets.length; i++) {
|
||||
for (let i = 0; i < snippets.length; i++) {
|
||||
if (snippets[i].id === snippetId) {
|
||||
snippets.splice(i, 1);
|
||||
snippets.splice(i, 1)
|
||||
fs.writeFile(consts.SNIPPET_FILE, JSON.stringify(snippets, null, 4), (err) => {
|
||||
if (err) reject(err)
|
||||
resolve(snippets)
|
||||
})
|
||||
}
|
||||
}
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
module.exports = deleteSnippet
|
||||
module.exports = deleteSnippet
|
||||
|
||||
@@ -3,10 +3,10 @@ import consts from 'browser/lib/consts'
|
||||
|
||||
function updateSnippet (snippet) {
|
||||
return new Promise((resolve, reject) => {
|
||||
let snippets = JSON.parse(fs.readFileSync(consts.SNIPPET_FILE, 'utf-8'))
|
||||
const snippets = JSON.parse(fs.readFileSync(consts.SNIPPET_FILE, 'utf-8'))
|
||||
|
||||
for (let i = 0; i < snippets.length; i++) {
|
||||
let currentSnippet = snippets[i]
|
||||
const currentSnippet = snippets[i]
|
||||
|
||||
if (currentSnippet.id === snippet.id) {
|
||||
if (
|
||||
@@ -20,7 +20,6 @@ function updateSnippet (snippet) {
|
||||
currentSnippet.name = snippet.name
|
||||
currentSnippet.prefix = snippet.prefix
|
||||
currentSnippet.content = snippet.content
|
||||
|
||||
fs.writeFile(consts.SNIPPET_FILE, JSON.stringify(snippets, null, 4), (err) => {
|
||||
if (err) reject(err)
|
||||
resolve(snippets)
|
||||
|
||||
@@ -2,12 +2,9 @@ import CodeMirror from 'codemirror'
|
||||
import React from 'react'
|
||||
import _ from 'lodash'
|
||||
import fs from 'fs'
|
||||
import path from 'path'
|
||||
import consts from 'browser/lib/consts'
|
||||
import dataApi from 'browser/main/lib/dataApi'
|
||||
|
||||
const { remote } = require('electron')
|
||||
|
||||
const defaultEditorFontFamily = ['Monaco', 'Menlo', 'Ubuntu Mono', 'Consolas', 'source-code-pro', 'monospace']
|
||||
const buildCMRulers = (rulers, enableRulers) =>
|
||||
enableRulers ? rulers.map(ruler => ({ column: ruler })) : []
|
||||
@@ -48,7 +45,7 @@ export default class SnippetEditor extends React.Component {
|
||||
}
|
||||
|
||||
saveSnippet () {
|
||||
dataApi.updateSnippet(this.snippet).catch((err) => {throw err})
|
||||
dataApi.updateSnippet(this.snippet).catch((err) => { throw err })
|
||||
}
|
||||
|
||||
loadSnippet (snippetId) {
|
||||
|
||||
@@ -4,7 +4,6 @@ import styles from './SnippetTab.styl'
|
||||
import fs from 'fs'
|
||||
import SnippetEditor from './SnippetEditor'
|
||||
import i18n from 'browser/lib/i18n'
|
||||
import path from 'path'
|
||||
import dataApi from 'browser/main/lib/dataApi'
|
||||
import consts from 'browser/lib/consts'
|
||||
|
||||
@@ -29,13 +28,13 @@ class SnippetTab extends React.Component {
|
||||
}
|
||||
|
||||
handleSnippetClick (snippet) {
|
||||
let currentSnippet = Object.assign({}, snippet)
|
||||
const currentSnippet = Object.assign({}, snippet)
|
||||
currentSnippet.prefix = currentSnippet.prefix.join(', ')
|
||||
this.setState({currentSnippet})
|
||||
}
|
||||
|
||||
handleSnippetContextMenu(snippet) {
|
||||
let menu = new Menu()
|
||||
handleSnippetContextMenu (snippet) {
|
||||
const menu = new Menu()
|
||||
menu.append(new MenuItem({
|
||||
label: 'Delete',
|
||||
click: () => {
|
||||
@@ -45,21 +44,21 @@ class SnippetTab extends React.Component {
|
||||
menu.popup()
|
||||
}
|
||||
|
||||
deleteSnippet(id) {
|
||||
deleteSnippet (id) {
|
||||
dataApi.deleteSnippet(this.snippets, id).then((snippets) => {
|
||||
this.snippets = snippets
|
||||
this.setState(this.snippets)
|
||||
}).catch(err => {throw err})
|
||||
}).catch(err => { throw err })
|
||||
}
|
||||
|
||||
createSnippet() {
|
||||
createSnippet () {
|
||||
dataApi.createSnippet(this.snippets).then((snippets) => {
|
||||
this.snippets = snippets
|
||||
this.setState(this.snippets)
|
||||
// scroll to end of list when added new snippet
|
||||
let snippetList = document.getElementById("snippets")
|
||||
const snippetList = document.getElementById('snippets')
|
||||
snippetList.scrollTop = snippetList.scrollHeight
|
||||
}).catch(err => {throw err})
|
||||
}).catch(err => { throw err })
|
||||
}
|
||||
|
||||
renderSnippetList () {
|
||||
@@ -72,8 +71,7 @@ class SnippetTab extends React.Component {
|
||||
styleName='snippet-item'
|
||||
key={snippet.id}
|
||||
onContextMenu={() => this.handleSnippetContextMenu(snippet)}
|
||||
onClick={() => {
|
||||
this.handleSnippetClick(snippet)}}>
|
||||
onClick={() => this.handleSnippetClick(snippet)}>
|
||||
{snippet.name}
|
||||
</li>
|
||||
))
|
||||
|
||||
Reference in New Issue
Block a user