Skip to content

Commit

Permalink
Fix avatar and duplicate code
Browse files Browse the repository at this point in the history
Spinner was broken
  • Loading branch information
Vincent Petry committed Jan 28, 2020
1 parent e0df137 commit 38a7642
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 35 deletions.
13 changes: 7 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 All @@ -21,6 +18,7 @@

<script>
import Mixins from '../../mixins/collaborators'
import Avatar from './Avatar.vue'
export default {
name: 'AutocompleteItem',
Expand All @@ -29,6 +27,9 @@ export default {
mounted () {
this.$_ocCollaborators_loadAvatar(this.item)
},
components: {
Avatar
},
data () {
return {
loading: false,
Expand Down
16 changes: 5 additions & 11 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 All @@ -27,18 +26,16 @@
<script>
import { mapGetters } from 'vuex'
import Mixins from '../../mixins/collaborators'
import Avatar from './Avatar.vue'
export default {
name: 'Collaborator',
props: ['collaborator'],
mixins: [
Mixins
],
data () {
return {
avatar: '',
loading: false
}
components: {
Avatar
},
computed: {
...mapGetters(['user']),
Expand All @@ -65,9 +62,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
36 changes: 19 additions & 17 deletions src/components/Avatar.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<template>
<component :is="type" v-if="enabled">
<oc-avatar :width="width" :loading="loading" :src="avatarSource" :userName="userName" />
<oc-avatar :width="width" :src="avatarSource" :userName="userName" />
</component>
</template>
<script>
Expand Down Expand Up @@ -35,22 +35,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
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 @@ -61,6 +63,7 @@ Vue.use(VueMeta, {
// optional pluginOptions
refreshOnceOnNavigation: true
})
Vue.use(Avatar)

Vue.component('drag', Drag)
Vue.component('drop', Drop)
Expand Down

0 comments on commit 38a7642

Please sign in to comment.