Skip to content

Commit 510b582

Browse files
committed
Make experience reactive
1 parent dd5f6ab commit 510b582

File tree

1 file changed

+26
-56
lines changed

1 file changed

+26
-56
lines changed

webpack/js/components.js

+26-56
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,6 @@ export const App = {
9393
label="name"
9494
:reduce="experience => experience.code"
9595
:clearable="false"/>
96-
97-
<button
98-
class="button small is-success margin-top-small"
99-
@click.prevent="search">
100-
Search
101-
</button>
10296
</form>
10397
</div>
10498
<div class="column">
@@ -137,70 +131,46 @@ export const App = {
137131
}
138132
},
139133
computed: {
140-
/**
141-
* Get a nested list of all the labels to search for. This is only based on
142-
* the experience filter. The skills filter must be applied on the client
143-
* side due to limitations of the GitHub API.
144-
*
145-
* This returns a list of lists. Each nested list corresponds to a single
146-
* API query and multiple queries need to be run to get the combined set of
147-
* valid issues.
148-
*
149-
* @returns {array} the array of array of labels
150-
*/
151-
labelsList() {
152-
const labelsList = []
153-
if (this.filters.experience === 'experienced') {
154-
labelsList.push('help wanted')
155-
} else {
156-
labelsList.push('good first issue')
157-
}
158-
return labelsList
159-
},
160134
/**
161135
* Get a filtered list of issues matching the chosen skill labels.
162136
*
163137
* @returns {array} the array of filtered issues
164138
*/
165139
filteredIssues() {
166-
let filtered = this.issues
167-
if (this.filters.skills.length) {
168-
filtered = filtered.filter(issue => {
169-
const joinedLabels = issue.labelNames.join(',')
170-
return this.filters.skills.some(skill => joinedLabels.includes(skill))
171-
})
172-
}
173-
return filtered
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))) {
143+
return false
144+
}
145+
if (this.filters.experience === 'beginner' && !joinedLabels.includes('good first issue')) {
146+
return false
147+
}
148+
return true
149+
})
174150
}
175151
},
176152
methods: {
177153
/**
178-
* Get a Promise for the list of issues pertaining to a given labels.
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.
179157
*
180-
* @param {Array} labels - list of labels to search for
181-
* @returns {Promise} a promise that resolves into a list of issues
158+
* @param {number} page - the page of results to fetch
182159
*/
183-
promise(labels = []) {
184-
const params = {
185-
org: 'creativecommons',
186-
state: 'open',
187-
filter: 'all',
188-
per_page: 200
189-
}
190-
if (labels) {
191-
params.labels = labels.join(',')
192-
}
193-
return octokit
160+
search(page = 1) {
161+
octokit
194162
.issues
195-
.listForOrg(params)
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+
})
196173
.then(response => response.data)
197-
},
198-
/**
199-
* Run the search based on the data submitted via the form and load all
200-
* results into the `issues` attribute.
201-
*/
202-
search() {
203-
this.promise(this.labelsList)
204174
.then(issueLists => {
205175
const issues = issueLists.flat()
206176
issues.forEach(issue => {

0 commit comments

Comments
 (0)