@craftercms/studio-ui
Version:
Services, components, models & utils to build CrafterCMS authoring extensions.
72 lines (70 loc) • 2.94 kB
JavaScript
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/*
* Copyright (C) 2007-2022 Crafter Software Corporation. All Rights Reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as published by
* the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import { useDispatch } from 'react-redux';
import { useEffect } from 'react';
import { fetchContentTypes, guestPathUpdated, reloadRequest } from '../../state/actions/preview';
import { filter } from 'rxjs/operators';
import { getHostToGuestBus } from '../../utils/subjects';
import { useActiveSiteId } from '../../hooks/useActiveSiteId';
export function LegacyConcierge() {
// As it stands, this should be a hook, but creating as a component for the convenience of mounting it
// only once on the CrafterCMSNextBridge component. As a hook, it would be out of the StoreProvider.
const site = useActiveSiteId();
const dispatch = useDispatch();
useEffect(() => {
if (site) {
dispatch(fetchContentTypes());
}
}, [site, dispatch]);
useEffect(() => {
// @ts-ignore
if (window.amplify) {
const hostToGuest$ = getHostToGuestBus();
const subscription = hostToGuest$.pipe(filter((action) => action.type === reloadRequest.type)).subscribe(() => {
var _a, _b;
// @ts-ignore
(_b = (_a = CStudioAuthoring.Operations).refreshPreview) === null || _b === void 0 ? void 0 : _b.call(_a);
});
const updateGuest = ({ contentTO: item }) => {
dispatch(guestPathUpdated({ path: item.uri }));
};
// @ts-ignore
amplify.subscribe('SELECTED_CONTENT_SET', updateGuest);
return () => {
subscription.unsubscribe();
// @ts-ignore
amplify.unsubscribe('SELECTED_CONTENT_SET', updateGuest);
};
}
}, [dispatch]);
return null;
}
export default LegacyConcierge;