Skip to content

Commit 424714f

Browse files
committed
Change implementation to use databag instead of Octokit
1 parent 91e769a commit 424714f

File tree

3 files changed

+47
-71
lines changed

3 files changed

+47
-71
lines changed

webpack/js/components.js

+41-58
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
import VueSelect from 'vue-select';
22

3-
import {octokit} from './octokit';
4-
53
export const IssueLabel = {
64
template: `
75
<span class="gh-label" :class="className">
@@ -27,24 +25,34 @@ export const IssueLabel = {
2725
* @returns {string} the name of the class to apply to the label
2826
*/
2927
className() {
30-
return window.className[this.name] || 'miscellaneous'
28+
return window.categories[this.name] || 'miscellaneous'
3129
}
3230
}
3331
}
3432

3533
export const IssueCard = {
3634
template: `
3735
<div class="card entry-post vertical margin-top-normal padding-normal">
38-
<h4 class="card-title b-header margin-bottom-small">{{ issue.title }}</h4>
39-
<a :href="issue.html_url" class="button is-text tiny site-link" target="_blank">
40-
<span class="has-color-forest-green">
41-
{{ issue.repository.name }}#{{ issue.number }}
42-
</span>
43-
<i class="icon external-link has-color-forest-green"></i>
44-
</a>
36+
<h4 class="card-title b-header margin-bottom-small">
37+
{{ issue.title }}
38+
</h4>
39+
<p class="is-size-6">
40+
<a
41+
:href="issue.html_url"
42+
target="_blank">
43+
<span class="has-color-forest-green">
44+
{{ issue.repo }}#{{ issue.number }}
45+
</span>
46+
<i
47+
class="icon external-link has-color-forest-green is-size-7"
48+
:style="{ verticalAlign: 'top' }">
49+
</i>
50+
</a>
51+
&nbsp;&nbsp;opened on {{ dateCreated }}.
52+
</p>
4553
<div class="labels margin-top-small">
4654
<IssueLabel
47-
v-for="(name, index) in issue.labelNames"
55+
v-for="(name, index) in issue.labels"
4856
:key="index"
4957
:name="name"/>
5058
</div>
@@ -57,6 +65,12 @@ export const IssueCard = {
5765
type: Object,
5866
required: true
5967
},
68+
},
69+
computed: {
70+
dateCreated() {
71+
const dateCreated = new Date(this.issue.createdAt*1000)
72+
return dateCreated.toLocaleDateString()
73+
}
6074
}
6175
}
6276

@@ -68,7 +82,7 @@ export const App = {
6882
<div class="column is-one-quarter">
6983
<form id="filters">
7084
<label for="skills">
71-
<strong>Skill set</strong><br>
85+
<strong>Skill set</strong><br/>
7286
Choose up to three skills that you would like to see issues for.
7387
</label>
7488
<VueSelect
@@ -82,7 +96,7 @@ export const App = {
8296
multiple/>
8397
<br/>
8498
<label for="experience">
85-
<strong>Experience</strong><br>
99+
<strong>Experience</strong><br/>
86100
Is this your first time contributing to CC?
87101
</label>
88102
<VueSelect
@@ -96,10 +110,10 @@ export const App = {
96110
</form>
97111
</div>
98112
<div class="column">
99-
<template v-if="issues.length">
100-
<issue-card
101-
v-for="issue in filteredIssues"
102-
:key="issue.id"
113+
<template v-if="filteredIssues.length">
114+
<IssueCard
115+
v-for="(issue, index) in filteredIssues"
116+
:key="index"
103117
:issue="issue"/>
104118
</template>
105119
<p
@@ -117,7 +131,7 @@ export const App = {
117131
data() {
118132
return {
119133
options: {
120-
skills: window.skillSet,
134+
skills: window.skills,
121135
experiences: [
122136
{name: 'Yes, it is', code: 'beginner'},
123137
{name: 'No, it isn\'t', code: 'experienced'}
@@ -137,51 +151,20 @@ export const App = {
137151
* @returns {array} the array of filtered issues
138152
*/
139153
filteredIssues() {
140-
return this.issues.filter(issue => {
141-
const joinedLabels = issue.labelNames.join(',')
142-
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
154+
return window.issues.filter(issue => {
155+
// Check experience match
156+
if (this.filters.experience === 'beginner' && !issue.labels.includes('good first issue')) {
143157
return false
144158
}
145-
if (this.filters.experience === 'beginner' && !joinedLabels.includes('good first issue')) {
159+
160+
// Check skill set match
161+
const joinedLabels = issue.labels.join(',')
162+
if (this.filters.skills.length && !this.filters.skills.some(skill => joinedLabels.includes(skill))) {
146163
return false
147164
}
165+
148166
return true
149-
})
167+
}).sort((a, b) => b.createdAt - a.createdAt)
150168
}
151-
},
152-
methods: {
153-
/**
154-
* Run the search based on the data submitted via the form and load all
155-
* results into the `issues` attribute. Can be reused for a future
156-
* 'Load More' button.
157-
*
158-
* @param {number} page - the page of results to fetch
159-
*/
160-
search(page = 1) {
161-
octokit
162-
.issues
163-
.listForOrg({
164-
org: 'creativecommons',
165-
state: 'open',
166-
filter: 'all',
167-
labels: 'help wanted',
168-
sort: 'created',
169-
direction: 'desc',
170-
per_page: 100,
171-
page
172-
})
173-
.then(response => response.data)
174-
.then(issueLists => {
175-
const issues = issueLists.flat()
176-
issues.forEach(issue => {
177-
issue.labelNames = issue.labels.map(label => label.name)
178-
})
179-
this.issues = issues
180-
})
181-
.catch(err => console.error(err))
182-
}
183-
},
184-
mounted() {
185-
this.search()
186169
}
187170
}

webpack/js/hydration.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
export const hydrateAppWithData = () => {
2-
window.skillSet = Array.from( // Convert back into an array
2+
window.skills = Array.from( // Convert back into an array
33
new Set( // Remove duplicates
44
Object.values(window.skills)
55
.flat() // Combine all skills
66
.map(skill => skill.split('/')[0]) // Keep only the prefix
77
)
88
)
99

10-
window.className = {}
10+
window.categories = {}
1111
window.labels.groups.forEach(group => {
1212
group.labels.forEach(label => {
1313
let name = label.name
@@ -23,15 +23,15 @@ export const hydrateAppWithData = () => {
2323
} else {
2424
styleName = group.name
2525
}
26-
window.className[name] = styleName
26+
window.categories[name] = styleName
2727
})
2828
})
2929
window.labels.standalone.forEach(label => {
3030
let name = `${label.emoji} ${label.name}`
31-
window.className[name] = 'miscellaneous'
31+
window.categories[name] = 'miscellaneous'
3232
})
33-
window.skillSet.forEach(skill => {
33+
window.skills.forEach(skill => {
3434
let name = `💪 skill: ${skill.toLocaleLowerCase()}`
35-
window.className[name] = 'skill'
35+
window.categories[name] = 'skill'
3636
})
3737
}

webpack/js/octokit.js

-7
This file was deleted.

0 commit comments

Comments
 (0)