Skip to content

Commit b0c22ee

Browse files
committed
refactor(frontend:files): replace @input with Angular input() and signals for improved reactivity and consistency across file viewers
1 parent f68a073 commit b0c22ee

File tree

4 files changed

+24
-26
lines changed

4 files changed

+24
-26
lines changed

frontend/src/app/applications/files/components/viewers/files-viewer-document.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
*/
66

77
import { HttpClient, HttpParams } from '@angular/common/http'
8-
import { Component, inject, Input, OnDestroy, OnInit } from '@angular/core'
8+
import { Component, inject, input, Input, OnDestroy, OnInit } from '@angular/core'
99
import { API_FILES_ONLY_OFFICE_SETTINGS } from '@sync-in-server/backend/src/applications/files/constants/routes'
1010
import { OnlyOfficeReqConfig } from '@sync-in-server/backend/src/applications/files/interfaces/only-office-config.interface'
1111
import { SERVER_NAME } from '@sync-in-server/backend/src/common/shared'
@@ -19,7 +19,7 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
1919
imports: [OnlyOfficeComponent],
2020
template: `
2121
@if (documentConfig) {
22-
<div [style.height.px]="currentHeight">
22+
<div [style.height.px]="currentHeight()">
2323
<app-files-onlyoffice-document
2424
[id]="docId"
2525
[documentServerUrl]="documentConfig.documentServerUrl"
@@ -31,9 +31,9 @@ import { OnlyOfficeComponent } from '../utils/only-office.component'
3131
`
3232
})
3333
export class FilesViewerDocumentComponent implements OnInit, OnDestroy {
34-
@Input() file: FileModel
35-
@Input() currentHeight: number
36-
@Input() mode: 'view' | 'edit'
34+
@Input({ required: true }) file: FileModel
35+
@Input({ required: true }) mode: 'view' | 'edit'
36+
currentHeight = input<number>()
3737
protected docId: string
3838
protected documentConfig: OnlyOfficeReqConfig = null
3939
private readonly http = inject(HttpClient)

frontend/src/app/applications/files/components/viewers/files-viewer-html.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,26 +5,26 @@
55
*/
66

77
import { HttpClient } from '@angular/common/http'
8-
import { Component, inject, Input, OnInit } from '@angular/core'
8+
import { Component, inject, input, OnInit } from '@angular/core'
99
import { DomSanitizer } from '@angular/platform-browser'
1010
import { LayoutService } from '../../../../layout/layout.service'
1111

1212
@Component({
1313
selector: 'app-files-viewer-html',
1414
template: `@if (content) {
15-
<iframe [src]="content" [style.height.px]="currentHeight" class="app-viewer-iframe" sandbox></iframe>
15+
<iframe [src]="content" [style.height.px]="currentHeight()" class="app-viewer-iframe" sandbox></iframe>
1616
}`
1717
})
1818
export class FilesViewerHtmlComponent implements OnInit {
19-
@Input() currentHeight: number
20-
@Input() fileUrl: string
19+
fileUrl = input<string>()
20+
currentHeight = input<number>()
2121
protected content: any = null
2222
private readonly http = inject(HttpClient)
2323
private readonly sanitizer = inject(DomSanitizer)
2424
private readonly layout = inject(LayoutService)
2525

2626
ngOnInit() {
27-
this.http.get(this.fileUrl, { responseType: 'text' }).subscribe({
27+
this.http.get(this.fileUrl(), { responseType: 'text' }).subscribe({
2828
next: (data: string) => (this.content = this.sanitizer.bypassSecurityTrustResourceUrl(`data:text/html,${data}`)),
2929
error: (e) => {
3030
this.content = this.sanitizer.bypassSecurityTrustResourceUrl(

frontend/src/app/applications/files/components/viewers/files-viewer-media.component.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* See the LICENSE file for licensing details
55
*/
66

7-
import { ChangeDetectionStrategy, Component, Input } from '@angular/core'
7+
import { ChangeDetectionStrategy, Component, input } from '@angular/core'
88
import { VgBufferingModule } from '@videogular/ngx-videogular/buffering'
99
import { VgControlsModule } from '@videogular/ngx-videogular/controls'
1010
import { VgCoreModule } from '@videogular/ngx-videogular/core'
@@ -15,14 +15,14 @@ import { VgOverlayPlayModule } from '@videogular/ngx-videogular/overlay-play'
1515
changeDetection: ChangeDetectionStrategy.OnPush,
1616
imports: [VgCoreModule, VgControlsModule, VgOverlayPlayModule, VgBufferingModule],
1717
template: `
18-
<vg-player [style.height.px]="currentHeight">
18+
<vg-player [style.height.px]="currentHeight()">
1919
<video [vgMedia]="$any(media)" #media preload="none" controls>
20-
<source [src]="fileUrl" type="video/webm" />
20+
<source [src]="fileUrl()" type="video/webm" />
2121
</video>
2222
</vg-player>
2323
`
2424
})
2525
export class FilesViewerMediaComponent {
26-
@Input() currentHeight: number
27-
@Input() fileUrl: string
26+
fileUrl = input<string>()
27+
currentHeight = input<number>()
2828
}

frontend/src/app/applications/files/components/viewers/files-viewer-pdf.component.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,21 @@
44
* See the LICENSE file for licensing details
55
*/
66

7-
import { ChangeDetectionStrategy, Component, inject, Input, OnInit } from '@angular/core'
8-
import { DomSanitizer } from '@angular/platform-browser'
7+
import { ChangeDetectionStrategy, Component, computed, inject, input } from '@angular/core'
8+
import { DomSanitizer, SafeResourceUrl } from '@angular/platform-browser'
99
import { assetsUrl } from '../../files.constants'
1010

1111
@Component({
1212
selector: 'app-files-viewer-pdf',
1313
changeDetection: ChangeDetectionStrategy.OnPush,
14-
template: ` <iframe [src]="url" class="app-viewer-iframe" [style.height.px]="currentHeight"></iframe> `
14+
template: ` <iframe [src]="url()" class="app-viewer-iframe" [style.height.px]="currentHeight()"></iframe> `
1515
})
16-
export class FilesViewerPdfComponent implements OnInit {
17-
@Input() fileUrl: string
18-
@Input() currentHeight: number
19-
protected url: any
16+
export class FilesViewerPdfComponent {
17+
fileUrl = input<string>()
18+
currentHeight = input<number>()
2019
private readonly sanitizer = inject(DomSanitizer)
2120
private readonly pdfjsUrl = `${assetsUrl}/pdfjs/web/viewer.html?file=`
22-
23-
ngOnInit() {
24-
this.url = this.sanitizer.bypassSecurityTrustResourceUrl(`${this.pdfjsUrl}${encodeURIComponent(this.fileUrl)}`)
25-
}
21+
url = computed<SafeResourceUrl | null>(() =>
22+
this.fileUrl() ? this.sanitizer.bypassSecurityTrustResourceUrl(`${this.pdfjsUrl}${encodeURIComponent(this.fileUrl())}`) : null
23+
)
2624
}

0 commit comments

Comments
 (0)