Allow set avatar from skinlib
This commit is contained in:
parent
70c9226bf8
commit
0dfdf593ca
33
resources/assets/src/components/mixins/setAsAvatar.js
Normal file
33
resources/assets/src/components/mixins/setAsAvatar.js
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
import toastr from 'toastr'
|
||||||
|
import { swal } from '../../js/notify'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
methods: {
|
||||||
|
async setAsAvatar() {
|
||||||
|
const { dismiss } = await swal({
|
||||||
|
title: this.$t('user.setAvatar'),
|
||||||
|
text: this.$t('user.setAvatarNotice'),
|
||||||
|
type: 'question',
|
||||||
|
showCancelButton: true,
|
||||||
|
})
|
||||||
|
if (dismiss) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
const { errno, msg } = await this.$http.post(
|
||||||
|
'/user/profile/avatar',
|
||||||
|
{ tid: this.tid }
|
||||||
|
)
|
||||||
|
if (errno === 0) {
|
||||||
|
toastr.success(msg)
|
||||||
|
|
||||||
|
$('[alt="User Image"]').each(function it() {
|
||||||
|
// eslint-disable-next-line no-invalid-this
|
||||||
|
$(this).prop('src', `${$(this).attr('src')}?${new Date().getTime()}`)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
toastr.warning(msg)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
@ -19,23 +19,26 @@
|
||||||
v-if="liked"
|
v-if="liked"
|
||||||
v-t="'skinlib.apply'"
|
v-t="'skinlib.apply'"
|
||||||
:href="`${baseUrl}/user/closet?tid=${tid}`"
|
:href="`${baseUrl}/user/closet?tid=${tid}`"
|
||||||
class="btn btn-success pull-right"
|
class="btn btn-success pull-right pulled-right-btn"
|
||||||
style="margin-left: 12px"
|
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
v-if="liked"
|
v-if="liked"
|
||||||
v-t="'skinlib.removeFromCloset'"
|
v-t="'skinlib.removeFromCloset'"
|
||||||
style="margin-left: 12px"
|
class="btn btn-primary pull-right pulled-right-btn"
|
||||||
class="btn btn-primary pull-right"
|
|
||||||
@click="removeFromCloset"
|
@click="removeFromCloset"
|
||||||
/>
|
/>
|
||||||
<a
|
<a
|
||||||
v-else
|
v-else
|
||||||
v-t="'skinlib.addToCloset'"
|
v-t="'skinlib.addToCloset'"
|
||||||
style="margin-left: 12px"
|
class="btn btn-primary pull-right pulled-right-btn"
|
||||||
class="btn btn-primary pull-right"
|
|
||||||
@click="addToCloset"
|
@click="addToCloset"
|
||||||
/>
|
/>
|
||||||
|
<button
|
||||||
|
v-if="type !== 'cape'"
|
||||||
|
v-t="'user.setAsAvatar'"
|
||||||
|
class="btn btn-default pull-right pulled-right-btn"
|
||||||
|
@click="setAsAvatar"
|
||||||
|
/>
|
||||||
<a
|
<a
|
||||||
v-if="canBeDownloaded"
|
v-if="canBeDownloaded"
|
||||||
v-t="'skinlib.show.download'"
|
v-t="'skinlib.show.download'"
|
||||||
|
|
@ -138,12 +141,14 @@
|
||||||
<script>
|
<script>
|
||||||
import toastr from 'toastr'
|
import toastr from 'toastr'
|
||||||
import { swal } from '../../js/notify'
|
import { swal } from '../../js/notify'
|
||||||
|
import setAsAvatar from '../mixins/setAsAvatar'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'Show',
|
name: 'Show',
|
||||||
components: {
|
components: {
|
||||||
Previewer: () => import('../common/Previewer'),
|
Previewer: () => import('../common/Previewer'),
|
||||||
},
|
},
|
||||||
|
mixins: [setAsAvatar],
|
||||||
props: {
|
props: {
|
||||||
baseUrl: {
|
baseUrl: {
|
||||||
type: String,
|
type: String,
|
||||||
|
|
@ -346,4 +351,8 @@ export default {
|
||||||
.table > tbody > tr > td {
|
.table > tbody > tr > td {
|
||||||
border-top: 0;
|
border-top: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.pulled-right-btn {
|
||||||
|
margin-left: 12px;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
||||||
|
|
@ -35,9 +35,11 @@
|
||||||
<script>
|
<script>
|
||||||
import toastr from 'toastr'
|
import toastr from 'toastr'
|
||||||
import { swal } from '../../js/notify'
|
import { swal } from '../../js/notify'
|
||||||
|
import setAsAvatar from '../mixins/setAsAvatar'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'ClosetItem',
|
name: 'ClosetItem',
|
||||||
|
mixins: [setAsAvatar],
|
||||||
props: {
|
props: {
|
||||||
tid: {
|
tid: {
|
||||||
type: Number,
|
type: Number,
|
||||||
|
|
@ -111,33 +113,6 @@ export default {
|
||||||
toastr.warning(msg)
|
toastr.warning(msg)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
async setAsAvatar() {
|
|
||||||
const { dismiss } = await swal({
|
|
||||||
title: this.$t('user.setAvatar'),
|
|
||||||
text: this.$t('user.setAvatarNotice'),
|
|
||||||
type: 'question',
|
|
||||||
showCancelButton: true,
|
|
||||||
})
|
|
||||||
if (dismiss) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
const { errno, msg } = await this.$http.post(
|
|
||||||
'/user/profile/avatar',
|
|
||||||
{ tid: this.tid }
|
|
||||||
)
|
|
||||||
if (errno === 0) {
|
|
||||||
toastr.success(msg)
|
|
||||||
|
|
||||||
// Refresh avatars
|
|
||||||
$('[alt="User Image"]').each(function it() {
|
|
||||||
// eslint-disable-next-line no-invalid-this
|
|
||||||
$(this).prop('src', `${$(this).attr('src')}?${new Date().getTime()}`)
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
toastr.warning(msg)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -130,6 +130,27 @@ test('link to downloading texture', async () => {
|
||||||
expect(wrapper.contains('a[title="123"]')).toBeFalse()
|
expect(wrapper.contains('a[title="123"]')).toBeFalse()
|
||||||
expect(wrapper.contains('span[title="123"]')).toBeTrue()
|
expect(wrapper.contains('span[title="123"]')).toBeTrue()
|
||||||
})
|
})
|
||||||
|
test('set as avatar', () => {
|
||||||
|
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: true })
|
||||||
|
Vue.prototype.$http.get.mockResolvedValueOnce({ type: 'steve' })
|
||||||
|
.mockResolvedValueOnce({ type: 'cape' })
|
||||||
|
const wrapper = mount(Show, {
|
||||||
|
mocks: {
|
||||||
|
$route: ['/skinlib/show/1', '1'],
|
||||||
|
},
|
||||||
|
stubs: { previewer },
|
||||||
|
})
|
||||||
|
wrapper.find('button.btn-default').trigger('click')
|
||||||
|
expect(swal).toBeCalled()
|
||||||
|
|
||||||
|
const noSetAsAvatar = mount(Show, {
|
||||||
|
mocks: {
|
||||||
|
$route: ['/skinlib/show/1', '1'],
|
||||||
|
},
|
||||||
|
stubs: { previewer },
|
||||||
|
})
|
||||||
|
expect(noSetAsAvatar.find('button.btn-default').isEmpty()).toBeTrue()
|
||||||
|
})
|
||||||
test('add to closet', async () => {
|
test('add to closet', async () => {
|
||||||
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false })
|
Object.assign(window.blessing.extra, { currentUid: 1, inCloset: false })
|
||||||
Vue.prototype.$http.get.mockResolvedValue({ name: 'wow', likes: 2 })
|
Vue.prototype.$http.get.mockResolvedValue({ name: 'wow', likes: 2 })
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user