Skip to content

Commit 37eee26

Browse files
committed
fix linting & routing
1 parent 18aae8c commit 37eee26

File tree

3 files changed

+27
-31
lines changed

3 files changed

+27
-31
lines changed

browser/main/lib/dataApi/createNoteFromUrl.js

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,27 +3,27 @@ const https = require('https')
33
const TurndownService = require('turndown')
44
const createNote = require('./createNote')
55

6-
import { hashHistory } from 'react-router'
6+
import { push } from 'connected-react-router'
77
import ee from 'browser/main/lib/eventEmitter'
88

9-
function validateUrl(str) {
10-
if(/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(str)) {
11-
return true;
9+
function validateUrl (str) {
10+
if (/^(?:(?:(?:https?|ftp):)?\/\/)(?:\S+(?::\S*)?@)?(?:(?!(?:10|127)(?:\.\d{1,3}){3})(?!(?:169\.254|192\.168)(?:\.\d{1,3}){2})(?!172\.(?:1[6-9]|2\d|3[0-1])(?:\.\d{1,3}){2})(?:[1-9]\d?|1\d\d|2[01]\d|22[0-3])(?:\.(?:1?\d{1,2}|2[0-4]\d|25[0-5])){2}(?:\.(?:[1-9]\d?|1\d\d|2[0-4]\d|25[0-4]))|(?:(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)(?:\.(?:[a-z\u00a1-\uffff0-9]-*)*[a-z\u00a1-\uffff0-9]+)*(?:\.(?:[a-z\u00a1-\uffff]{2,})).?)(?::\d{2,5})?(?:[/?#]\S*)?$/i.test(str)) {
11+
return true
1212
} else {
13-
return false;
13+
return false
1414
}
1515
}
1616

1717
function createNoteFromUrl (url, storage, folder, dispatch = null, location = null) {
1818
return new Promise((resolve, reject) => {
19-
let td = new TurndownService();
19+
let td = new TurndownService()
2020

21-
if(!validateUrl(url)) {
22-
reject({result: false, error: "Please check your URL is in correct format. (Example, https://www.google.com)"})
21+
if (!validateUrl(url)) {
22+
reject({result: false, error: 'Please check your URL is in correct format. (Example, https://www.google.com)'})
2323
}
2424

2525
let request = http
26-
if(url.includes('https')) {
26+
if (url.includes('https')) {
2727
request = https
2828
}
2929

@@ -39,7 +39,7 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
3939
html.innerHTML = data
4040

4141
let scripts = html.getElementsByTagName('script')
42-
for(let i = scripts.length - 1; i >= 0; i--) {
42+
for (let i = scripts.length - 1; i >= 0; i--) {
4343
scripts[i].parentNode.removeChild(scripts[i])
4444
}
4545

@@ -48,7 +48,7 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
4848

4949
html.innerHTML = ''
5050

51-
if(dispatch !== null) {
51+
if (dispatch !== null) {
5252
createNote(storage, {
5353
type: 'MARKDOWN_NOTE',
5454
folder: folder,
@@ -61,10 +61,10 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
6161
type: 'UPDATE_NOTE',
6262
note: note
6363
})
64-
hashHistory.push({
64+
dispatch(push({
6565
pathname: location.pathname,
6666
query: {key: noteHash}
67-
})
67+
}))
6868
ee.emit('list:jump', noteHash)
6969
ee.emit('detail:focus')
7070
resolve({result: true, error: null})
@@ -86,9 +86,8 @@ function createNoteFromUrl (url, storage, folder, dispatch = null, location = nu
8686
console.error('error in parsing URL', e)
8787
reject({result: false, error: e})
8888
})
89-
req.end();
89+
req.end()
9090
})
91-
9291
}
9392

94-
module.exports = createNoteFromUrl;
93+
module.exports = createNoteFromUrl

browser/main/modals/CreateMarkdownFromURLModal.js

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,7 @@ import React from 'react'
33
import CSSModules from 'browser/lib/CSSModules'
44
import styles from './CreateMarkdownFromURLModal.styl'
55
import dataApi from 'browser/main/lib/dataApi'
6-
import store from 'browser/main/store'
7-
import consts from 'browser/lib/consts'
86
import ModalEscButton from 'browser/components/ModalEscButton'
9-
import AwsMobileAnalyticsConfig from 'browser/main/lib/AwsMobileAnalyticsConfig'
107
import i18n from 'browser/lib/i18n'
118

129
class CreateMarkdownFromURLModal extends React.Component {
@@ -18,7 +15,6 @@ class CreateMarkdownFromURLModal extends React.Component {
1815
showerror: false,
1916
errormessage: ''
2017
}
21-
2218
}
2319

2420
componentDidMount () {
@@ -57,7 +53,7 @@ class CreateMarkdownFromURLModal extends React.Component {
5753
this.setState({
5854
showerror: true,
5955
errormessage: message
60-
});
56+
})
6157
}
6258

6359
hideError () {
@@ -68,14 +64,14 @@ class CreateMarkdownFromURLModal extends React.Component {
6864
}
6965

7066
confirm () {
71-
this.hideError()
72-
const { storage, folder, dispatch, location } = this.props
67+
this.hideError()
68+
const { storage, folder, dispatch, location } = this.props
7369

74-
let note = dataApi.createNoteFromUrl(this.state.name, storage, folder, dispatch, location).then((result) => {
75-
this.props.close()
76-
}).catch((result) => {
77-
this.showError(result.error);
78-
});
70+
dataApi.createNoteFromUrl(this.state.name, storage, folder, dispatch, location).then((result) => {
71+
this.props.close()
72+
}).catch((result) => {
73+
this.showError(result.error)
74+
})
7975
}
8076

8177
render () {
@@ -103,7 +99,7 @@ class CreateMarkdownFromURLModal extends React.Component {
10399
>
104100
{i18n.__('Import')}
105101
</button>
106-
<div className="error" styleName="error">{this.state.errormessage}</div>
102+
<div className='error' styleName='error'>{this.state.errormessage}</div>
107103
</div>
108104
</div>
109105
)

tests/dataApi/createNoteFromUrl-test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ test.serial('Create a note from URL', (t) => {
2727

2828
const url = 'https://shapeshed.com/writing-cross-platform-node/'
2929

30-
3130
return Promise.resolve()
3231
.then(function doTest () {
3332
return Promise.all([
@@ -37,10 +36,12 @@ test.serial('Create a note from URL', (t) => {
3736
.then(function assert (data) {
3837
const data1 = data[0]
3938

40-
console.log("STORM LOOK HERE", data1)
39+
console.log('STORM LOOK HERE', data1)
4140

4241
t.is(storageKey, data1.storage)
4342
const jsonData2 = CSON.readFileSync(path.join(storagePath, 'notes', data1.key + '.cson'))
43+
44+
// <<<<<< fix me - input2 & data not defined
4445
t.is(input2.content, data2.content)
4546
t.is(input2.content, jsonData2.content)
4647
t.is(input2.tags.length, data2.tags.length)

0 commit comments

Comments
 (0)