Skip to content

Commit e0ae817

Browse files
committed
Reorder hydration to happen after UI is loaded
1 parent 8581759 commit e0ae817

File tree

3 files changed

+42
-38
lines changed

3 files changed

+42
-38
lines changed

webpack/js/components.js

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

3+
import {hydrateAppWithData} from "./hydration";
4+
35
export const IssueLabel = {
46
template: `
57
<span class="gh-label" :class="className">
@@ -25,7 +27,7 @@ export const IssueLabel = {
2527
* @returns {string} the name of the class to apply to the label
2628
*/
2729
className() {
28-
return window.categories[this.name] || 'miscellaneous'
30+
return this.$root.categories[this.name] || 'miscellaneous'
2931
}
3032
}
3133
}
@@ -68,7 +70,7 @@ export const IssueCard = {
6870
},
6971
computed: {
7072
dateCreated() {
71-
const dateCreated = new Date(this.issue.createdAt*1000)
73+
const dateCreated = new Date(this.issue.createdAt * 1000)
7274
return dateCreated.toLocaleDateString()
7375
}
7476
}
@@ -80,7 +82,7 @@ export const App = {
8082
<div class="find-issues">
8183
<div class="columns">
8284
<div class="column is-one-quarter">
83-
<form id="filters">
85+
<form id="filters" v-if="options.skills.length">
8486
<label for="skills">
8587
<strong>Skill set</strong><br/>
8688
Choose up to three skills that you would like to see issues for.
@@ -108,6 +110,9 @@ export const App = {
108110
:reduce="experience => experience.code"
109111
:clearable="false"/>
110112
</form>
113+
<div v-else>
114+
Loading filters, please wait...
115+
</div>
111116
</div>
112117
<div class="column">
113118
<template v-if="filteredIssues.length">
@@ -131,7 +136,7 @@ export const App = {
131136
data() {
132137
return {
133138
options: {
134-
skills: window.skills,
139+
skills: [],
135140
experiences: [
136141
{name: 'Yes, it is', code: 'beginner'},
137142
{name: 'No, it isn\'t', code: 'experienced'}
@@ -141,6 +146,7 @@ export const App = {
141146
skills: [],
142147
experience: 'experienced'
143148
},
149+
categories: {},
144150
issues: []
145151
}
146152
},
@@ -166,5 +172,23 @@ export const App = {
166172
return true
167173
}).sort((a, b) => b.createdAt - a.createdAt)
168174
}
175+
},
176+
mounted() {
177+
const BASE_URL = 'https://raw.githubusercontent.com/creativecommons/ccos-scripts/master/normalize_repos'
178+
const FILE_URL = name => `${BASE_URL}/${name}.json`
179+
180+
Promise
181+
.all([
182+
fetch(FILE_URL('skills'))
183+
.then(response => response.json()),
184+
fetch(FILE_URL('labels'))
185+
.then(response => response.json())
186+
])
187+
.then(([skillResponse, labelResponse]) => {
188+
const [skills, categories] = hydrateAppWithData(skillResponse, labelResponse)
189+
this.categories = categories
190+
this.options.skills = skills
191+
})
192+
.catch(err => console.error(err))
169193
}
170194
}

webpack/js/hydration.js

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

10-
window.categories = {}
11-
window.labels.groups.forEach(group => {
10+
const categories = {}
11+
labels.groups.forEach(group => {
1212
group.labels.forEach(label => {
1313
let name = label.name
1414
if (group.is_prefixed !== false) {
@@ -23,15 +23,17 @@ export const hydrateAppWithData = () => {
2323
} else {
2424
styleName = group.name
2525
}
26-
window.categories[name] = styleName
26+
categories[name] = styleName
2727
})
2828
})
29-
window.labels.standalone.forEach(label => {
29+
labels.standalone.forEach(label => {
3030
let name = `${label.emoji} ${label.name}`
31-
window.categories[name] = 'miscellaneous'
31+
categories[name] = 'miscellaneous'
3232
})
33-
window.skills.forEach(skill => {
33+
skills.forEach(skill => {
3434
let name = `💪 skill: ${skill.toLocaleLowerCase()}`
35-
window.categories[name] = 'skill'
35+
categories[name] = 'skill'
3636
})
37+
38+
return [skills, categories]
3739
}

webpack/js/issue-finder.js

+2-24
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,6 @@
11
import Vue from 'vue';
2-
3-
import {hydrateAppWithData} from './hydration';
42
import {App} from './components'
53

64
$(document).ready(function () {
7-
const BASE_URL = 'https://raw.githubusercontent.com/creativecommons/ccos-scripts/master/normalize_repos'
8-
const FILE_URL = name => `${BASE_URL}/${name}.json`
9-
10-
Promise
11-
.all([
12-
fetch(FILE_URL('skills'))
13-
.then(response => response.json())
14-
.then(data => {
15-
window.skills = data
16-
}),
17-
fetch(FILE_URL('labels'))
18-
.then(response => response.json())
19-
.then(data => {
20-
window.labels = data
21-
})
22-
])
23-
.then(() => {
24-
hydrateAppWithData()
25-
window.app = new Vue(App)
26-
})
27-
.catch(err => console.error(err))
28-
})
5+
window.app = new Vue(App)
6+
})

0 commit comments

Comments
 (0)