Skip to content

Commit

Permalink
fix(webui): scrolling position was not restored properly
Browse files Browse the repository at this point in the history
  • Loading branch information
gotson committed Jan 30, 2020
1 parent 2ded39f commit be6a7fc
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 20 deletions.
42 changes: 30 additions & 12 deletions komga-webui/src/views/BrowseLibraries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ export default mixins(VisibleElements).extend({
sortDefault: { key: 'name', order: 'asc' } as SortActive,
filterStatus: [] as string[],
SeriesStatus,
cardWidth: 150
cardWidth: 150,
sortUnwatch: null as any,
filterUnwatch: null as any
}
},
props: {
Expand All @@ -118,14 +120,6 @@ export default mixins(VisibleElements).extend({
}
},
watch: {
filterStatus () {
this.updateRoute()
this.reloadData(this.libraryId)
},
sortActive () {
this.updateRoute()
this.reloadData(this.libraryId)
},
async visibleElements (val) {
for (const i of val) {
const pageNumber = Math.floor(i / this.pageSize)
Expand Down Expand Up @@ -158,18 +152,42 @@ export default mixins(VisibleElements).extend({
// restore filter status from query params
this.filterStatus = this.parseQueryFilterStatus(this.$route.query.status)
this.setWatches()
},
beforeRouteUpdate (to, from, next) {
if (to.params.libraryId !== from.params.libraryId) {
this.unsetWatches()
this.library = this.getLibraryLazy(Number(to.params.libraryId))
if (to.params.index) {
this.series = Array(Number(to.params.index)).fill(null)
} else { // else fill one page of skeletons
this.series = Array(this.pageSize).fill(null)
}
this.sortActive = this.parseQuerySortOrDefault(to.query.sort)
this.filterStatus = this.parseQueryFilterStatus(to.query.status)
this.reloadData(Number(to.params.libraryId))
this.reloadData(Number(to.params.libraryId), this.series.length)
this.setWatches()
}
next()
},
methods: {
setWatches () {
this.sortUnwatch = this.$watch('sortActive', this.updateRouteAndReload)
this.filterUnwatch = this.$watch('filterStatus', this.updateRouteAndReload)
},
unsetWatches () {
this.sortUnwatch()
this.filterUnwatch()
},
updateRouteAndReload () {
this.updateRoute()
this.reloadData(this.libraryId)
},
updateCardWidth () {
const content = this.$refs.content as HTMLElement
this.cardWidth = computeCardWidth(content.clientWidth, this.$vuetify.breakpoint.name)
Expand All @@ -180,11 +198,11 @@ export default mixins(VisibleElements).extend({
parseQueryFilterStatus (queryStatus: any): string[] {
return queryStatus ? queryStatus.toString().split(',').filter((x: string) => Object.keys(SeriesStatus).includes(x)) : []
},
reloadData (libraryId: number) {
reloadData (libraryId: number, countItem?: number) {
this.totalElements = null
this.pagesState = []
this.visibleElements = []
this.series = Array(this.pageSize).fill(null)
this.series = Array(countItem || this.pageSize).fill(null)
this.loadInitialData(libraryId)
},
updateRoute (index?: string) {
Expand Down
36 changes: 28 additions & 8 deletions komga-webui/src/views/BrowseSeries.vue
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ export default mixins(VisibleElements).extend({
sortActive: {} as SortActive,
sortDefault: { key: 'number', order: 'asc' } as SortActive,
cardWidth: 150,
dialogEdit: false
dialogEdit: false,
sortUnwatch: null as any
}
},
computed: {
Expand All @@ -144,10 +145,6 @@ export default mixins(VisibleElements).extend({
}
},
watch: {
sortActive () {
this.updateRoute()
this.reloadData(this.seriesId)
},
async visibleElements (val) {
for (const i of val) {
const pageNumber = Math.floor(i / this.pageSize)
Expand Down Expand Up @@ -182,17 +179,40 @@ export default mixins(VisibleElements).extend({
// restore sort from query param
this.sortActive = this.parseQuerySortOrDefault(this.$route.query.sort)
this.setWatches()
},
async beforeRouteUpdate (to, from, next) {
if (to.params.seriesId !== from.params.seriesId) {
this.unsetWatches()
this.series = await this.$komgaSeries.getOneSeries(Number(to.params.seriesId))
if (to.params.index) {
this.books = Array(Number(to.params.index)).fill(null)
} else { // else fill one page of skeletons
this.books = Array(this.pageSize).fill(null)
}
this.sortActive = this.parseQuerySortOrDefault(to.query.sort)
this.reloadData(Number(to.params.seriesId))
this.reloadData(Number(to.params.seriesId), this.books.length)
this.setWatches()
}
next()
},
methods: {
setWatches () {
this.sortUnwatch = this.$watch('sortActive', this.updateRouteAndReload)
},
unsetWatches () {
this.sortUnwatch()
},
updateRouteAndReload () {
this.updateRoute()
this.reloadData(this.seriesId)
},
async loadSeries () {
this.series = await this.$komgaSeries.getOneSeries(this.seriesId)
},
Expand All @@ -213,11 +233,11 @@ export default mixins(VisibleElements).extend({
}).catch(_ => {
})
},
reloadData (seriesId: number) {
reloadData (seriesId: number, countItem?: number) {
this.totalElements = null
this.pagesState = []
this.visibleElements = []
this.books = Array(this.pageSize).fill(null)
this.books = Array(countItem || this.pageSize).fill(null)
this.loadInitialData(seriesId)
},
async loadInitialData (seriesId: number, pageToLoad: number = 0) {
Expand Down

0 comments on commit be6a7fc

Please sign in to comment.