mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-10-03 09:49:20 +02:00
Restore scroll position after homepage redirect
This commit is contained in:
parent
24a0d7fd00
commit
59d5f28ed6
4 changed files with 44 additions and 3 deletions
|
@ -1,13 +1,17 @@
|
||||||
import { Component, ElementRef, OnInit, inject, viewChild } from '@angular/core'
|
import { Component, ElementRef, inject, OnDestroy, OnInit, viewChild } from '@angular/core'
|
||||||
|
import { DisableForReuseHook, PeerTubeRouterService } from '@app/core'
|
||||||
import { CustomPageService } from '@app/shared/shared-main/custom-page/custom-page.service'
|
import { CustomPageService } from '@app/shared/shared-main/custom-page/custom-page.service'
|
||||||
|
import { debounceTime, fromEvent, Subscription } from 'rxjs'
|
||||||
import { CustomMarkupContainerComponent } from '../shared/shared-custom-markup/custom-markup-container.component'
|
import { CustomMarkupContainerComponent } from '../shared/shared-custom-markup/custom-markup-container.component'
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
templateUrl: './home.component.html',
|
templateUrl: './home.component.html',
|
||||||
imports: [ CustomMarkupContainerComponent ]
|
imports: [ CustomMarkupContainerComponent ]
|
||||||
})
|
})
|
||||||
export class HomeComponent implements OnInit {
|
export class HomeComponent implements OnInit, OnDestroy, DisableForReuseHook {
|
||||||
private customPageService = inject(CustomPageService)
|
private customPageService = inject(CustomPageService)
|
||||||
|
private sub: Subscription
|
||||||
|
private peertubeRouter = inject(PeerTubeRouterService)
|
||||||
|
|
||||||
readonly contentWrapper = viewChild<ElementRef<HTMLInputElement>>('contentWrapper')
|
readonly contentWrapper = viewChild<ElementRef<HTMLInputElement>>('contentWrapper')
|
||||||
|
|
||||||
|
@ -16,5 +20,29 @@ export class HomeComponent implements OnInit {
|
||||||
ngOnInit () {
|
ngOnInit () {
|
||||||
this.customPageService.getInstanceHomepage()
|
this.customPageService.getInstanceHomepage()
|
||||||
.subscribe(({ content }) => this.homepageContent = content)
|
.subscribe(({ content }) => this.homepageContent = content)
|
||||||
|
|
||||||
|
// If this has been a redirection from the homepage,
|
||||||
|
// replace the URL on scroll to correctly restore scroll position on web browser back button
|
||||||
|
if (window.location.pathname === '/') {
|
||||||
|
this.sub = fromEvent(window, 'scroll')
|
||||||
|
.pipe(debounceTime(250))
|
||||||
|
.subscribe(() => {
|
||||||
|
if (window.pageYOffset > 300) {
|
||||||
|
this.peertubeRouter.silentNavigate([], {})
|
||||||
|
this.sub.unsubscribe()
|
||||||
|
this.sub = undefined
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ngOnDestroy () {
|
||||||
|
if (this.sub) this.sub.unsubscribe()
|
||||||
|
}
|
||||||
|
|
||||||
|
disableForReuse () {
|
||||||
|
}
|
||||||
|
|
||||||
|
enabledForReuse () {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,10 @@ export default [
|
||||||
data: {
|
data: {
|
||||||
meta: {
|
meta: {
|
||||||
title: $localize`Homepage`
|
title: $localize`Homepage`
|
||||||
|
},
|
||||||
|
reuse: {
|
||||||
|
enabled: true,
|
||||||
|
key: 'home'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import { CommonModule } from '@angular/common'
|
import { CommonModule } from '@angular/common'
|
||||||
import { AfterViewChecked, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, inject, viewChild } from '@angular/core'
|
import { AfterViewChecked, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, inject, viewChild } from '@angular/core'
|
||||||
import { RouterLink } from '@angular/router'
|
import { RouterLink } from '@angular/router'
|
||||||
import { DisableForReuseHook, Notifier, ServerService, User, UserService } from '@app/core'
|
import { DisableForReuseHook, Notifier, PeerTubeRouterService, ServerService, User, UserService } from '@app/core'
|
||||||
import { ActorAvatarComponent, ActorAvatarInput } from '@app/shared/shared-actor-image/actor-avatar.component'
|
import { ActorAvatarComponent, ActorAvatarInput } from '@app/shared/shared-actor-image/actor-avatar.component'
|
||||||
import { ButtonComponent } from '@app/shared/shared-main/buttons/button.component'
|
import { ButtonComponent } from '@app/shared/shared-main/buttons/button.component'
|
||||||
import { InfiniteScrollerDirective } from '@app/shared/shared-main/common/infinite-scroller.directive'
|
import { InfiniteScrollerDirective } from '@app/shared/shared-main/common/infinite-scroller.directive'
|
||||||
|
@ -29,6 +29,7 @@ export class VideoOverviewComponent implements OnInit, OnDestroy, AfterViewCheck
|
||||||
private overviewService = inject(OverviewService)
|
private overviewService = inject(OverviewService)
|
||||||
private cd = inject(ChangeDetectorRef)
|
private cd = inject(ChangeDetectorRef)
|
||||||
private server = inject(ServerService)
|
private server = inject(ServerService)
|
||||||
|
private peertubeRouter = inject(PeerTubeRouterService)
|
||||||
|
|
||||||
readonly quickAccessContent = viewChild<ElementRef>('quickAccessContent')
|
readonly quickAccessContent = viewChild<ElementRef>('quickAccessContent')
|
||||||
|
|
||||||
|
@ -111,6 +112,10 @@ export class VideoOverviewComponent implements OnInit, OnDestroy, AfterViewCheck
|
||||||
if (this.isLoading) return
|
if (this.isLoading) return
|
||||||
if (this.disabled) return
|
if (this.disabled) return
|
||||||
|
|
||||||
|
if (window.location.pathname === '/') {
|
||||||
|
this.peertubeRouter.silentNavigate([], {})
|
||||||
|
}
|
||||||
|
|
||||||
this.currentPage++
|
this.currentPage++
|
||||||
this.loadMoreResults()
|
this.loadMoreResults()
|
||||||
}
|
}
|
||||||
|
|
|
@ -206,6 +206,10 @@ export class VideosListComponent implements OnInit, OnDestroy {
|
||||||
onNearOfBottom () {
|
onNearOfBottom () {
|
||||||
if (this.disabled()) return
|
if (this.disabled()) return
|
||||||
|
|
||||||
|
if (window.location.pathname === '/') {
|
||||||
|
this.peertubeRouter.silentNavigate([], this.route.snapshot.queryParams)
|
||||||
|
}
|
||||||
|
|
||||||
// No more results
|
// No more results
|
||||||
if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return
|
if (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue