Skip to content

Commit

Permalink
Improve appending to gallery.
Browse files Browse the repository at this point in the history
  • Loading branch information
mczachurski committed Jan 5, 2025
1 parent 7b36b9b commit c3dce50
Showing 1 changed file with 23 additions and 7 deletions.
30 changes: 23 additions & 7 deletions src/app/components/widgets/gallery/gallery.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,19 +165,35 @@ export class GalleryComponent extends ResponsiveComponent implements OnInit, OnD
}

const columns = this.galleryColumns();

// Create temporary array for new statuses (with columns configuration).
const internalColumns: GalleryColumn[] = [];
for (const column of columns) {
const galleryColumn = new GalleryColumn(column.columnId);
galleryColumn.size = column.size;

internalColumns.push(galleryColumn);
}

// Append new statuses to temporary array.
for(let i = fromIndex; i < addedStatuses.length; i++) {
const status = addedStatuses[i];

const imageHeight = this.getImageConstraintHeight(status);
const smallerColumnIndex = this.getSmallerColumnIndex(columns, imageHeight);
const smallerColumnIndex = this.getSmallerColumnIndex(internalColumns, imageHeight);

this.galleryColumns.update(columns => {
columns[smallerColumnIndex].size = columns[smallerColumnIndex].size + imageHeight;
columns[smallerColumnIndex].statuses.push(new GalleryStatus(status, false));

return columns;
});
internalColumns[smallerColumnIndex].size = internalColumns[smallerColumnIndex].size + imageHeight;
internalColumns[smallerColumnIndex].statuses.push(new GalleryStatus(status, false));
}

// Update in one step columns signal (to reduce DOM manipulations).
this.galleryColumns.update(columns => {
for (let i = 0; i < internalColumns.length; i++) {
columns[i].statuses = columns[i].statuses.concat(internalColumns[i].statuses);
columns[i].size = internalColumns[i].size;
}
return columns;
});
}

getMainStatus(status: Status): Status {
Expand Down

0 comments on commit c3dce50

Please sign in to comment.