Skip to content

Commit d18fefa

Browse files
committed
first pass at all files
1 parent 04a41e0 commit d18fefa

8 files changed

+376
-369
lines changed

Diff for: src/client/AddForm.vue

+94-93
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,108 @@
1-
const Vue = require('vue/dist/vue.js')
2-
const marked = require('marked')
1+
<template>
2+
<div class="add-form form-horizontal">
33

4-
Vue.component('add-form', {
5-
props: ['problemProp', 'solutionProp', 'keywordStringProp'],
6-
data: function() {
7-
return {
8-
problem: this.problemProp || '',
9-
solution: this.solutionProp || '',
10-
keywordString: this.keywordStringProp || ''
11-
}
12-
},
13-
computed: {
14-
keywords: {
15-
get: function() {
16-
let result
17-
18-
// Split into keywords
19-
result = this.keywordString.trim().split(/[, ]+/g)
20-
21-
// Get rid of empty keywords
22-
result = result.filter(keyword => {
23-
return keyword
24-
})
25-
26-
return result
27-
},
28-
set: function(words) {
29-
this.keywordString = words.join(',')
30-
}
31-
},
32-
markdownPreview: function() {
33-
if (this.solution) {
34-
return marked(this.solution)
35-
} else {
36-
return '<p>Preview of markdown rendering of the solution</p>'
37-
}
38-
}
39-
},
40-
template: `
41-
<div class="add-form form-horizontal">
42-
43-
<div class="form-group">
44-
<label for="problem" class="col-sm-2">Problem:</label>
45-
<div class="col-sm-10">
46-
<input class="form-control" id="problem" type="text" v-model="problem">
47-
</div>
4+
<div class="form-group">
5+
<label for="problem" class="col-sm-2">Problem:</label>
6+
<div class="col-sm-10">
7+
<input class="form-control" id="problem" type="text" v-model="problem">
488
</div>
9+
</div>
4910

50-
<div class="form-group">
51-
<label for="solution" class="col-sm-2">Solution:</label>
52-
<div class="col-sm-10">
53-
<textarea class="form-control" id="solution" rows=10 cols=40 v-model="solution"></textarea>
54-
</div>
11+
<div class="form-group">
12+
<label for="solution" class="col-sm-2">Solution:</label>
13+
<div class="col-sm-10">
14+
<textarea class="form-control" id="solution" rows=10 cols=40 v-model="solution"></textarea>
5515
</div>
16+
</div>
5617

57-
<div class="form-group">
58-
<label for="keywords" class="col-sm-2">Keywords:</label>
59-
<div class="col-sm-10">
60-
<input class="form-control" id="keywords" type="text" v-model="keywordString"> {{ keywords }}
61-
</div>
18+
<div class="form-group">
19+
<label for="keywords" class="col-sm-2">Keywords:</label>
20+
<div class="col-sm-10">
21+
<input class="form-control" id="keywords" type="text" v-model="keywordString"> {{ keywords }}
6222
</div>
23+
</div>
6324

64-
<div class="form-group">
65-
<div class="col-sm-offset-2 col-sm-10">
66-
<button class="btn btn-primary" v-on:click="submit">Submit</button>
67-
</div>
25+
<div class="form-group">
26+
<div class="col-sm-offset-2 col-sm-10">
27+
<button class="btn btn-primary" v-on:click="submit">Submit</button>
6828
</div>
69-
70-
<hr />
71-
<div class="md" v-html="markdownPreview"></div>
7229
</div>
73-
`,
74-
methods: {
75-
submit: function() {
76-
if (!this.problem) {
77-
this.$emit('message', 'You gotta input a problem to add it, bro')
78-
} else if (!this.solution) {
79-
this.$emit(
80-
'message',
81-
"It isn't very helpful to have a problem with no solution, now is it?"
82-
)
83-
} else if (this.keywords.length == 0) {
84-
this.$emit('message', 'Keywords are your friend')
85-
} else {
86-
this.$emit('submit', {
87-
problem: this.problem,
88-
solution: this.solution,
89-
keywords: this.keywords
90-
})
30+
31+
<hr />
32+
33+
<div class="md" v-html="markdownPreview"></div>
34+
</div>
35+
</template>
36+
37+
<script>
38+
const marked = require('marked')
39+
40+
module.exports = {
41+
props: ['problemProp', 'solutionProp', 'keywordStringProp'],
42+
data: function() {
43+
return {
44+
problem: this.problemProp || '',
45+
solution: this.solutionProp || '',
46+
keywordString: this.keywordStringProp || ''
9147
}
9248
},
93-
clear: function() {
94-
this.problem = ''
95-
this.solution = ''
96-
this.keywordString = ''
49+
computed: {
50+
keywords: {
51+
get: function() {
52+
let result
53+
54+
// Split into keywords
55+
result = this.keywordString.trim().split(/[, ]+/g)
56+
57+
// Get rid of empty keywords
58+
result = result.filter(keyword => {
59+
return keyword
60+
})
61+
62+
return result
63+
},
64+
set: function(words) {
65+
this.keywordString = words.join(',')
66+
}
67+
},
68+
markdownPreview: function() {
69+
if (this.solution) {
70+
return marked(this.solution)
71+
} else {
72+
return '<p>Preview of markdown rendering of the solution</p>'
73+
}
74+
}
9775
},
98-
set: function(snippet) {
99-
this.problem = snippet.problem || this.problem
100-
this.solution = snippet.solution || this.solution
101-
this.keywordString = snippet.keywordString || this.keywordString
102-
this.keywords = snippet.keywords || this.keywords
76+
methods: {
77+
submit: function() {
78+
if (!this.problem) {
79+
this.$emit('message', 'You gotta input a problem to add it, bro')
80+
} else if (!this.solution) {
81+
this.$emit(
82+
'message',
83+
"It isn't very helpful to have a problem with no solution, now is it?"
84+
)
85+
} else if (this.keywords.length == 0) {
86+
this.$emit('message', 'Keywords are your friend')
87+
} else {
88+
this.$emit('submit', {
89+
problem: this.problem,
90+
solution: this.solution,
91+
keywords: this.keywords
92+
})
93+
}
94+
},
95+
clear: function() {
96+
this.problem = ''
97+
this.solution = ''
98+
this.keywordString = ''
99+
},
100+
set: function(snippet) {
101+
this.problem = snippet.problem || this.problem
102+
this.solution = snippet.solution || this.solution
103+
this.keywordString = snippet.keywordString || this.keywordString
104+
this.keywords = snippet.keywords || this.keywords
105+
}
103106
}
104107
}
105-
})
106-
107-
module.exports = {}
108+
</script>

Diff for: src/client/AddPage.vue

+36-37
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,42 @@
1-
const {ipcRenderer} = require('electron')
2-
const Vue = require('vue/dist/vue.js')
1+
<template>
2+
<div id="add-page">
3+
<div id="add-links">
4+
<p><a href="#" v-on:click="$emit('page', 'search')">Back to search results</a></p>
5+
</div>
36

4-
const addForm = require('./AddForm')
7+
<AddForm
8+
v-on:message="$emit('message', $event)"
9+
v-on:submit="submit"
10+
ref="form"
11+
></AddForm>
12+
</div>
13+
</template>
514

6-
let vm
15+
<script>
16+
const {ipcRenderer} = require('electron')
17+
const AddForm = require('./AddForm')
718
8-
Vue.component('add-page', {
9-
created: function() {
10-
vm = this
11-
},
12-
template: `
13-
<div id="add-page">
14-
<div id="add-links">
15-
<p><a href="#" v-on:click="$emit('page', 'search')">Back to search results</a></p>
16-
</div>
19+
let vm
1720
18-
<add-form
19-
v-on:message="$emit('message', $event)"
20-
v-on:submit="submit"
21-
ref="form"
22-
></add-form>
23-
</div>
24-
`,
25-
methods: {
26-
submit: function(data) {
27-
ipcRenderer.send('add', data)
21+
// Server adds a snippet
22+
ipcRenderer.on('add-result', (event, result) => {
23+
if (result.status == 'success') {
24+
vm.$emit('message', 'Successfully added')
25+
vm.$refs.form.clear()
26+
} else {
27+
console.log(result)
28+
vm.$emit('message', 'Could not add snippet')
2829
}
29-
}
30-
})
30+
})
3131
32-
// Server adds a snippet
33-
ipcRenderer.on('add-result', (event, result) => {
34-
if (result.status == 'success') {
35-
vm.$emit('message', 'Successfully added')
36-
vm.$refs.form.clear()
37-
} else {
38-
console.log(result)
39-
vm.$emit('message', 'Could not add snippet')
40-
}
41-
})
42-
43-
module.exports = {}
32+
export.modules = {
33+
created: function() {
34+
vm = this
35+
},
36+
methods: {
37+
submit: function(data) {
38+
ipcRenderer.send('add', data)
39+
}
40+
}
41+
})
42+
</script>

Diff for: src/client/App.vue

+21-14
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,66 @@
11
<template>
22
<div class="m-3">
3-
<message-display
3+
<MessageDisplay
44
:message="message"
5-
></message-display>
5+
></MessageDisplay>
66

77
<hr />
88

99
<div id="content">
10-
<search-page
10+
<SearchPage
1111
v-show="showSearchPage"
1212
v-on:page="page = $event"
1313
v-on:message="message = $event"
14-
></search-page>
14+
></SearchPage>
1515

16-
<view-page
16+
<ViewPage
1717
v-show="showViewPage"
1818
v-on:page="page = $event"
1919
v-on:message="message = $event"
2020
:snippetID="viewingID"
21-
></view-page>
21+
></ViewPage>
2222

23-
<add-page
23+
<AddPage
2424
v-show="showAddPage"
2525
v-on:page="page = $event"
2626
v-on:message="message = $event"
27-
></add-page>
27+
></AddPage>
2828

29-
<edit-page
29+
<EditPage
3030
v-show="showEditPage"
3131
v-on:page="page = $event"
3232
v-on:message="message = $event"
3333
:snippetID="editingID"
34-
></edit-page>
34+
></EditPage>
3535

36-
<dropped-page
36+
<DroppedPage
3737
v-show="showDroppedPage"
3838
v-on:page="page = $event"
3939
v-on:message="message = $event"
4040
:visible="showDroppedPage"
41-
></dropped-page>
41+
></DroppedPage>
4242

43-
<view-page
43+
<ViewPage
4444
v-show="showDroppedViewPage"
4545
v-on:page="page = $event"
4646
v-on:message="message = $event"
4747

4848
:snippetID="droppedID"
4949
:dropped=true
50-
></view-page>
50+
></ViewPage>
5151
</div>
5252
</div>
5353
</template>
5454

5555
<script>
5656
const {ipcRenderer} = require('electron')
57+
const MessageDisplay = require('./MessageDisplay')
58+
const SearchPage = require('./SearchPage')
59+
const ViewPage = require('./ViewPage')
60+
const AddPage = require('./AddPage')
61+
const EditPage = require('./EditPage')
62+
const DroppedPage = require('./DroppedPage')
63+
const ViewPage = require('./ViewPage')
5764
5865
let vm
5966

0 commit comments

Comments
 (0)