Skip to content

Commit 25c9387

Browse files
committed
Add Prettier and git commit hooks
- Prettier has been run on every file I think. - Before committing, Prettier will be run on all staged code files
1 parent 25d8831 commit 25c9387

22 files changed

+423
-397
lines changed

Diff for: .prettierrc.json

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"useTabs": true,
3+
"singleQuote": true,
4+
"arrowParens": "avoid",
5+
"bracketSpacing": false
6+
}

Diff for: app.js

+40-32
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,28 @@
1-
const {app, BrowserWindow, Menu, ipcMain} = require('electron')
2-
const redis = require('redis')
3-
const bluebird = require('bluebird')
4-
bluebird.promisifyAll(redis)
1+
const {app, BrowserWindow, Menu, ipcMain} = require('electron');
2+
const redis = require('redis');
3+
const bluebird = require('bluebird');
4+
bluebird.promisifyAll(redis);
55

6-
const searchHandler = require('./server/search')
7-
const getHandler = require('./server/get')
8-
const addHandler = require('./server/add')
9-
const editHandler = require('./server/edit')
10-
const deleteHandler = require('./server/delete')
6+
const searchHandler = require('./server/search');
7+
const getHandler = require('./server/get');
8+
const addHandler = require('./server/add');
9+
const editHandler = require('./server/edit');
10+
const deleteHandler = require('./server/delete');
1111

12-
let win
13-
let client
12+
let win;
13+
let client;
1414

1515
// Connect to redis and set up the main window
1616
function main() {
1717
// Connect to redis
18-
client = redis.createClient()
18+
client = redis.createClient();
1919

2020
// Create main window
21-
win = new BrowserWindow({width: 800, height: 600})
21+
win = new BrowserWindow({width: 800, height: 600});
2222
const menu = Menu.buildFromTemplate([
2323
{
2424
label: 'File',
25-
submenu: [
26-
{ label: 'Install sheet' },
27-
{ label: 'Remove sheet' }
28-
]
25+
submenu: [{label: 'Install sheet'}, {label: 'Remove sheet'}]
2926
},
3027
{
3128
label: 'View',
@@ -40,29 +37,40 @@ function main() {
4037
}
4138
]
4239
}
43-
])
44-
Menu.setApplicationMenu(menu)
45-
win.loadFile('client/index.html')
40+
]);
41+
Menu.setApplicationMenu(menu);
42+
win.loadFile('client/index.html');
4643
}
4744

4845
// Routes
49-
ipcMain.on('search', (event, query) => { timeLog(event, query, searchHandler.search) })
50-
ipcMain.on('get', (event, id) => { timeLog(event, id, getHandler.get) })
51-
ipcMain.on('add', (event, data) => { timeLog(event, data, addHandler.add) })
52-
ipcMain.on('edit:get', (event, data) => { timeLog(event, data, editHandler.get) })
53-
ipcMain.on('edit:change', (event, data) => { timeLog(event, data, editHandler.change) })
54-
ipcMain.on('delete', (event, id) => { timeLog(event, id, deleteHandler.delete) })
46+
ipcMain.on('search', (event, query) => {
47+
timeLog(event, query, searchHandler.search);
48+
});
49+
ipcMain.on('get', (event, id) => {
50+
timeLog(event, id, getHandler.get);
51+
});
52+
ipcMain.on('add', (event, data) => {
53+
timeLog(event, data, addHandler.add);
54+
});
55+
ipcMain.on('edit:get', (event, data) => {
56+
timeLog(event, data, editHandler.get);
57+
});
58+
ipcMain.on('edit:change', (event, data) => {
59+
timeLog(event, data, editHandler.change);
60+
});
61+
ipcMain.on('delete', (event, id) => {
62+
timeLog(event, id, deleteHandler.delete);
63+
});
5564

5665
// Wrap the handlers in a timer
5766
function timeLog(event, request, fn) {
58-
console.time('time')
67+
console.time('time');
5968

60-
fn(event, client, request)
69+
fn(event, client, request);
6170

62-
console.timeEnd('time')
63-
console.log()
71+
console.timeEnd('time');
72+
console.log();
6473
}
6574

6675
// Start app
67-
app.on('ready', main)
68-
76+
app.on('ready', main);

Diff for: client/AddForm.js

+27-24
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
const Vue = require('vue/dist/vue.js')
2-
const marked = require('marked')
1+
const Vue = require('vue/dist/vue.js');
2+
const marked = require('marked');
33

44
Vue.component('add-form', {
55
props: ['problemProp', 'solutionProp', 'keywordStringProp'],
@@ -8,32 +8,32 @@ Vue.component('add-form', {
88
problem: this.problemProp || '',
99
solution: this.solutionProp || '',
1010
keywordString: this.keywordStringProp || ''
11-
}
11+
};
1212
},
1313
computed: {
1414
keywords: {
1515
get: function() {
16-
let result
16+
let result;
1717

1818
// Split into keywords
19-
result = this.keywordString.trim().split(/[, ]+/g)
19+
result = this.keywordString.trim().split(/[, ]+/g);
2020

2121
// Get rid of empty keywords
2222
result = result.filter(keyword => {
23-
return keyword
24-
})
23+
return keyword;
24+
});
2525

26-
return result
26+
return result;
2727
},
2828
set: function(words) {
29-
this.keywordString = words.join(',')
29+
this.keywordString = words.join(',');
3030
}
3131
},
3232
markdownPreview: function() {
3333
if (this.solution) {
34-
return marked(this.solution)
34+
return marked(this.solution);
3535
} else {
36-
return "<p>Preview of markdown rendering of the solution</p>"
36+
return '<p>Preview of markdown rendering of the solution</p>';
3737
}
3838
}
3939
},
@@ -53,31 +53,34 @@ Vue.component('add-form', {
5353
methods: {
5454
submit: function() {
5555
if (!this.problem) {
56-
this.$emit('message', 'You gotta input a problem to add it, bro')
56+
this.$emit('message', 'You gotta input a problem to add it, bro');
5757
} else if (!this.solution) {
58-
this.$emit('message', 'It isn\'t very helpful to have a problem with no solution, now is it?')
58+
this.$emit(
59+
'message',
60+
"It isn't very helpful to have a problem with no solution, now is it?"
61+
);
5962
} else if (this.keywords.length == 0) {
60-
this.$emit('message', 'Keywords are your friend')
63+
this.$emit('message', 'Keywords are your friend');
6164
} else {
6265
this.$emit('submit', {
6366
problem: this.problem,
6467
solution: this.solution,
6568
keywords: this.keywords
66-
})
69+
});
6770
}
6871
},
6972
clear: function() {
70-
this.problem = ''
71-
this.solution = ''
72-
this.keywordString = ''
73+
this.problem = '';
74+
this.solution = '';
75+
this.keywordString = '';
7376
},
7477
set: function(snippet) {
75-
this.problem = snippet.problem || this.problem
76-
this.solution = snippet.solution || this.solution
77-
this.keywordString = snippet.keywordString || this.keywordString
78-
this.keywords = snippet.keywords || this.keywords
78+
this.problem = snippet.problem || this.problem;
79+
this.solution = snippet.solution || this.solution;
80+
this.keywordString = snippet.keywordString || this.keywordString;
81+
this.keywords = snippet.keywords || this.keywords;
7982
}
8083
}
81-
})
84+
});
8285

83-
module.exports = {}
86+
module.exports = {};

Diff for: client/AddPage.js

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
const {ipcRenderer} = require('electron')
2-
const Vue = require('vue/dist/vue.js')
1+
const {ipcRenderer} = require('electron');
2+
const Vue = require('vue/dist/vue.js');
33

4-
const addForm = require('./AddForm')
4+
const addForm = require('./AddForm');
55

6-
let vm
6+
let vm;
77

88
Vue.component('add-page', {
9-
created: function (){
10-
vm = this
9+
created: function() {
10+
vm = this;
1111
},
1212
template: `
1313
<div id="add-page">
@@ -24,20 +24,20 @@ Vue.component('add-page', {
2424
`,
2525
methods: {
2626
submit: function(data) {
27-
ipcRenderer.send('add', data)
27+
ipcRenderer.send('add', data);
2828
}
2929
}
30-
})
30+
});
3131

3232
// Server adds a snippet
3333
ipcRenderer.on('add-result', (event, result) => {
3434
if (result.status == 'success') {
35-
vm.$emit('message', 'Successfully added')
36-
vm.$refs.form.clear()
35+
vm.$emit('message', 'Successfully added');
36+
vm.$refs.form.clear();
3737
} else {
38-
console.log(result)
39-
vm.$emit('message', 'Could not add snippet')
38+
console.log(result);
39+
vm.$emit('message', 'Could not add snippet');
4040
}
41-
})
41+
});
4242

43-
module.exports = {}
43+
module.exports = {};

Diff for: client/App.js

+16-23
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
const Vue = require('vue/dist/vue')
1+
const Vue = require('vue/dist/vue');
22

3-
const messageDisplay = require('./MessageDisplay')
4-
const searchPage = require('./SearchPage')
5-
const viewPage = require('./ViewPage')
6-
const addPage = require('./AddPage')
7-
const editPage = require('./EditPage')
3+
const messageDisplay = require('./MessageDisplay');
4+
const searchPage = require('./SearchPage');
5+
const viewPage = require('./ViewPage');
6+
const addPage = require('./AddPage');
7+
const editPage = require('./EditPage');
88

99
document.addEventListener('DOMContentLoaded', () => {
1010
new Vue({
@@ -15,29 +15,29 @@ document.addEventListener('DOMContentLoaded', () => {
1515
},
1616
computed: {
1717
showSearchPage: function() {
18-
return (this.page == 'search')
18+
return this.page == 'search';
1919
},
2020
showViewPage: function() {
21-
return (this.page.slice(0,5) == 'view:')
21+
return this.page.slice(0, 5) == 'view:';
2222
},
2323
showAddPage: function() {
24-
return (this.page == 'add')
24+
return this.page == 'add';
2525
},
2626
showEditPage: function() {
27-
return (this.page.slice(0,5) == 'edit:')
27+
return this.page.slice(0, 5) == 'edit:';
2828
},
2929
viewingKey: function() {
3030
if (this.showViewPage) {
31-
return this.page.slice(5)
31+
return this.page.slice(5);
3232
} else {
33-
return null
33+
return null;
3434
}
3535
},
3636
editingKey: function() {
3737
if (this.showEditPage) {
38-
return this.page.slice(5)
38+
return this.page.slice(5);
3939
} else {
40-
return null
40+
return null;
4141
}
4242
}
4343
},
@@ -80,12 +80,5 @@ document.addEventListener('DOMContentLoaded', () => {
8080
</div>
8181
</div>
8282
`
83-
})
84-
})
85-
86-
87-
88-
89-
90-
91-
83+
});
84+
});

Diff for: client/EditPage.js

+19-19
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
1-
const {ipcRenderer} = require('electron')
2-
const Vue = require('vue/dist/vue.js')
1+
const {ipcRenderer} = require('electron');
2+
const Vue = require('vue/dist/vue.js');
33

4-
const addForm = require('./AddForm')
4+
const addForm = require('./AddForm');
55

6-
let vm
6+
let vm;
77

88
Vue.component('edit-page', {
9-
created: function (){
10-
vm = this
9+
created: function() {
10+
vm = this;
1111
},
1212
props: ['snippetKey'],
1313
watch: {
1414
snippetKey: function(key) {
1515
if (key) {
16-
ipcRenderer.send('edit:get', key)
16+
ipcRenderer.send('edit:get', key);
1717
}
1818
}
1919
},
@@ -32,29 +32,29 @@ Vue.component('edit-page', {
3232
`,
3333
methods: {
3434
back: function(event) {
35-
this.$emit('page', 'view:' + vm.snippetKey)
35+
this.$emit('page', 'view:' + vm.snippetKey);
3636
},
3737
submit: function(data) {
38-
data.key = this.snippetKey
39-
ipcRenderer.send('edit:change', data)
38+
data.key = this.snippetKey;
39+
ipcRenderer.send('edit:change', data);
4040
}
4141
}
42-
})
42+
});
4343

4444
// Get the snippet to edit
4545
ipcRenderer.on('edit:get-result', (event, snippet) => {
46-
vm.$refs.form.set(snippet)
47-
})
46+
vm.$refs.form.set(snippet);
47+
});
4848

4949
// Server adds a snippet
5050
ipcRenderer.on('edit:change-result', (event, result) => {
5151
if (result.status == 'success') {
52-
vm.$emit('message', 'Successfully edited')
53-
vm.$emit('page', 'view:' + vm.snippetKey)
52+
vm.$emit('message', 'Successfully edited');
53+
vm.$emit('page', 'view:' + vm.snippetKey);
5454
} else {
55-
console.log(result)
56-
vm.$emit('message', 'Could not edit snippet')
55+
console.log(result);
56+
vm.$emit('message', 'Could not edit snippet');
5757
}
58-
})
58+
});
5959

60-
module.exports = {}
60+
module.exports = {};

0 commit comments

Comments
 (0)