-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
73 lines (67 loc) · 1.8 KB
/
main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
'use strict';
Vue.component('firstcommit', {
props: {
commit: Object
},
template: `
<div>
<h4><a :href="commit.html_url">{{ commit.commit.message }}</a></h4>
<h4>{{ commit.commit.committer.date }}</h4>
<h5>By <a :href="commit.author.html_url">{{ commit.author.login }}</a></h5>
<p><a :href="commit.html_url">{{ commit.sha }}</a></p>
</div>`
});
Vue.component('errormsg', {
props: {
message: {
type: String,
default: null
}
},
template: `
<div class="error">
<p>{{ message||'Something went wrong...' }}</p>
</div>`
});
var prompt = new Vue({
el: '#app',
data: {
/* Model fields linked to input */
username: '',
repo: '',
/********************************/
show_commit: false,
commit: null, // No commit message shown when null
error: null // No error message shown when null
},
methods: {
fetch_first_commit: fetch_first_commit_wrapper,
reset: reset
},
});
function fetch_first_commit_wrapper () {
// Pass commit object back to this -> which is linked to the firstcommit component
fetch_first_commit (this.username, this.repo,
(commit) => {
// Need a callback for async fetch in the helper
this.commit = commit;
this.show_commit = true;
// Clear error message
this.error = null;
},
(error_msg) => {
// Clear previous commit displayed
this.commit = null;
this.show_commit = false;
// Display error msg
this.error = error_msg;
}
);
}
function reset () {
this.commit = null;
this.show_commit = false;
this.username = '';
this.repo = '';
this.error = null;
}