Skip to content

Commit

Permalink
feat(webui): add series and book title in page title and reader overlay
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Feb 25, 2020
1 parent f7390f0 commit 6b1998c
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 28 deletions.
7 changes: 7 additions & 0 deletions komga-webui/src/functions/book-title.ts
@@ -0,0 +1,7 @@
export function getBookTitleCompact (bookTitle: string, seriesTitle: string): string {
if (bookTitle?.toLowerCase().includes(seriesTitle?.toLowerCase())) {
return bookTitle
} else {
return `${seriesTitle} - ${bookTitle}`
}
}
11 changes: 0 additions & 11 deletions komga-webui/src/functions/meta-utilities.ts

This file was deleted.

4 changes: 3 additions & 1 deletion komga-webui/src/router.ts
Expand Up @@ -124,7 +124,9 @@ const router = new Router({
})

router.beforeEach((to, from, next) => {
document.title = 'Komga'
if (!['read-book', 'browse-book', 'browse-series'].includes(<string>to.name)) {
document.title = 'Komga'
}
if (to.name !== 'startup' && to.name !== 'login' && !lStore.getters.authenticated) next({ name: 'startup' })
else next()
})
Expand Down
25 changes: 19 additions & 6 deletions komga-webui/src/views/BookReader.vue
Expand Up @@ -92,6 +92,13 @@
class="pa-6 pt-12"
style="border-bottom: 4px dashed"
>
<!-- Menu: book title -->
<v-row>
<v-col class="text-center title">
{{ bookTitle }}
</v-col>
</v-row>

<!-- Menu: number of pages -->
<v-row>
<v-col class="text-center title">
Expand Down Expand Up @@ -311,7 +318,7 @@ import { checkWebpFeature } from '@/functions/check-webp'
import { bookPageThumbnailUrl, bookPageUrl } from '@/functions/urls'
import { ImageFit } from '@/types/common'
import Vue from 'vue'
import { getBookTitle } from '@/functions/meta-utilities'
import { getBookTitleCompact } from '@/functions/book-title'
const cookieFit = 'webreader.fit'
const cookieRtl = 'webreader.rtl'
Expand All @@ -323,6 +330,7 @@ export default Vue.extend({
return {
ImageFit,
book: {} as BookDto,
series: {} as SeriesDto,
siblingPrevious: {} as BookDto,
siblingNext: {} as BookDto,
jumpToNextBook: false,
Expand Down Expand Up @@ -389,6 +397,12 @@ export default Vue.extend({
currentPage (val) {
this.updateRoute()
this.goToPage = val
},
async book (val) {
if (this.$_.has(val, 'name')) {
this.series = await this.$komgaSeries.getOneSeries(val.seriesId)
document.title = `Komga - ${getBookTitleCompact(val.name, this.series.name)}`
}
}
},
computed: {
Expand Down Expand Up @@ -425,6 +439,9 @@ export default Vue.extend({
},
pagesCount (): number {
return this.pages.length
},
bookTitle (): string {
return getBookTitleCompact(this.book.name, this.series.name)
}
},
methods: {
Expand Down Expand Up @@ -458,7 +475,6 @@ export default Vue.extend({
async setup (bookId: number, page: number) {
this.book = await this.$komgaBooks.getBook(bookId)
this.pages = await this.$komgaBooks.getBookPages(bookId)
this.updateTitle()
if (page >= 1 && page <= this.pagesCount) {
this.goTo(page)
} else {
Expand Down Expand Up @@ -493,6 +509,7 @@ export default Vue.extend({
} else {
if (this.jumpToPreviousBook) {
if (!this.$_.isEmpty(this.siblingPrevious)) {
console.log(this.siblingPrevious)
this.jumpToPreviousBook = false
this.$router.push({ name: 'read-book', params: { bookId: this.siblingPrevious.id.toString() } })
}
Expand Down Expand Up @@ -536,10 +553,6 @@ export default Vue.extend({
}
})
},
async updateTitle () {
let title: string = await getBookTitle(this.$komgaSeries, this.book)
document.title = `Komga - ${title}`
},
closeBook () {
this.$router.push({ name: 'browse-book', params: { bookId: this.bookId.toString() } })
},
Expand Down
18 changes: 11 additions & 7 deletions komga-webui/src/views/BrowseBook.vue
Expand Up @@ -128,19 +128,27 @@ import ToolbarSticky from '@/components/ToolbarSticky.vue'
import { getBookFormatFromMediaType } from '@/functions/book-format'
import { bookFileUrl, bookThumbnailUrl } from '@/functions/urls'
import Vue from 'vue'
import { getBookTitle } from '@/functions/meta-utilities'
import { getBookTitleCompact } from '@/functions/book-title'
export default Vue.extend({
name: 'BrowseBook',
components: { ToolbarSticky },
data: () => {
return {
book: {} as BookDto
book: {} as BookDto,
series: {} as SeriesDto
}
},
async created () {
this.book = await this.$komgaBooks.getBook(this.bookId)
this.updateTitle()
},
watch: {
async book (val) {
if (this.$_.has(val, 'name')) {
this.series = await this.$komgaSeries.getOneSeries(val.seriesId)
document.title = `Komga - ${getBookTitleCompact(val.name, this.series.name)}`
}
}
},
props: {
bookId: {
Expand Down Expand Up @@ -172,10 +180,6 @@ export default Vue.extend({
methods: {
analyze () {
this.$komgaBooks.analyzeBook(this.book)
},
async updateTitle () {
let title: string = await getBookTitle(this.$komgaSeries, this.book)
document.title = `Komga - ${title}`
}
}
})
Expand Down
10 changes: 7 additions & 3 deletions komga-webui/src/views/BrowseSeries.vue
Expand Up @@ -159,12 +159,17 @@ export default mixins(VisibleElements).extend({
if (this.$route.params.index !== index) {
this.updateRoute(index)
}
},
series (val) {
if (this.$_.has(val, 'name')) {
document.title = `Komga - ${val.name}`
}
}
},
async created () {
this.loadSeries()
},
async mounted () {
mounted () {
// fill books skeletons if an index is provided, so scroll position can be restored
if (this.$route.params.index) {
this.books = Array(Number(this.$route.params.index)).fill(null)
Expand All @@ -178,8 +183,7 @@ export default mixins(VisibleElements).extend({
this.reloadData(Number(this.$route.params.seriesId), this.books.length)
this.setWatches()
await this.loadSeries()
document.title = `Komga - ${this.series.name}`
this.loadSeries()
},
async beforeRouteUpdate (to, from, next) {
if (to.params.seriesId !== from.params.seriesId) {
Expand Down

0 comments on commit 6b1998c

Please sign in to comment.