mirror of
https://github.com/paperless-ngx/paperless-ngx.git
synced 2025-12-07 23:35:22 +01:00
Chore: use rxjs instead of JS setInterval for timers (#8461)
This commit is contained in:
parent
0a7c296194
commit
e3fa3fe818
7 changed files with 36 additions and 53 deletions
|
|
@ -6,7 +6,7 @@ import {
|
|||
ChangeDetectorRef,
|
||||
OnDestroy,
|
||||
} from '@angular/core'
|
||||
import { takeUntil } from 'rxjs'
|
||||
import { filter, takeUntil, timer } from 'rxjs'
|
||||
import { LogService } from 'src/app/services/rest/log.service'
|
||||
import { LoadingComponentWithPermissions } from '../../loading-component/loading.component'
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ export class LogsComponent
|
|||
|
||||
public activeLog: string
|
||||
|
||||
public autoRefreshInterval: any
|
||||
public autoRefreshEnabled: boolean = true
|
||||
|
||||
@ViewChild('logContainer') logContainer: ElementRef
|
||||
|
||||
|
|
@ -47,13 +47,19 @@ export class LogsComponent
|
|||
this.activeLog = this.logFiles[0]
|
||||
this.reloadLogs()
|
||||
}
|
||||
this.toggleAutoRefresh()
|
||||
timer(5000, 5000)
|
||||
.pipe(
|
||||
filter(() => this.autoRefreshEnabled),
|
||||
takeUntil(this.unsubscribeNotifier)
|
||||
)
|
||||
.subscribe(() => {
|
||||
this.reloadLogs()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
ngOnDestroy(): void {
|
||||
super.ngOnDestroy()
|
||||
clearInterval(this.autoRefreshInterval)
|
||||
}
|
||||
|
||||
reloadLogs() {
|
||||
|
|
@ -96,15 +102,4 @@ export class LogsComponent
|
|||
behavior: 'auto',
|
||||
})
|
||||
}
|
||||
|
||||
toggleAutoRefresh(): void {
|
||||
if (this.autoRefreshInterval) {
|
||||
clearInterval(this.autoRefreshInterval)
|
||||
this.autoRefreshInterval = null
|
||||
} else {
|
||||
this.autoRefreshInterval = setInterval(() => {
|
||||
this.reloadLogs()
|
||||
}, 5000)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue