-
-
Notifications
You must be signed in to change notification settings - Fork 184
/
Copy pathcomponents.js
170 lines (165 loc) · 4.09 KB
/
components.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import VueSelect from 'vue-select';
export const IssueLabel = {
template: `
<span class="gh-label" :class="className">
{{ name }}
</span>`,
data() {
return {
labels: window.labels
}
},
props: {
name: {
type: String,
required: true
}
},
computed: {
/**
* Get the name of the class to apply to the label based on the group to
* which it belongs. Falls back to miscellaneous if the label does not
* belong to a group or a class cannot be identified.
*
* @returns {string} the name of the class to apply to the label
*/
className() {
return window.categories[this.name] || 'miscellaneous'
}
}
}
export const IssueCard = {
template: `
<div class="card entry-post vertical margin-top-normal padding-normal">
<h4 class="card-title b-header margin-bottom-small">
{{ issue.title }}
</h4>
<p class="is-size-6">
<a
:href="issue.html_url"
target="_blank">
<span class="has-color-forest-green">
{{ issue.repo }}#{{ issue.number }}
</span>
<i
class="icon external-link has-color-forest-green is-size-7"
:style="{ verticalAlign: 'top' }">
</i>
</a>
opened on {{ dateCreated }}.
</p>
<div class="labels margin-top-small">
<IssueLabel
v-for="(name, index) in issue.labels"
:key="index"
:name="name"/>
</div>
</div>`,
components: {
IssueLabel
},
props: {
issue: {
type: Object,
required: true
},
},
computed: {
dateCreated() {
const dateCreated = new Date(this.issue.createdAt*1000)
return dateCreated.toLocaleDateString()
}
}
}
export const App = {
el: '#vue-app',
template: `
<div class="find-issues">
<div class="columns">
<div class="column is-one-quarter">
<form id="filters">
<label for="skills">
<strong>Skill set</strong><br/>
Choose up to three skills that you would like to see issues for.
</label>
<VueSelect
v-model="filters.skills"
id="skills"
name="skills"
placeholder="No preference"
:options="options.skills"
:reduce="skill => skill.toLocaleLowerCase()"
:selectable="() => filters.skills.length < 3"
multiple/>
<br/>
<label for="experience">
<strong>Experience</strong><br/>
Is this your first time contributing to CC?
</label>
<VueSelect
v-model="filters.experience"
id="experience"
name="experience"
:options="options.experiences"
label="name"
:reduce="experience => experience.code"
:clearable="false"/>
</form>
</div>
<div class="column">
<template v-if="filteredIssues.length">
<IssueCard
v-for="(issue, index) in filteredIssues"
:key="index"
:issue="issue"/>
</template>
<p
v-else
class="margin-top-normal">
No results.
</p>
</div>
</div>
</div>`,
components: {
VueSelect,
IssueCard
},
data() {
return {
options: {
skills: window.skills,
experiences: [
{name: 'Yes, it is', code: 'beginner'},
{name: 'No, it isn\'t', code: 'experienced'}
]
},
filters: {
skills: [],
experience: 'experienced'
},
issues: []
}
},
computed: {
/**
* Get a filtered list of issues matching the chosen skill labels.
*
* @returns {array} the array of filtered issues
*/
filteredIssues() {
return window.issues.filter(issue => {
// Check experience match
if (this.filters.experience === 'beginner' && !issue.labels.includes('good first issue')) {
return false
}
// Check skill set match
const joinedLabels = issue.labels.join(',')
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
return false
}
return true
}).sort((a, b) => b.createdAt - a.createdAt)
}
}
}