diff --git a/frontend/app/gallery/grid/grid.gallery.component.ts b/frontend/app/gallery/grid/grid.gallery.component.ts index 6d63980..d42976d 100644 --- a/frontend/app/gallery/grid/grid.gallery.component.ts +++ b/frontend/app/gallery/grid/grid.gallery.component.ts @@ -45,7 +45,11 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { if (this.isAfterViewInit == false) { return; } - this.onPhotosChanged(); + this.sortPhotos(); + this.mergeNewPhotos(); + setImmediate(() => { + this.renderPhotos(); + }); } @HostListener('window:resize') @@ -53,7 +57,11 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { if (this.isAfterViewInit == false) { return; } - this.onPhotosChanged(); + this.sortPhotos(); + this.clearRenderedPhotos(); + setImmediate(() => { + this.renderPhotos(); + }); } isAfterViewInit:boolean = false; @@ -64,13 +72,16 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { //TODO: implement scroll detection - this.onPhotosChanged(); + this.sortPhotos(); + this.clearRenderedPhotos(); + setImmediate(() => { + this.renderPhotos(); + }); this.isAfterViewInit = true; } - private onPhotosChanged() { - + private sortPhotos() { //sort pohots by date this.photos.sort((a:Photo, b:Photo) => { if (a.metadata.creationDate > b.metadata.creationDate) { @@ -83,6 +94,14 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { return 0; }); + } + + private clearRenderedPhotos() { + this.photosToRender = []; + this.renderedPhotoIndex = 0; + } + + private mergeNewPhotos() { //merge new data with old one let lastSameIndex = 0; let lastRowId = null; @@ -102,15 +121,11 @@ export class GalleryGridComponent implements OnChanges,AfterViewInit { this.photosToRender.splice(lastSameIndex, this.photosToRender.length - lastSameIndex); this.renderedPhotoIndex = lastSameIndex; } else { - this.photosToRender = []; - this.renderedPhotoIndex = 0; + this.clearRenderedPhotos(); } - - setImmediate(() => { - this.renderPhotos(); - }); } + private renderedPhotoIndex:number = 0; private renderPhotos() { diff --git a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts index ee960f5..b9e8e76 100644 --- a/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts +++ b/frontend/app/gallery/grid/photo/photo.grid.gallery.component.ts @@ -1,6 +1,6 @@ /// -import {Component, Input, ElementRef, ViewChild, OnInit, AfterViewInit, OnDestroy, Renderer} from "@angular/core"; +import {Component, Input, ElementRef, ViewChild, OnInit, AfterViewInit, OnDestroy} from "@angular/core"; import {IRenderable, Dimension} from "../../../model/IRenderable"; import {GridPhoto} from "../GridPhoto"; import {SearchTypes} from "../../../../../common/entities/AutoCompleteItem"; @@ -49,7 +49,7 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, AfterViewInit wasInView:boolean = null; - constructor(private thumbnailService:ThumbnailLoaderService, private renderer:Renderer) { + constructor(private thumbnailService:ThumbnailLoaderService) { this.SearchTypes = SearchTypes; this.searchEnabled = Config.Client.Search.searchEnabled; @@ -92,13 +92,11 @@ export class GalleryPhotoComponent implements IRenderable, OnInit, AfterViewInit onError: (error)=> {//onError this.thumbnailTask = null; //TODO: handle error + //TODO: not an error if its from cache console.error("something bad happened"); console.error(error); } }; - /* this.scrollListener = this.renderer.listenGlobal('window', 'scroll', () => { - this.onScroll(); - });*/ if (this.gridPhoto.isReplacementThumbnailAvailable()) { this.thumbnailTask = this.thumbnailService.loadImage(this.gridPhoto, ThumbnailLoadingPriority.medium, listener); } else {