ActivityPub-federated video streaming platform using P2P directly in your web browser
Restore scroll position after homepage redirect
Chocobozzz59d5f28ed656
diff --git a/client/src/app/+home/home.component.ts b/client/src/app/+home/home.component.tsindex 0d320cf84f..faf4110788 100644--- a/client/src/app/+home/home.component.ts+++ b/client/src/app/+home/home.component.ts@@ -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 { debounceTime, fromEvent, Subscription } from 'rxjs'import { CustomMarkupContainerComponent } from '../shared/shared-custom-markup/custom-markup-container.component'@Component({templateUrl: './home.component.html',imports: [ CustomMarkupContainerComponent ]})-export class HomeComponent implements OnInit {+export class HomeComponent implements OnInit, OnDestroy, DisableForReuseHook {private customPageService = inject(CustomPageService)+ private sub: Subscription+ private peertubeRouter = inject(PeerTubeRouterService)readonly contentWrapper = viewChild<ElementRef<HTMLInputElement>>('contentWrapper')@@ -16,5 +20,29 @@ export class HomeComponent implements OnInit {ngOnInit () {this.customPageService.getInstanceHomepage().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 () {}}diff --git a/client/src/app/+home/routes.ts b/client/src/app/+home/routes.tsindex c4f18f5cfe..e5b60dd0d8 100644--- a/client/src/app/+home/routes.ts+++ b/client/src/app/+home/routes.ts@@ -28,6 +28,10 @@ export default [data: {meta: {title: $localize`Homepage`+ },+ reuse: {+ enabled: true,+ key: 'home'}}}diff --git a/client/src/app/+video-list/overview/video-overview.component.ts b/client/src/app/+video-list/overview/video-overview.component.tsindex 4197c6a5bb..6e577c2bbc 100644--- a/client/src/app/+video-list/overview/video-overview.component.ts+++ b/client/src/app/+video-list/overview/video-overview.component.ts@@ -1,7 +1,7 @@import { CommonModule } from '@angular/common'import { AfterViewChecked, ChangeDetectorRef, Component, ElementRef, OnDestroy, OnInit, inject, viewChild } from '@angular/core'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 { ButtonComponent } from '@app/shared/shared-main/buttons/button.component'import { InfiniteScrollerDirective } from '@app/shared/shared-main/common/infinite-scroller.directive'@@ -29,6 +29,7 @@ export class VideoOverviewComponent implements OnInit, OnDestroy, AfterViewCheckprivate overviewService = inject(OverviewService)private cd = inject(ChangeDetectorRef)private server = inject(ServerService)+ private peertubeRouter = inject(PeerTubeRouterService)readonly quickAccessContent = viewChild<ElementRef>('quickAccessContent')@@ -111,6 +112,10 @@ export class VideoOverviewComponent implements OnInit, OnDestroy, AfterViewCheckif (this.isLoading) returnif (this.disabled) return+ if (window.location.pathname === '/') {+ this.peertubeRouter.silentNavigate([], {})+ }+this.currentPage++this.loadMoreResults()}diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.ts b/client/src/app/shared/shared-video-miniature/videos-list.component.tsindex 1ce82784e1..33b84db7ca 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.ts+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.ts@@ -206,6 +206,10 @@ export class VideosListComponent implements OnInit, OnDestroy {onNearOfBottom () {if (this.disabled()) return+ if (window.location.pathname === '/') {+ this.peertubeRouter.silentNavigate([], this.route.snapshot.queryParams)+ }+// No more resultsif (this.lastQueryLength !== undefined && this.lastQueryLength < this.pagination.itemsPerPage) return