Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

See real time updates when you change title in sidebar #49

Merged
merged 8 commits into from
Jun 20, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update review changes
  • Loading branch information
MAX-786 committed Jun 20, 2024
commit 8153a522dfac6a3c3defc084f704e21aaa6012e4
4 changes: 2 additions & 2 deletions hydra.js
Original file line number Diff line number Diff line change
@@ -147,8 +147,8 @@ export async function getToken() {
* @param {*} initialData
* @param {*} callback
*/
export function onEditChange(initialData, callback) {
export function onEditChange(callback) {
if (bridgeInstance) {
bridgeInstance.onEditChange(initialData, callback);
bridgeInstance.onEditChange(callback);
}
}
17 changes: 15 additions & 2 deletions packages/volto-hydra/src/components/Iframe/View.jsx
Original file line number Diff line number Diff line change
@@ -4,6 +4,16 @@ import { useSelector } from 'react-redux';
import Cookies from 'js-cookie';
import './styles.css';

function isValidUrl(string) {
try {
new URL(string);
return true;
} catch (error) {
console.error(error);
return false;
}
}

const Iframe = () => {
const history = useHistory();
const token = useSelector((state) => state.userSession.token);
@@ -48,21 +58,24 @@ const Iframe = () => {
}, [token]);

useEffect(() => {
if (typeof window !== 'undefined' && Object.keys(form).length > 0) {
if (Object.keys(form).length > 0 && isValidUrl(initialUrl)) {
// Send the form data to the iframe
const origin = new URL(initialUrl).origin;
MAX-786 marked this conversation as resolved.
Show resolved Hide resolved
document
.getElementById('previewIframe')
.contentWindow.postMessage({ type: 'FORM', data: form }, origin);
}
}, [form]);
}, [form, initialUrl]);

const handleUrlChange = (event) => {
setUrl(event.target.value);
};

const handleNavigateToUrl = (givenUrl = '') => {
// Update adminUI URL with the new URL
if (!isValidUrl(givenUrl) && !isValidUrl(url)) {
return;
}
const formattedUrl = givenUrl ? new URL(givenUrl) : new URL(url);
MAX-786 marked this conversation as resolved.
Show resolved Hide resolved
// const newUrl = formattedUrl.href;
// setSrc(newUrl);