@brizy/media-gallery
Version:
86 lines (85 loc) • 2.87 kB
JavaScript
import React, { Fragment, useCallback } from "react";
import { Content as CContent } from "../../../components/pages/MediaGallery/Content";
import * as State from "../types/State";
import * as Actions from "../types/Actions";
import { useDispatch } from "react-redux";
import { always, pipe } from "ramda";
import { match } from "fp-utilities";
import { createElement } from "../../../utils/react/createElement";
import { Loading } from "../../../components/Loading";
import { isBulkSelected, isLoading, isMultipleSelected, isRemoveConfirmation, isWithContent } from "../utils";
import { RemoveConfirmation } from "../../../components/RemoveConfirmation";
var Container = function(s) {
var items = s.items, type = s.type;
var dispatch = useDispatch();
var onBulkSelect = useCallback(function() {
return pipe(Actions.bulkSelect, dispatch)();
}, [
dispatch
]);
var onSelectAll = useCallback(function() {
return pipe(Actions.selectAll, dispatch)();
}, [
dispatch
]);
var onSelectItem = useCallback(function(v) {
return pipe(Actions.selectItem, dispatch)(v);
}, [
dispatch
]);
var onSelectType = useCallback(function(v) {
return pipe(Actions.selectType, dispatch)(v);
}, [
dispatch
]);
var onUpload = useCallback(function(v) {
return pipe(Actions.upload, dispatch)(v);
}, [
dispatch
]);
var onDecline = useCallback(function() {
return pipe(Actions.removeDeclined, dispatch)();
}, [
dispatch
]);
var onApprove = useCallback(function() {
return pipe(Actions.removeApproved, dispatch)();
}, [
dispatch
]);
var _s_height;
return React.createElement(Fragment, {}, [
React.createElement(CContent, {
key: "content",
items: items,
type: type,
isMultipleSelected: isMultipleSelected(s),
isBulkSelected: isBulkSelected(s),
isAllSelected: items.every(function(i) {
return i.isSelected;
}) && !!items.length,
isDisabledBulkSelected: !items.length,
height: "calc(".concat((_s_height = s.height) !== null && _s_height !== void 0 ? _s_height : "100vh", " - 160px"),
onBulkSelect: onBulkSelect,
onSelectAll: onSelectAll,
onSelectItem: onSelectItem,
onSelectType: onSelectType,
onUpload: onUpload
}),
isRemoveConfirmation(s) ? React.createElement(RemoveConfirmation, {
onApprove: onApprove,
onDecline: onDecline,
key: "confirmation"
}) : null
]);
};
export var Content = match([
isLoading,
createElement(Loading)
], [
State.isLoadError,
always(null)
], [
isWithContent,
createElement(Container)
]);