Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ export default (onParameterChange) => {
h5pEditor.selector.form.metadataForm.setMetadata({authors: [{name, role}]});
}
};
const getAuthors = () => {
const params = getParams();
return params?.metadata?.authors || [];
};

const setAuthors = (authors) => {
if (h5pEditor?.selector?.form?.metadataForm && authors?.length > 0) {
h5pEditor.selector.form.metadataForm.setMetadata({ authors });
}
};

const onBeforeUpgrade = params => {
if (!params !== undefined && params !== false) {
Expand Down Expand Up @@ -160,5 +170,7 @@ export default (onParameterChange) => {
},
h5pEditor,
iframeLoading,
getAuthors,
setAuthors,
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ const H5PEditorContainer = ({ intl }) => {
stageUpgrade,
iframeLoading,
setAuthor,
setAuthors,
getAuthors,
} = useH5PEditor(onParamsChange);

const getCurrentParams = React.useCallback(() => {
Expand Down Expand Up @@ -144,6 +146,25 @@ const H5PEditorContainer = ({ intl }) => {
}
clearInterval(H5PLibraryInterval);
setLibrarySelected(true);

// Listen for library changes to preserve authors
if (h5pEditor.selector?.on) {
let previousAuthors = [];

// Capture authors before library change
h5pEditor.selector.on('editorload', () => {
previousAuthors = getAuthors();
});

// Restore authors after library change
h5pEditor.selector.on('editorloaded', () => {
if (previousAuthors.length > 0) {
setAuthors(previousAuthors);
} else if (creatorName !== null) {
setAuthor(creatorName, 'Author');
}
});
}
}
// eslint-disable-next-line no-empty
} catch (ignore) {}
Expand Down
Loading