ActivityPub-federated video streaming platform using P2P directly in your web browser
Better client scroll management
Chocobozzz933be18036d3
diff --git a/client/src/app/+accounts/account-videos/account-videos.component.ts b/client/src/app/+accounts/account-videos/account-videos.component.tsindex 0a6013bea0..16a1c3e331 100644--- a/client/src/app/+accounts/account-videos/account-videos.component.ts+++ b/client/src/app/+accounts/account-videos/account-videos.component.ts@@ -6,7 +6,7 @@ import { AccountService } from '@app/shared/shared-main/account/account.service'import { VideoService } from '@app/shared/shared-main/video/video.service'import { VideoFilters } from '@app/shared/shared-video-miniature/video-filters.model'import { VideoSortField } from '@peertube/peertube-models'-import { Subscription } from 'rxjs'+import { first, Subscription } from 'rxjs'import { VideosListComponent } from '../../shared/shared-video-miniature/videos-list.component'@Component({@@ -37,6 +37,8 @@ export class AccountVideosComponent implements OnInit, OnDestroy, DisableForReus// Parent get the account for usthis.accountSub = this.accountService.accountLoaded.subscribe(account => {+ if (account.id === this.account?.id) return+this.account = accountif (this.alreadyLoaded) this.videosList().reloadVideos()diff --git a/client/src/app/+my-library/routes.ts b/client/src/app/+my-library/routes.tsindex eec6c0a1b3..178b4e1516 100644--- a/client/src/app/+my-library/routes.ts+++ b/client/src/app/+my-library/routes.ts@@ -13,6 +13,7 @@ import { LoginGuard } from '../core'import { CommentsOnMyVideosComponent } from './comments-on-my-videos/comments-on-my-videos.component'import { AutomaticTagService } from './my-auto-tag-policies/automatic-tag.service'import { MyAutoTagPoliciesComponent } from './my-auto-tag-policies/my-auto-tag-policies.component'+import { MyChannelSpaceComponent } from './my-channel-space.component'import { MyFollowersComponent } from './my-follows/my-followers.component'import { MySubscriptionsComponent } from './my-follows/my-subscriptions.component'import { MyHistoryComponent } from './my-history/my-history.component'@@ -28,7 +29,6 @@ import { MyVideoPlaylistsComponent } from './my-video-playlists/my-video-playlisimport { MyVideoSpaceComponent } from './my-video-space.component'import { MyVideosComponent } from './my-videos/my-videos.component'import { MyWatchedWordsListComponent } from './my-watched-words-list/my-watched-words-list.component'-import { MyChannelSpaceComponent } from './my-channel-space.component'const commonConfig = {path: '',@@ -93,10 +93,6 @@ const videoSpaceRoutes = [data: {meta: {title: $localize`My videos`- },- reuse: {- enabled: true,- key: 'my-videos-list'}}},diff --git a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.tsindex 8e66bf6a03..3745359307 100644--- a/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts+++ b/client/src/app/+video-channels/video-channel-videos/video-channel-videos.component.ts@@ -48,6 +48,8 @@ export class VideoChannelVideosComponent implements OnInit, AfterViewInit, OnDes// Parent get the video channel for usthis.videoChannelSub = this.videoChannelService.videoChannelLoaded.subscribe(videoChannel => {+ if (this.videoChannel?.id === videoChannel.id) return+this.videoChannel = videoChannelif (this.alreadyLoaded) this.videosList().reloadVideos()diff --git a/client/src/app/+video-list/overview/video-overview.component.html b/client/src/app/+video-list/overview/video-overview.component.htmlindex 330c054321..e1d3ba7c43 100644--- a/client/src/app/+video-list/overview/video-overview.component.html+++ b/client/src/app/+video-list/overview/video-overview.component.html@@ -18,7 +18,7 @@<divclass="margin-content videos-margin-content"myInfiniteScroller (nearOfBottom)="onNearOfBottom()"- [dataObservable]="onDataSubject.asObservable()" setAngularState="true" [parentDisabled]="disabled"+ [dataObservable]="onDataSubject.asObservable()"><div class="section videos" *ngFor="let object of objects">diff --git a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.tsindex 18e9052794..02a3256717 100644--- a/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts+++ b/client/src/app/+videos-publish-manage/shared-manage/main-info/video-main-info.component.ts@@ -45,7 +45,6 @@ import { forkJoin, Subscription } from 'rxjs'import { map } from 'rxjs/operators'import { SelectChannelItem } from 'src/types/select-options-item.model'import { GlobalIconComponent } from '../../../shared/shared-icons/global-icon.component'-import { DeleteButtonComponent } from '../../../shared/shared-main/buttons/delete-button.component'import { MarkdownHintComponent } from '../../../shared/shared-main/text/markdown-hint.component'import { I18nPrimengCalendarService } from '../common/i18n-primeng-calendar.service'import { ThumbnailManagerComponent } from '../common/thumbnail-manager.component'@@ -100,8 +99,7 @@ type Form = {ThumbnailManagerComponent,GlobalIconComponent,MarkdownHintComponent,- RouterLink,- DeleteButtonComponent+ RouterLink]})export class VideoMainInfoComponent implements OnInit, OnDestroy {diff --git a/client/src/app/core/routing/custom-reuse-strategy.ts b/client/src/app/core/routing/custom-reuse-strategy.tsindex 269b9d193a..326a00a72b 100644--- a/client/src/app/core/routing/custom-reuse-strategy.ts+++ b/client/src/app/core/routing/custom-reuse-strategy.ts@@ -2,7 +2,6 @@ import { ComponentRef, Injectable } from '@angular/core'import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router'import { logger } from '@root-helpers/logger'import { DisableForReuseHook } from './disable-for-reuse-hook'-import { PeerTubeRouterService, RouterSetting } from './peertube-router.service'@Injectable()export class CustomReuseStrategy implements RouteReuseStrategy {@@ -50,9 +49,8 @@ export class CustomReuseStrategy implements RouteReuseStrategy {logger.info(`Reusing component ${key}.`)const handle = this.storedRouteHandles.get(key)- if (!handle) return handle;-- (handle as any).componentRef.instance.enabledForReuse()+ if (!handle) return handle+ ;(handle as any).componentRef.instance.enabledForReuse()return handle}@@ -67,9 +65,8 @@ export class CustomReuseStrategy implements RouteReuseStrategy {this.storedRouteHandles.forEach((r, key) => {if (key === this.recentlyUsed) return- logger.info(`Removing stored component ${key}`);-- (r as any).componentRef.destroy()+ logger.info(`Removing stored component ${key}`)+ ;(r as any).componentRef.destroy()this.storedRouteHandles.delete(key)})}@@ -84,7 +81,6 @@ export class CustomReuseStrategy implements RouteReuseStrategy {private isReuseEnabled (route: ActivatedRouteSnapshot) {// Cannot use peertube router here because of cyclic router dependency- return route.data.reuse?.enabled &&- !!(route.queryParams[PeerTubeRouterService.ROUTE_SETTING_NAME] & RouterSetting.REUSE_COMPONENT)+ return route.data.reuse?.enabled}}diff --git a/client/src/app/core/routing/peertube-router.service.ts b/client/src/app/core/routing/peertube-router.service.tsindex 5e158a13ce..5ea78bb75c 100644--- a/client/src/app/core/routing/peertube-router.service.ts+++ b/client/src/app/core/routing/peertube-router.service.ts@@ -1,11 +1,10 @@import { Injectable, inject } from '@angular/core'-import { ActivatedRoute, ActivatedRouteSnapshot, Event, NavigationEnd, Params, Router, Scroll } from '@angular/router'+import { ActivatedRoute, Event, NavigationEnd, Params, Router, Scroll } from '@angular/router'import { filter } from 'rxjs/operators'import { ServerService } from '../server'export const enum RouterSetting {NONE = 0,- REUSE_COMPONENT = 1 << 0,DISABLE_SCROLL_RESTORE = 1 << 1}@@ -15,39 +14,6 @@ export class PeerTubeRouterService {private router = inject(Router)private server = inject(ServerService)- static readonly ROUTE_SETTING_NAME = 's'-- addRouteSetting (toAdd: RouterSetting) {- if (this.hasRouteSetting(toAdd)) return-- const current = this.getRouteSetting()-- this.setRouteSetting(current | toAdd)- }-- deleteRouteSetting (toDelete: RouterSetting) {- const current = this.getRouteSetting()-- this.setRouteSetting(current & ~toDelete)- }-- getRouteSetting (snapshot?: ActivatedRouteSnapshot) {- return (snapshot || this.route.snapshot).queryParams[PeerTubeRouterService.ROUTE_SETTING_NAME]- }-- setRouteSetting (value: number) {- let path = window.location.pathname- if (!path || path === '/') path = this.server.getHTMLConfig().instance.defaultClientRoute-- const queryParams = { [PeerTubeRouterService.ROUTE_SETTING_NAME]: value }-- this.router.navigate([ path ], { queryParams, replaceUrl: true, queryParamsHandling: 'merge' })- }-- hasRouteSetting (setting: RouterSetting, snapshot?: ActivatedRouteSnapshot) {- return !!(this.getRouteSetting(snapshot) & setting)- }-getNavigationEndEvents () {return this.router.events.pipe(filter((e: Event): e is NavigationEnd => e instanceof NavigationEnd)@@ -60,16 +26,20 @@ export class PeerTubeRouterService {)}+ // ---------------------------------------------------------------------------++ hasRouteSetting (setting: RouterSetting) {+ return !!(this.getRouteSetting() & setting)+ }+silentNavigate (baseRoute: string[], existingParams: Params, relativeTo?: ActivatedRoute) {let routeSetting = this.getRouteSetting() ?? RouterSetting.NONErouteSetting |= RouterSetting.DISABLE_SCROLL_RESTORE- const queryParams = {- ...existingParams,-- [PeerTubeRouterService.ROUTE_SETTING_NAME]: routeSetting- }+ return this.router.navigate(baseRoute, { queryParams: existingParams, relativeTo, state: { routeSetting } })+ }- return this.router.navigate(baseRoute, { queryParams, relativeTo })+ private getRouteSetting () {+ return this.router.getCurrentNavigation()?.extras?.state?.routeSetting as RouterSetting}}diff --git a/client/src/app/core/routing/scroll.service.ts b/client/src/app/core/routing/scroll.service.tsindex c2a31ee485..1642a71350 100644--- a/client/src/app/core/routing/scroll.service.ts+++ b/client/src/app/core/routing/scroll.service.ts@@ -1,10 +1,10 @@+import { ViewportScroller } from '@angular/common'+import { ApplicationRef, Injectable, inject } from '@angular/core'+import { logger } from '@root-helpers/logger'import debug from 'debug'import { pairwise } from 'rxjs'-import { ViewportScroller } from '@angular/common'-import { Injectable, inject } from '@angular/core'import { RouterSetting } from '../'import { PeerTubeRouterService } from './peertube-router.service'-import { logger } from '@root-helpers/logger'const debugLogger = debug('peertube:main:ScrollService')@@ -12,6 +12,7 @@ const debugLogger = debug('peertube:main:ScrollService')export class ScrollService {private viewportScroller = inject(ViewportScroller)private peertubeRouter = inject(PeerTubeRouterService)+ private appRef = inject(ApplicationRef)private resetScroll = true@@ -34,25 +35,29 @@ export class ScrollService {const nextUrl = new URL(window.location.origin + e2.urlAfterRedirects)if (previousUrl.pathname !== nextUrl.pathname) {+ debugLogger('Schedule reset scroll after pathname change', { previousUrl, nextUrl })+this.resetScroll = truereturn}if (this.peertubeRouter.hasRouteSetting(RouterSetting.DISABLE_SCROLL_RESTORE)) {+ debugLogger('Do not reset scroll after because router state disabled scroll restore')+this.resetScroll = falsereturn}// Remove route settings from the comparisonconst nextSearchParams = nextUrl.searchParams- nextSearchParams.delete(PeerTubeRouterService.ROUTE_SETTING_NAME)-const previousSearchParams = previousUrl.searchParamsnextSearchParams.sort()previousSearchParams.sort()if (nextSearchParams.toString() !== previousSearchParams.toString()) {+ debugLogger('Schedule reset scroll after search params change', { previousUrl, nextUrl })+this.resetScroll = true}} catch (err) {@@ -65,10 +70,10 @@ export class ScrollService {private consumeScroll () {// Handle anchors/restore positionthis.peertubeRouter.getScrollEvents().subscribe(e => {- debugLogger('Will schedule scroll after router event %o.', { e, resetScroll: this.resetScroll })-// scrollToAnchor first to preserve anchor position when using history navigationif (e.anchor) {+ debugLogger('Scroll to anchor.', { e, resetScroll: this.resetScroll })+setTimeout(() => this.viewportScroller.scrollToAnchor(e.anchor))return@@ -81,6 +86,8 @@ export class ScrollService {}if (this.resetScroll) {+ debugLogger('Reset scroll.', { e, resetScroll: this.resetScroll })+return this.viewportScroller.scrollToPosition([ 0, 0 ])}})diff --git a/client/src/app/shared/shared-main/common/infinite-scroller.directive.ts b/client/src/app/shared/shared-main/common/infinite-scroller.directive.tsindex 164a8de874..bc04381ae2 100644--- a/client/src/app/shared/shared-main/common/infinite-scroller.directive.ts+++ b/client/src/app/shared/shared-main/common/infinite-scroller.directive.ts@@ -1,5 +1,5 @@-import { AfterViewChecked, booleanAttribute, Directive, ElementRef, OnDestroy, OnInit, inject, input, output } from '@angular/core'-import { PeerTubeRouterService, RouterSetting } from '@app/core'+import { AfterViewChecked, booleanAttribute, Directive, ElementRef, inject, input, OnDestroy, OnInit, output } from '@angular/core'+import { PeerTubeRouterService } from '@app/core'import { fromEvent, Observable, Subscription } from 'rxjs'import { distinctUntilChanged, filter, map, share, startWith, throttleTime } from 'rxjs/operators'@@ -13,13 +13,8 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy, AfterViewChreadonly percentLimit = input(70)readonly onItself = input(false, { transform: booleanAttribute })- // Add angular state in query params to reuse the routed componentreadonly dataObservable = input<Observable<any[]>>(undefined)- // Add angular state in query params to reuse the routed component- readonly setAngularState = input<boolean, unknown>(undefined, { transform: booleanAttribute })- readonly parentDisabled = input(false)-readonly nearOfBottom = output()private decimalLimit = 0@@ -77,8 +72,6 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy, AfterViewChfilter(({ current, maximumScroll }) => (current / maximumScroll) > this.decimalLimit)).subscribe(() => {- if (this.setAngularState() && !this.parentDisabled()) this.setScrollRouteParams()-this.nearOfBottom.emit()})@@ -110,8 +103,4 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy, AfterViewChthis.lastCurrentBottom = currentreturn result}-- private setScrollRouteParams () {- this.peertubeRouter.addRouteSetting(RouterSetting.REUSE_COMPONENT)- }}diff --git a/client/src/app/shared/shared-video-miniature/videos-list.component.html b/client/src/app/shared/shared-video-miniature/videos-list.component.htmlindex 118ee2bd6a..d5a49e0ff5 100644--- a/client/src/app/shared/shared-video-miniature/videos-list.component.html+++ b/client/src/app/shared/shared-video-miniature/videos-list.component.html@@ -19,7 +19,6 @@<divmyInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onVideosDataSubject.asObservable()"- [setAngularState]="true" [parentDisabled]="disabled()"class="videos" [ngClass]="{ 'display-as-row': displayAsRow() }"><ng-container *ngIf="highlightedLives.length !== 0">diff --git a/client/src/app/shared/shared-video-miniature/videos-selection.component.html b/client/src/app/shared/shared-video-miniature/videos-selection.component.htmlindex 401433deef..5618c1d0e7 100644--- a/client/src/app/shared/shared-video-miniature/videos-selection.component.html+++ b/client/src/app/shared/shared-video-miniature/videos-selection.component.html@@ -3,7 +3,6 @@<divclass="videos"myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()"- [parentDisabled]="disabled()" [setAngularState]="true"><div class="video" *ngFor="let video of videos(); let i = index; trackBy: videoById">