bidasoa-components
Version:
Colección de componentes comunes empleados en proyectos Bidasoa.
64 lines (63 loc) • 3.21 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.Preview = void 0;
const react_1 = __importStar(require("react"));
const Preview_styles_1 = require("./Preview.styles");
const Preview = ({ pageContext, renderView }) => {
var _a, _b;
const [isNodePreview, setIsNodePreview] = (0, react_1.useState)(false);
const handleClick = () => {
var _a, _b;
const nodeId = (_a = pageContext === null || pageContext === void 0 ? void 0 : pageContext.node) === null || _a === void 0 ? void 0 : _a.data.content.id;
const splittedUrl = window.location.pathname.split('/');
if (!nodeId) {
const nodeType = (_b = pageContext === null || pageContext === void 0 ? void 0 : pageContext.node) === null || _b === void 0 ? void 0 : _b.data.content.bundle;
window.location.href = `/node/add/${nodeType}?uuid=${splittedUrl[3]}`;
}
else {
window.location.href = `/node/${nodeId}/edit?uuid=${splittedUrl[3]}`;
}
};
(0, react_1.useEffect)(() => {
if (!pageContext || !(pageContext === null || pageContext === void 0 ? void 0 : pageContext.node.data.content.bundle)) {
return;
}
if (window.location.pathname.indexOf('/node/preview') !== -1) {
setIsNodePreview(true);
}
}, []);
if (!pageContext || !((_a = pageContext === null || pageContext === void 0 ? void 0 : pageContext.node) === null || _a === void 0 ? void 0 : _a.data.content.bundle)) {
return null;
}
const contentTypeToRender = (_b = pageContext === null || pageContext === void 0 ? void 0 : pageContext.node) === null || _b === void 0 ? void 0 : _b.data.content.bundle;
if (contentTypeToRender === 'preview') {
return react_1.default.createElement("p", null, "Cargando contenido para preview");
}
return (react_1.default.createElement(react_1.default.Fragment, null,
isNodePreview && (react_1.default.createElement(Preview_styles_1.BackToEditingContentButton, { onClick: handleClick }, "Vuelta a edici\u00F3n")),
renderView(contentTypeToRender, pageContext)));
};
exports.Preview = Preview;