Add a Show Subtitles option

This commit is contained in:
mikiher 2024-07-04 20:35:58 +03:00
parent 6b6df619f5
commit 54f2bb1092
4 changed files with 76 additions and 2 deletions

View File

@ -88,11 +88,17 @@
<ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" /> <ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" />
</template> </template>
<!-- home page -->
<template v-else-if="isHome">
<div class="flex-grow" />
<ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" />
</template>
<!-- search page --> <!-- search page -->
<template v-else-if="page === 'search'"> <template v-else-if="page === 'search'">
<div class="flex-grow" /> <div class="flex-grow" />
<p>{{ $strings.MessageSearchResultsFor }} "{{ searchQuery }}"</p> <p>{{ $strings.MessageSearchResultsFor }} "{{ searchQuery }}"</p>
<div class="flex-grow" /> <div class="flex-grow" />
<ui-context-menu-dropdown v-if="contextMenuItems.length" :items="contextMenuItems" :menu-width="110" class="ml-2" @action="contextMenuAction" />
</template> </template>
<!-- authors page --> <!-- authors page -->
<template v-else-if="page === 'authors'"> <template v-else-if="page === 'authors'">
@ -156,6 +162,8 @@ export default {
}) })
} }
this.addSubtitlesMenuItem(items)
return items return items
}, },
seriesSortItems() { seriesSortItems() {
@ -323,6 +331,8 @@ export default {
}) })
} }
this.addSubtitlesMenuItem(items)
return items return items
}, },
showPlaylists() { showPlaylists() {
@ -330,9 +340,40 @@ export default {
} }
}, },
methods: { methods: {
addSubtitlesMenuItem(items) {
if (this.isBookLibrary && (!this.page || this.page === 'search')) {
if (this.settings.showSubtitles) {
items.push({
text: 'Hide Subtitles',
action: 'hide-subtitles'
})
} else {
items.push({
text: 'Show Subtitles',
action: 'show-subtitles'
})
}
}
},
handleSubtitlesAction(action) {
if (action === 'show-subtitles') {
this.settings.showSubtitles = true
this.updateShowSubtitles()
return true
}
if (action === 'hide-subtitles') {
this.settings.showSubtitles = false
this.updateShowSubtitles()
return true
}
return false
},
contextMenuAction({ action }) { contextMenuAction({ action }) {
if (action === 'export-opml') { if (action === 'export-opml') {
this.exportOPML() this.exportOPML()
return
} else if (this.handleSubtitlesAction(action)) {
return
} }
}, },
exportOPML() { exportOPML() {
@ -353,6 +394,8 @@ export default {
return return
} }
this.markSeriesFinished() this.markSeriesFinished()
} else if (this.handleSubtitlesAction(action)) {
return
} }
}, },
showOpenSeriesRSSFeed() { showOpenSeriesRSSFeed() {
@ -482,6 +525,9 @@ export default {
updateCollapseBookSeries() { updateCollapseBookSeries() {
this.saveSettings() this.saveSettings()
}, },
updateShowSubtitles() {
this.saveSettings()
},
updateAuthorSort() { updateAuthorSort() {
this.saveSettings() this.saveSettings()
}, },

View File

@ -132,6 +132,9 @@
<widgets-explicit-indicator cy-id="explicitIndicator" v-if="isExplicit" /> <widgets-explicit-indicator cy-id="explicitIndicator" v-if="isExplicit" />
</ui-tooltip> </ui-tooltip>
</div> </div>
<ui-tooltip v-if="showSubtitles" :text="displaySubtitle" :disabled="!displaySubtitleTruncated" direction="bottom" :delayOnShow="500" class="flex items-center">
<p cy-id="subtitle" class="truncate" ref="displaySubtitle" :style="{ fontSize: 0.6 + 'em' }">{{ displaySubtitle }}</p>
</ui-tooltip>
<p cy-id="line2" class="truncate text-gray-400" :style="{ fontSize: 0.8 + 'em' }">{{ displayLineTwo || '&nbsp;' }}</p> <p cy-id="line2" class="truncate text-gray-400" :style="{ fontSize: 0.8 + 'em' }">{{ displayLineTwo || '&nbsp;' }}</p>
<p cy-id="line3" v-if="displaySortLine" class="truncate text-gray-400" :style="{ fontSize: 0.8 + 'em' }">{{ displaySortLine }}</p> <p cy-id="line3" v-if="displaySortLine" class="truncate text-gray-400" :style="{ fontSize: 0.8 + 'em' }">{{ displaySortLine }}</p>
</div> </div>
@ -171,6 +174,7 @@ export default {
selected: false, selected: false,
isSelectionMode: false, isSelectionMode: false,
displayTitleTruncated: false, displayTitleTruncated: false,
displaySubtitleTruncated: false,
showCoverBg: false showCoverBg: false
} }
}, },
@ -237,7 +241,7 @@ export default {
return this._libraryItem.mediaType return this._libraryItem.mediaType
}, },
isPodcast() { isPodcast() {
return this.mediaType === 'podcast' return this.mediaType === 'podcast' || this.store.getters['libraries/getCurrentLibraryMediaType'] === 'podcast'
}, },
isMusic() { isMusic() {
return this.mediaType === 'music' return this.mediaType === 'music'
@ -339,6 +343,13 @@ export default {
if (this.collapsedSeries) return ignorePrefix ? this.collapsedSeries.nameIgnorePrefix : this.collapsedSeries.name if (this.collapsedSeries) return ignorePrefix ? this.collapsedSeries.nameIgnorePrefix : this.collapsedSeries.name
return ignorePrefix ? this.mediaMetadata.titleIgnorePrefix : this.title || '\u00A0' return ignorePrefix ? this.mediaMetadata.titleIgnorePrefix : this.title || '\u00A0'
}, },
displaySubtitle() {
if (!this.libraryItem) return '\u00A0'
if (this.collapsedSeries) return this.collapsedSeries.numBooks === 1 ? '1 book' : `${this.collapsedSeries.numBooks} books`
if (this.mediaMetadata.subtitle) return this.mediaMetadata.subtitle
if (this.mediaMetadata.seriesName) return this.mediaMetadata.seriesName
return ''
},
displayLineTwo() { displayLineTwo() {
if (this.recentEpisode) return this.title if (this.recentEpisode) return this.title
if (this.isPodcast) return this.author if (this.isPodcast) return this.author
@ -635,6 +646,9 @@ export default {
}, },
mediaItemShare() { mediaItemShare() {
return this._libraryItem.mediaItemShare || null return this._libraryItem.mediaItemShare || null
},
showSubtitles() {
return !this.isPodcast && this.store.getters['user/getUserSetting']('showSubtitles')
} }
}, },
methods: { methods: {
@ -676,6 +690,9 @@ export default {
if (this.$refs.displayTitle) { if (this.$refs.displayTitle) {
this.displayTitleTruncated = this.$refs.displayTitle.scrollWidth > this.$refs.displayTitle.clientWidth this.displayTitleTruncated = this.$refs.displayTitle.scrollWidth > this.$refs.displayTitle.clientWidth
} }
if (this.$refs.displaySubtitle) {
this.displaySubtitleTruncated = this.$refs.displaySubtitle.scrollWidth > this.$refs.displaySubtitle.clientWidth
}
}) })
}, },
clickCard(e) { clickCard(e) {

View File

@ -11,7 +11,7 @@ function createMountOptions() {
mediaType: 'book', mediaType: 'book',
media: { media: {
id: 'book1', id: 'book1',
metadata: { title: 'The Fellowship of the Ring', titleIgnorePrefix: 'Fellowship of the Ring', authorName: 'J. R. R. Tolkien' }, metadata: { title: 'The Fellowship of the Ring', titleIgnorePrefix: 'Fellowship of the Ring', authorName: 'J. R. R. Tolkien', subtitle: 'The Lord of the Rings, Book 1' },
numTracks: 1 numTracks: 1
} }
} }
@ -138,6 +138,16 @@ describe('LazyBookCard', () => {
}) })
}) })
it('shows subtitle when showSubtitles settings is true', () => {
mountOptions.mocks.$store.getters['user/getUserSetting'] = (settingName) => {
if (settingName === 'showSubtitles') return true
}
cy.mount(LazyBookCard, mountOptions)
cy.get('&titleImageNotReady').should('be.hidden')
cy.get('&subtitle').should('be.visible').and('have.text', 'The Lord of the Rings, Book 1')
})
it('shows overlay on mouseover', () => { it('shows overlay on mouseover', () => {
cy.mount(LazyBookCard, mountOptions) cy.mount(LazyBookCard, mountOptions)
cy.get('#book-card-0').trigger('mouseover') cy.get('#book-card-0').trigger('mouseover')

View File

@ -8,6 +8,7 @@ export const state = () => ({
bookshelfCoverSize: 120, bookshelfCoverSize: 120,
collapseSeries: false, collapseSeries: false,
collapseBookSeries: false, collapseBookSeries: false,
showSubtitles: false,
useChapterTrack: false, useChapterTrack: false,
seriesSortBy: 'name', seriesSortBy: 'name',
seriesSortDesc: false, seriesSortDesc: false,