diff --git a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html index e3bc970..f4eb5e6 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html +++ b/mediarepo-ui/src/app/components/shared/file/file-card/file-card.component.html @@ -1,5 +1,5 @@ + [class.selected]="this.entry.selected | async"> ; @Input() public fileChanged: BehaviorSubject = new BehaviorSubject(undefined); @Output() clickEvent = new EventEmitter(); @Output() dblClickEvent = new EventEmitter(); + public loading = false; private cachedId: number | undefined; private workId: number | undefined; - private selectedPrevious = false; constructor(private changeDetector: ChangeDetectorRef, private schedulingService: SchedulingService) { } async ngOnInit() { this.cachedId = this.entry.data.id; - this.selectedPrevious = this.entry.selected; this.setImageDelayed(); } @@ -56,13 +54,6 @@ export class FileCardComponent implements OnInit, OnChanges, OnDestroy, AfterVie } } - public ngAfterViewChecked(): void { - if (this.entry.selected != this.selectedPrevious) { - this.selectedPrevious = this.entry.selected; - this.changeDetector.markForCheck(); - } - } - public ngOnDestroy(): void { if (this.workId) { this.schedulingService.cancelWork(LOADING_WORK_KEY, this.workId); diff --git a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.ts b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.ts index cebd3fa..b91a034 100644 --- a/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.ts +++ b/mediarepo-ui/src/app/components/shared/file/file-multiview/file-grid/file-grid.component.ts @@ -80,14 +80,14 @@ export class FileGridComponent implements OnChanges, OnInit, AfterViewInit { setSelectedFile(clickedEntry: Selectable) { if (!(this.shiftClicked || this.ctrlClicked) && this.selectedEntries.length > 0) { this.selectedEntries.forEach(entry => { - if (entry !== clickedEntry) entry.selected = false; + if (entry !== clickedEntry) entry.unselect(); }); this.selectedEntries = []; } if (this.shiftClicked && this.selectedEntries.length > 0) { this.handleShiftSelect(clickedEntry); } else { - clickedEntry.selected = !clickedEntry.selected; + clickedEntry.selected.next(!clickedEntry.selected.value); if (!clickedEntry.selected) { const index = this.selectedEntries.indexOf(clickedEntry); if (index > -1) { @@ -213,7 +213,7 @@ export class FileGridComponent implements OnChanges, OnInit, AfterViewInit { this.virtualScroll?.scrollToIndex(scrollToIndex); if (selectedEntry) { - selectedEntry.selected = true; + selectedEntry.select(); this.selectedEntries.push(selectedEntry); } } @@ -225,7 +225,7 @@ export class FileGridComponent implements OnChanges, OnInit, AfterViewInit { const newSelection: Selectable[] = this.gridEntries.filter( entry => this.selectedEntries.findIndex( e => e.data.id == entry.data.id) >= 0); - newSelection.forEach(entry => entry.selected = true); + newSelection.forEach(entry => entry.select()); this.selectedEntries = newSelection; } @@ -240,7 +240,7 @@ export class FileGridComponent implements OnChanges, OnInit, AfterViewInit { for (const gridEntry of this.gridEntries) { if (found) { - gridEntry.selected = true; + gridEntry.select(); this.selectedEntries.push(gridEntry); if (gridEntry === clickedEntry || gridEntry == lastEntry) { return; @@ -248,7 +248,7 @@ export class FileGridComponent implements OnChanges, OnInit, AfterViewInit { } else if (gridEntry === lastEntry || gridEntry === clickedEntry) { found = true; if (gridEntry === clickedEntry) { - gridEntry.selected = true; + gridEntry.select(); this.selectedEntries.push(gridEntry); } } diff --git a/mediarepo-ui/src/app/models/Selectable.ts b/mediarepo-ui/src/app/models/Selectable.ts index 6e64c3a..7268065 100644 --- a/mediarepo-ui/src/app/models/Selectable.ts +++ b/mediarepo-ui/src/app/models/Selectable.ts @@ -1,12 +1,18 @@ +import {BehaviorSubject} from "rxjs"; + export class Selectable { - constructor(public data: T, public selected: boolean) { + + public selected: BehaviorSubject; + + constructor(public data: T, selected: boolean) { + this.selected = new BehaviorSubject(selected); } public select() { - this.selected = true; + this.selected.next(true); } public unselect() { - this.selected = false; + this.selected.next(false); } }