2021-12-03 02:02:38 +01:00
|
|
|
<template>
|
2024-06-23 18:15:39 +02:00
|
|
|
<div :style="{ minWidth: cardWidth + 'px', maxWidth: cardWidth + 'px' }">
|
2024-06-03 08:04:03 +02:00
|
|
|
<nuxt-link :to="`/author/${author.id}`">
|
|
|
|
<div cy-id="card" @mouseover="mouseover" @mouseleave="mouseleave">
|
|
|
|
<div cy-id="imageArea" :style="{ height: cardHeight + 'px' }" class="bg-primary box-shadow-book rounded-md relative overflow-hidden">
|
|
|
|
<!-- Image or placeholder -->
|
|
|
|
<covers-author-image :author="author" />
|
2022-03-13 16:35:35 +01:00
|
|
|
|
2024-06-03 08:04:03 +02:00
|
|
|
<!-- Author name & num books overlay -->
|
2024-06-23 18:15:39 +02:00
|
|
|
<div cy-id="textInline" v-show="!searching && !nameBelow" class="absolute bottom-0 left-0 w-full py-1e bg-black bg-opacity-60 px-2e">
|
2024-06-03 08:04:03 +02:00
|
|
|
<p class="text-center font-semibold truncate" :style="{ fontSize: 0.75 + 'em' }">{{ name }}</p>
|
|
|
|
<p class="text-center text-gray-200" :style="{ fontSize: 0.65 + 'em' }">{{ numBooks }} {{ $strings.LabelBooks }}</p>
|
|
|
|
</div>
|
2021-12-03 02:02:38 +01:00
|
|
|
|
2024-06-03 08:04:03 +02:00
|
|
|
<!-- Search icon btn -->
|
2024-06-23 18:15:39 +02:00
|
|
|
<div cy-id="match" v-show="!searching && isHovering && userCanUpdate" class="absolute top-0 left-0 p-2e cursor-pointer hover:text-white text-gray-200 transform hover:scale-125 duration-150" @click.prevent.stop="searchAuthor">
|
2024-06-03 08:04:03 +02:00
|
|
|
<ui-tooltip :text="$strings.ButtonQuickMatch" direction="bottom">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols" :style="{ fontSize: 1.125 + 'em' }">search</span>
|
2024-06-03 08:04:03 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</div>
|
2024-06-23 18:15:39 +02:00
|
|
|
<div cy-id="edit" v-show="isHovering && !searching && userCanUpdate" class="absolute top-0 right-0 p-2e cursor-pointer hover:text-white text-gray-200 transform hover:scale-125 duration-150" @click.prevent.stop="$emit('edit', author)">
|
2024-06-03 08:04:03 +02:00
|
|
|
<ui-tooltip :text="$strings.LabelEdit" direction="bottom">
|
2024-07-08 18:36:37 +02:00
|
|
|
<span class="material-symbols" :style="{ fontSize: 1.125 + 'em' }">edit</span>
|
2024-06-03 08:04:03 +02:00
|
|
|
</ui-tooltip>
|
|
|
|
</div>
|
2022-03-13 12:42:43 +01:00
|
|
|
|
2024-06-03 08:04:03 +02:00
|
|
|
<!-- Loading spinner -->
|
|
|
|
<div cy-id="spinner" v-show="searching" class="absolute top-0 left-0 z-10 w-full h-full bg-black bg-opacity-50 flex items-center justify-center">
|
|
|
|
<widgets-loading-spinner size="" />
|
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-23 18:15:39 +02:00
|
|
|
<div cy-id="nameBelow" v-show="nameBelow" class="w-full py-1e px-2e">
|
2024-06-03 08:04:03 +02:00
|
|
|
<p class="text-center font-semibold truncate text-gray-200" :style="{ fontSize: 0.75 + 'em' }">{{ name }}</p>
|
2022-05-10 01:23:23 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
2024-06-03 08:04:03 +02:00
|
|
|
</nuxt-link>
|
|
|
|
</div>
|
2021-12-03 02:02:38 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
author: {
|
|
|
|
type: Object,
|
|
|
|
default: () => {}
|
|
|
|
},
|
|
|
|
width: Number,
|
2024-06-03 08:04:03 +02:00
|
|
|
height: {
|
2022-03-13 16:35:35 +01:00
|
|
|
type: Number,
|
2024-06-03 08:04:03 +02:00
|
|
|
default: 192
|
2022-03-21 11:08:33 +01:00
|
|
|
},
|
2024-06-03 08:04:03 +02:00
|
|
|
nameBelow: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false
|
|
|
|
}
|
2021-12-03 02:02:38 +01:00
|
|
|
},
|
|
|
|
data() {
|
|
|
|
return {
|
2022-03-13 16:35:35 +01:00
|
|
|
searching: false,
|
2022-03-15 00:53:49 +01:00
|
|
|
isHovering: false
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
computed: {
|
2024-06-03 08:04:03 +02:00
|
|
|
cardWidth() {
|
|
|
|
return this.width || this.cardHeight * 0.8
|
|
|
|
},
|
|
|
|
cardHeight() {
|
|
|
|
return this.height * this.sizeMultiplier
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
userToken() {
|
|
|
|
return this.$store.getters['user/getToken']
|
|
|
|
},
|
|
|
|
_author() {
|
|
|
|
return this.author || {}
|
|
|
|
},
|
2022-03-13 01:50:31 +01:00
|
|
|
authorId() {
|
|
|
|
return this._author.id
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
name() {
|
|
|
|
return this._author.name || ''
|
|
|
|
},
|
2022-05-14 01:11:54 +02:00
|
|
|
asin() {
|
|
|
|
return this._author.asin || ''
|
|
|
|
},
|
2021-12-03 02:02:38 +01:00
|
|
|
numBooks() {
|
|
|
|
return this._author.numBooks || 0
|
2022-05-03 00:32:52 +02:00
|
|
|
},
|
|
|
|
userCanUpdate() {
|
|
|
|
return this.$store.getters['user/getUserCanUpdate']
|
2023-04-16 22:53:46 +02:00
|
|
|
},
|
|
|
|
currentLibraryId() {
|
|
|
|
return this.$store.state.libraries.currentLibraryId
|
|
|
|
},
|
|
|
|
libraryProvider() {
|
|
|
|
return this.$store.getters['libraries/getLibraryProvider'](this.currentLibraryId) || 'google'
|
2024-06-03 08:04:03 +02:00
|
|
|
},
|
|
|
|
sizeMultiplier() {
|
|
|
|
return this.$store.getters['user/getSizeMultiplier']
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
|
|
|
},
|
2022-03-13 12:42:43 +01:00
|
|
|
methods: {
|
2022-03-13 16:35:35 +01:00
|
|
|
mouseover() {
|
|
|
|
this.isHovering = true
|
|
|
|
},
|
2022-05-10 01:23:23 +02:00
|
|
|
mouseleave() {
|
2022-03-13 16:35:35 +01:00
|
|
|
this.isHovering = false
|
|
|
|
},
|
2022-03-13 12:42:43 +01:00
|
|
|
async searchAuthor() {
|
2022-03-13 16:35:35 +01:00
|
|
|
this.searching = true
|
2022-05-14 01:11:54 +02:00
|
|
|
const payload = {}
|
|
|
|
if (this.asin) payload.asin = this.asin
|
|
|
|
else payload.q = this.name
|
|
|
|
|
2023-04-16 22:53:46 +02:00
|
|
|
payload.region = 'us'
|
|
|
|
if (this.libraryProvider.startsWith('audible.')) {
|
|
|
|
payload.region = this.libraryProvider.split('.').pop() || 'us'
|
|
|
|
}
|
|
|
|
|
2022-05-14 01:11:54 +02:00
|
|
|
var response = await this.$axios.$post(`/api/authors/${this.authorId}/match`, payload).catch((error) => {
|
2022-03-13 12:42:43 +01:00
|
|
|
console.error('Failed', error)
|
|
|
|
return null
|
|
|
|
})
|
2022-03-13 16:35:35 +01:00
|
|
|
if (!response) {
|
2022-09-19 00:02:19 +02:00
|
|
|
this.$toast.error(`Author ${this.name} not found`)
|
2022-03-13 16:35:35 +01:00
|
|
|
} else if (response.updated) {
|
2022-09-19 00:02:19 +02:00
|
|
|
if (response.author.imagePath) this.$toast.success(`Author ${response.author.name} was updated`)
|
|
|
|
else this.$toast.success(`Author ${response.author.name} was updated (no image found)`)
|
2022-03-13 16:35:35 +01:00
|
|
|
} else {
|
2022-09-19 00:02:19 +02:00
|
|
|
this.$toast.info(`No updates were made for Author ${response.author.name}`)
|
2022-03-13 16:35:35 +01:00
|
|
|
}
|
|
|
|
this.searching = false
|
2022-05-29 19:15:39 +02:00
|
|
|
},
|
|
|
|
setSearching(isSearching) {
|
|
|
|
this.searching = isSearching
|
2022-03-13 12:42:43 +01:00
|
|
|
}
|
|
|
|
},
|
2022-05-29 19:15:39 +02:00
|
|
|
mounted() {
|
|
|
|
this.$eventBus.$on(`searching-author-${this.authorId}`, this.setSearching)
|
|
|
|
},
|
|
|
|
beforeDestroy() {
|
|
|
|
this.$eventBus.$off(`searching-author-${this.authorId}`, this.setSearching)
|
|
|
|
}
|
2021-12-03 02:02:38 +01:00
|
|
|
}
|
2024-06-03 08:04:03 +02:00
|
|
|
</script>
|