Correctly disable infinite scroll for reuse

pull/4461/head
Chocobozzz 2021-10-08 15:59:05 +02:00
parent 9db2330e4a
commit 0af2a8c5d6
No known key found for this signature in database
GPG Key ID: 583A612D890159BE
4 changed files with 13 additions and 8 deletions

View File

@ -1,7 +1,7 @@
import { Injectable } from '@angular/core' import { ComponentRef, Injectable } from '@angular/core'
import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router' import { ActivatedRouteSnapshot, DetachedRouteHandle, RouteReuseStrategy } from '@angular/router'
import { RouterSetting } from './' import { DisableForReuseHook } from './disable-for-reuse-hook'
import { PeerTubeRouterService } from './peertube-router.service' import { PeerTubeRouterService, RouterSetting } from './peertube-router.service'
@Injectable() @Injectable()
export class CustomReuseStrategy implements RouteReuseStrategy { export class CustomReuseStrategy implements RouteReuseStrategy {
@ -22,9 +22,11 @@ export class CustomReuseStrategy implements RouteReuseStrategy {
const key = this.generateKey(route) const key = this.generateKey(route)
this.recentlyUsed = key this.recentlyUsed = key
console.log('Storing component %s to reuse later.', key); console.log('Storing component %s to reuse later.', key)
(handle as any).componentRef.instance.disableForReuse() const componentRef = (handle as any).componentRef as ComponentRef<DisableForReuseHook>
componentRef.instance.disableForReuse()
componentRef.changeDetectorRef.detectChanges()
this.storedRouteHandles.set(key, handle) this.storedRouteHandles.set(key, handle)

View File

@ -13,6 +13,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy, AfterViewCh
// Add angular state in query params to reuse the routed component // Add angular state in query params to reuse the routed component
@Input() setAngularState: boolean @Input() setAngularState: boolean
@Input() parentDisabled = false
@Output() nearOfBottom = new EventEmitter<void>() @Output() nearOfBottom = new EventEmitter<void>()
@ -74,7 +75,7 @@ export class InfiniteScrollerDirective implements OnInit, OnDestroy, AfterViewCh
filter(({ current, maximumScroll }) => (current / maximumScroll) > this.decimalLimit) filter(({ current, maximumScroll }) => (current / maximumScroll) > this.decimalLimit)
) )
.subscribe(() => { .subscribe(() => {
if (this.setAngularState) this.setScrollRouteParams() if (this.setAngularState && !this.parentDisabled) this.setScrollRouteParams()
this.nearOfBottom.emit() this.nearOfBottom.emit()
}) })

View File

@ -40,7 +40,8 @@
<div class="no-results" i18n *ngIf="hasDoneFirstQuery && videos.length === 0">No results.</div> <div class="no-results" i18n *ngIf="hasDoneFirstQuery && videos.length === 0">No results.</div>
<div <div
myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()" [setAngularState]="true" myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()"
[setAngularState]="true" [parentDisabled]="disabled"
class="videos" [ngClass]="{ 'display-as-row': displayAsRow }" class="videos" [ngClass]="{ 'display-as-row': displayAsRow }"
> >
<ng-container *ngFor="let video of videos; trackBy: videoById;"> <ng-container *ngFor="let video of videos; trackBy: videoById;">

View File

@ -2,7 +2,8 @@
<div <div
class="videos" class="videos"
myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()" [setAngularState]="true" myInfiniteScroller (nearOfBottom)="onNearOfBottom()" [dataObservable]="onDataSubject.asObservable()"
[parentDisabled]="disabled" [setAngularState]="true"
> >
<div class="video" *ngFor="let video of videos; let i = index; trackBy: videoById"> <div class="video" *ngFor="let video of videos; let i = index; trackBy: videoById">