Skip to content

Commit

Permalink
feat(ui): try to load logo.png in package search
Browse files Browse the repository at this point in the history
  • Loading branch information
Guillaume Chau committed Apr 12, 2018
1 parent 11bb249 commit 46567e3
Showing 1 changed file with 30 additions and 1 deletion.
31 changes: 30 additions & 1 deletion packages/@vue/cli-ui/src/components/PackageSearchItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
}"
>
<ItemLogo
:image="pkg.owner.avatar"
:image="logoUrl"
:selected="selected"
/>

Expand Down Expand Up @@ -62,10 +62,39 @@ export default {
}
},
data () {
return {
logoUrl: null
}
},
computed: {
official () {
return this.pkg.owner.name === 'vuejs'
}
},
watch: {
pkg: {
handler: 'updateLogo',
immediate: true
}
},
methods: {
updateLogo () {
// By default, show the npm user avatar
this.logoUrl = this.pkg.owner.avatar
// Try to load the logo.png file inside the package
const name = this.pkg.name
const img = new Image()
img.onload = () => {
if (name !== this.pkg.name) return
this.logoUrl = img.src
}
img.src = `https://unpkg.com/${name}/logo.png`
}
}
}
</script>
Expand Down

0 comments on commit 46567e3

Please sign in to comment.