Skip to content

Commit

Permalink
Fix avatar loading spinner size
Browse files Browse the repository at this point in the history
Refactored avatar component logic to be located only in Phoenix core.
Moved spinner into the avatar component.
Adjusted spinner size to match the one of the avatar to avoid layout
shifting.
  • Loading branch information
Vincent Petry committed Jan 28, 2020
1 parent e0df137 commit 5a1fd3f
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 40 deletions.
9 changes: 3 additions & 6 deletions apps/files/src/components/Collaborators/AutocompleteItem.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
<template>
<div class="uk-flex uk-flex-middle">
<oc-spinner v-if="loading" uk-spinner="ratio:1.6" class="uk-margin-small-right" :aria-label="$gettext('Loading avatar')" />
<avatar v-if="item.value.shareType === 0" class="uk-margin-small-right" :width="50" :userid="avatar" :userName="item.label" />
<template v-else>
<oc-avatar v-if="item.value.shareType === 0" :src="avatar" class="uk-margin-small-right" :width="50" :userName="item.label" />
<template v-else>
<oc-icon v-if="item.value.shareType === 1" class="uk-margin-small-right" name="group" size="large" />
<oc-icon v-else class="uk-margin-small-right" name="person" size="large" />
</template>
<oc-icon v-if="item.value.shareType === 1" class="uk-margin-small-right" name="group" size="large" />
<oc-icon v-else class="uk-margin-small-right" name="person" size="large" />
</template>
<div class="files-collaborators-autocomplete-user-text">
<div
Expand Down
14 changes: 2 additions & 12 deletions apps/files/src/components/Collaborators/Collaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
<div>
<div v-if="$_reshareInformation" class="uk-text-meta uk-flex uk-flex-middle uk-margin-small-bottom"><oc-icon name="repeat" class="uk-margin-small-right" /> {{ $_reshareInformation }}</div>
<div class="files-collaborators-collaborator-information uk-flex uk-flex-wrap uk-flex-middle">
<oc-spinner v-if="loading" key="collaborator-avatar-spinner" uk-spinner="ratio:1.6" class="uk-margin-small-right" :aria-label="$gettext('Loading')"/>
<div v-else key="collaborator-avatar-loaded">
<oc-avatar v-if="collaborator.info.share_type === '0'" :src="avatar" class="uk-margin-small-right" :width="50" :userName="collaborator.displayName" />
<div key="collaborator-avatar-loaded">
<avatar v-if="collaborator.info.share_type === '0'" class="uk-margin-small-right" :width="50" :userid="collaborator.name" :userName="collaborator.displayName" />
<div v-else key="collaborator-avatar-placeholder">
<oc-icon v-if="collaborator.info.share_type === '1'" class="uk-margin-small-right" name="group" size="large" />
<oc-icon v-else class="uk-margin-small-right" name="person" size="large" />
Expand Down Expand Up @@ -34,12 +33,6 @@ export default {
mixins: [
Mixins
],
data () {
return {
avatar: '',
loading: false
}
},
computed: {
...mapGetters(['user']),
Expand All @@ -65,9 +58,6 @@ export default {
label: this.$gettext('Unknown Role')
}
}
},
mounted () {
this.$_ocCollaborators_loadAvatar(this.collaborator)
}
}
</script>
Expand Down
1 change: 0 additions & 1 deletion apps/files/src/store/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ function _buildShare (s, file) {
case ('1'): // group share
share.role = bitmaskToRole(s.permissions, file.type === 'folder')
share.permissions = s.permissions
share.avatar = 'https://picsum.photos/64/64?image=1075' // TODO where do we get the avatar from? by uid? remote.php/dav/avatars/admin/128.png
share.name = s.share_with // this is the recipient userid, rename to uid or subject? add separate field userName?
share.displayName = s.share_with_displayname
// TODO: Refactor to work with roles / prepare for roles API
Expand Down
39 changes: 22 additions & 17 deletions src/components/Avatar.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<template>
<component :is="type" v-if="enabled">
<oc-avatar :width="width" :loading="loading" :src="avatarSource" :userName="userName" />
<oc-spinner v-if="loading" size="small" key="collaborator-avatar-spinner" :aria-label="$gettext('Loading')"
:style="'width:' + width + 'px;height:' + width + 'px'" />
<oc-avatar v-else :width="width" :src="avatarSource" :userName="userName" />
</component>
</template>
<script>
import { mapGetters } from 'vuex'
export default {
name: 'Avatar',
data () {
return {
/**
Expand Down Expand Up @@ -35,22 +38,24 @@ export default {
const url = instance + '/remote.php/dav/avatars/' + this.userid + '/128.png'
headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')
fetch(url, { headers })
.then(response => {
if (response.ok) {
return response.blob()
}
throw new Error('Network response was not ok.')
})
.then(blob => {
this.loading = false
this.avatarSource = window.URL.createObjectURL(blob)
})
.catch(error => {
this.avatarSource = ''
this.loading = false
console.log('There has been a problem with your fetch operation: ', error.message)
})
window.setTimeout(() => {
fetch(url, { headers })
.then(response => {
if (response.ok) {
return response.blob()
}
throw new Error('Network response was not ok.')
})
.then(blob => {
this.loading = false
this.avatarSource = window.URL.createObjectURL(blob)
})
.catch(error => {
this.avatarSource = ''
this.loading = false
console.log('There has been a problem with your fetch operation: ', error.message)
})
}, 5000)
}
},
watch: {
Expand Down
4 changes: 0 additions & 4 deletions src/components/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,8 @@

<script>
import appVersionJson from '../../build/version.json'
import Avatar from './Avatar.vue'
export default {
components: {
Avatar
},
props: {
userId: {
type: String,
Expand Down
3 changes: 3 additions & 0 deletions src/phoenix.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ import { Drag, Drop } from 'vue-drag-drop'
import DesignSystem from 'owncloud-design-system'
import 'owncloud-design-system/dist/system/system.css'

import Avatar from './components/Avatar.vue'

import wgxpath from 'wicked-good-xpath'
wgxpath.install()

Expand All @@ -64,6 +66,7 @@ Vue.use(VueMeta, {

Vue.component('drag', Drag)
Vue.component('drop', Drop)
Vue.component('avatar', Avatar)

// --- Router ----

Expand Down

0 comments on commit 5a1fd3f

Please sign in to comment.