UNPKG

@fakel/rest-admin

Version:

An application that makes it easier to work with your API

55 lines (54 loc) 2.19 kB
var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; var __spreadArray = (this && this.__spreadArray) || function (to, from) { for (var i = 0, il = from.length, j = to.length; i < il; i++, j++) to[j] = from[i]; return to; }; import { observable, makeObservable } from 'mobx'; var ImagesStore = /** @class */ (function () { function ImagesStore() { this.images = []; this.total = 0; makeObservable(this, { images: observable, total: observable, }); } ImagesStore.prototype.setImages = function (images, total) { this.images = images.map(function (image) { return (__assign(__assign({}, image), { isSelected: false })); }); this.images.sort(function (a, b) { return +a.isSelected - +b.isSelected; }); this.total = total; }; ImagesStore.prototype.pushImage = function (image) { this.images = __spreadArray(__spreadArray([], this.images), [__assign(__assign({}, image), { isSelected: false })]); }; ImagesStore.prototype.setIsSelected = function (image, isSelected) { this.images = this.images.map(function (img) { if (img.id === image.id) { return __assign(__assign({}, img), { isSelected: isSelected }); } return img; }); }; ImagesStore.prototype.clearSelected = function () { this.images = this.images.map(function (image) { return (__assign(__assign({}, image), { isSelected: false })); }); }; ImagesStore.prototype.toggleSelectAll = function () { this.images = this.images.map(function (image) { return (__assign(__assign({}, image), { isSelected: !image.isSelected })); }); }; ImagesStore.prototype.setTotal = function (total) { this.total = total; }; return ImagesStore; }()); export { ImagesStore };