2021-06-28 07:11:47 +00:00
|
|
|
import { updateWidget } from "actions/pageActions";
|
2021-09-09 15:10:22 +00:00
|
|
|
import { MAIN_CONTAINER_WIDGET_ID } from "constants/WidgetConstants";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { useEffect } from "react";
|
|
|
|
|
import { useDispatch } from "react-redux";
|
|
|
|
|
import { AppState } from "reducers";
|
2021-08-06 09:17:56 +00:00
|
|
|
import { APP_MODE } from "entities/App";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { getWidget } from "sagas/selectors";
|
2021-07-14 16:30:10 +00:00
|
|
|
import { getAppMode } from "selectors/applicationSelectors";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { useSelector } from "store";
|
2021-09-09 15:10:22 +00:00
|
|
|
import WidgetFactory from "utils/WidgetFactory";
|
2021-06-28 07:11:47 +00:00
|
|
|
import { WidgetOperations } from "widgets/BaseWidget";
|
|
|
|
|
|
2021-09-09 15:10:22 +00:00
|
|
|
const WidgetTypes = WidgetFactory.widgetTypes;
|
|
|
|
|
|
2021-06-28 07:11:47 +00:00
|
|
|
export const useCanvasMinHeightUpdateHook = (
|
|
|
|
|
widgetId: string,
|
|
|
|
|
minHeight = 0,
|
|
|
|
|
) => {
|
|
|
|
|
const widget = useSelector((state: AppState) => getWidget(state, widgetId));
|
|
|
|
|
const dispatch = useDispatch();
|
2021-07-14 16:30:10 +00:00
|
|
|
const appMode = useSelector(getAppMode);
|
|
|
|
|
const canUpdateWidgetMinHeight =
|
|
|
|
|
appMode === APP_MODE.EDIT &&
|
|
|
|
|
widgetId !== MAIN_CONTAINER_WIDGET_ID &&
|
|
|
|
|
widget &&
|
|
|
|
|
widget.type === WidgetTypes.CANVAS_WIDGET;
|
2021-06-28 07:11:47 +00:00
|
|
|
useEffect(() => {
|
2021-07-14 16:30:10 +00:00
|
|
|
if (canUpdateWidgetMinHeight && widget.minHeight !== minHeight) {
|
2021-06-28 07:11:47 +00:00
|
|
|
dispatch(
|
|
|
|
|
updateWidget(WidgetOperations.UPDATE_PROPERTY, widgetId, {
|
|
|
|
|
propertyPath: "minHeight",
|
|
|
|
|
propertyValue: minHeight,
|
|
|
|
|
}),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}, [minHeight]);
|
|
|
|
|
};
|