Commit 0606bbcf authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Reload iframe on every `openNotebook` event

While there is no mechanism to sync new annotations in the notebook, we
force re-rendering of the iframe on every 'openNotebook' event, so we
fetch the new annotations.

This is a temporary fix that is intended to be removed.
parent 599df082
...@@ -26,7 +26,6 @@ function NotebookIframe({ config, groupId }) { ...@@ -26,7 +26,6 @@ function NotebookIframe({ config, groupId }) {
return ( return (
<iframe <iframe
key={groupId} // force re-rendering on group change
title={'Hypothesis annotation notebook'} title={'Hypothesis annotation notebook'}
className="Notebook__iframe" className="Notebook__iframe"
// Enable media in annotations to be shown fullscreen // Enable media in annotations to be shown fullscreen
...@@ -48,6 +47,11 @@ function NotebookIframe({ config, groupId }) { ...@@ -48,6 +47,11 @@ function NotebookIframe({ config, groupId }) {
* @param {NotebookModalProps} props * @param {NotebookModalProps} props
*/ */
export default function NotebookModal({ eventBus, config }) { export default function NotebookModal({ eventBus, config }) {
// Temporary solution: while there is no mechanism to sync new annotations in
// the notebook, we force re-rendering of the iframe on every 'openNotebook'
// event, so that the new annotations are displayed.
// https://github.com/hypothesis/client/issues/3182
const [iframeKey, setIframeKey] = useState(0);
const [isHidden, setIsHidden] = useState(true); const [isHidden, setIsHidden] = useState(true);
const [groupId, setGroupId] = useState(/** @type {string|null} */ (null)); const [groupId, setGroupId] = useState(/** @type {string|null} */ (null));
const originalDocumentOverflowStyle = useRef(''); const originalDocumentOverflowStyle = useRef('');
...@@ -81,6 +85,7 @@ export default function NotebookModal({ eventBus, config }) { ...@@ -81,6 +85,7 @@ export default function NotebookModal({ eventBus, config }) {
/** @type {string} */ groupId /** @type {string} */ groupId
) => { ) => {
setIsHidden(false); setIsHidden(false);
setIframeKey(iframeKey => iframeKey + 1);
setGroupId(groupId); setGroupId(groupId);
}); });
...@@ -105,7 +110,7 @@ export default function NotebookModal({ eventBus, config }) { ...@@ -105,7 +110,7 @@ export default function NotebookModal({ eventBus, config }) {
onClick={onClose} onClick={onClose}
/> />
{groupId !== null && ( {groupId !== null && (
<NotebookIframe config={config} groupId={groupId} /> <NotebookIframe key={iframeKey} config={config} groupId={groupId} />
)} )}
</div> </div>
</div> </div>
......
...@@ -58,7 +58,7 @@ describe('NotebookModal', () => { ...@@ -58,7 +58,7 @@ describe('NotebookModal', () => {
); );
}); });
it('creates a new iframe element if the group is changed', () => { it('creates a new iframe element on every "openNotebook" event', () => {
const wrapper = createComponent(); const wrapper = createComponent();
emitter.publish('openNotebook', '1'); emitter.publish('openNotebook', '1');
...@@ -78,7 +78,7 @@ describe('NotebookModal', () => { ...@@ -78,7 +78,7 @@ describe('NotebookModal', () => {
iframe2.prop('src'), iframe2.prop('src'),
`/notebook#config=${encodeURIComponent('{"group":"1"}')}` `/notebook#config=${encodeURIComponent('{"group":"1"}')}`
); );
assert.equal(iframe1.getDOMNode(), iframe2.getDOMNode()); assert.notEqual(iframe1.getDOMNode(), iframe2.getDOMNode());
emitter.publish('openNotebook', '2'); emitter.publish('openNotebook', '2');
wrapper.update(); wrapper.update();
...@@ -91,7 +91,7 @@ describe('NotebookModal', () => { ...@@ -91,7 +91,7 @@ describe('NotebookModal', () => {
assert.notEqual(iframe1.getDOMNode(), iframe3.getDOMNode()); assert.notEqual(iframe1.getDOMNode(), iframe3.getDOMNode());
}); });
it('makes the document unscrollable on openNotebook event', () => { it('makes the document unscrollable on "openNotebook" event', () => {
createComponent(); createComponent();
act(() => { act(() => {
emitter.publish('openNotebook', 'myGroup'); emitter.publish('openNotebook', 'myGroup');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment