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 29, 2020
1 parent e0df137 commit 967b1da
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 72 deletions.
17 changes: 6 additions & 11 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-image v-if="item.value.shareType === shareTypes.user" class="uk-margin-small-right" :width="50" :userid="item.value.shareWith" :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 === shareTypes.group" 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 All @@ -21,18 +18,16 @@

<script>
import Mixins from '../../mixins/collaborators'
import { shareTypes } from '../../helpers/shareTypes'
export default {
name: 'AutocompleteItem',
props: ['item'],
mixins: [Mixins],
mounted () {
this.$_ocCollaborators_loadAvatar(this.item)
},
data () {
return {
loading: false,
avatar: ''
shareTypes,
loading: false
}
}
}
Expand Down
20 changes: 10 additions & 10 deletions apps/files/src/components/Collaborators/Collaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@
<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-image v-if="$_shareType === shareTypes.user" 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-if="$_shareType === shareTypes.group" class="uk-margin-small-right" name="group" size="large" />
<oc-icon v-else class="uk-margin-small-right" name="person" size="large" />
</div>
</div>
Expand All @@ -26,6 +25,7 @@

<script>
import { mapGetters } from 'vuex'
import { shareTypes } from '../../helpers/shareTypes'
import Mixins from '../../mixins/collaborators'
export default {
Expand All @@ -34,10 +34,9 @@ export default {
mixins: [
Mixins
],
data () {
data: function () {
return {
avatar: '',
loading: false
shareTypes
}
},
computed: {
Expand All @@ -51,6 +50,10 @@ export default {
return this.collaborator.info.displayname_owner
},
$_shareType () {
return parseInt(this.collaborator.info.share_type, 10)
},
originalRole () {
if (this.collaborator.role.name === 'advancedRole') {
return this.advancedRole
Expand All @@ -65,9 +68,6 @@ export default {
label: this.$gettext('Unknown Role')
}
}
},
mounted () {
this.$_ocCollaborators_loadAvatar(this.collaborator)
}
}
</script>
Expand Down
3 changes: 0 additions & 3 deletions apps/files/src/components/Collaborators/EditCollaborator.vue
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,6 @@ export default {
return filterObject(permissions, (key, value) => value)
}
},
mounted () {
this.$_ocCollaborators_loadAvatar(this.collaborator)
},
methods: {
...mapActions('Files', ['changeShare', 'toggleCollaboratorsEdit']),
Expand Down
37 changes: 0 additions & 37 deletions apps/files/src/mixins/collaborators.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,43 +84,6 @@ export default {
this.editing = true
this.toggleCollaboratorsEdit(true)
},
$_ocCollaborators_loadAvatar (item) {
if ((item.value && item.value.shareType !== 0) || (item.info && item.info.share_type !== '0')) return

let name
if (item.value) {
name = item.value.shareWith
} else if (item.info) {
name = item.name
}

const dav = this.$client.helpers._davPath
const headers = new Headers()
const url = `${dav}/avatars/${name}/128.png`

headers.append('Authorization', 'Bearer ' + this.getToken)
headers.append('X-Requested-With', 'XMLHttpRequest')

this.loading = true

fetch(url, { headers })
.then(response => {
if (response.ok) {
return response.blob()
}
throw new Error('Network response was not ok.')
})
.then(blob => {
this.avatar = window.URL.createObjectURL(blob)
})
.catch(_ => {
this.avatar = ''
})
.finally(_ => {
this.loading = false
})
},

collaboratorOptionChanged ({ role, permissions, propagate = true }) {
this.selectedRole = role
this.additionalPermissions = permissions
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
18 changes: 14 additions & 4 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 @@ -40,16 +43,23 @@ export default {
if (response.ok) {
return response.blob()
}
throw new Error('Network response was not ok.')
if (response.status !== 404) {
throw new Error(`Unexpected status code ${response.status}`)
}
})
.then(blob => {
this.loading = false
this.avatarSource = window.URL.createObjectURL(blob)
if (blob) {
this.avatarSource = window.URL.createObjectURL(blob)
} else {
// 404, none found
this.avatarSource = ''
}
})
.catch(error => {
this.avatarSource = ''
this.loading = false
console.log('There has been a problem with your fetch operation: ', error.message)
console.error(`Error loading avatar image for user "${this.userid}": `, error.message)
})
}
},
Expand Down
8 changes: 2 additions & 6 deletions src/components/UserMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@
<div>
<oc-button id="_userMenuButton" class="oc-topbar-personal uk-height-1-1" variation="primary" aria-label="$gettext('User Menu')" ref="menuButton">
<oc-grid gutter="small">
<avatar class="oc-topbar-personal-avatar" :width="32" :userid="userId" :userName="userDisplayName"/>
<avatar-image class="oc-topbar-personal-avatar" :width="32" :userid="userId" :userName="userDisplayName"/>
<div class="oc-topbar-personal-label">{{ userDisplayName }}</div>
</oc-grid>
</oc-button>
<oc-drop toggle="#_userMenuButton" mode="click" :options="{pos:'bottom-right'}" class="uk-width-large" ref="menu">
<div class="uk-card-body uk-flex uk-flex-middle uk-flex-column" id="account-info-container">
<avatar
<avatar-image
:userid="userId"
:userName="userDisplayName"
:width="128"
Expand All @@ -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-image', Avatar)

// --- Router ----

Expand Down

0 comments on commit 967b1da

Please sign in to comment.