Skip to content

Commit a0757d9

Browse files
committed
[IIIF-148] Address feedback from korbit
1 parent 03a9011 commit a0757d9

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

src/mirador-viewer/locationPlugin.js

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
11
import { takeEvery, select } from 'redux-saga/effects';
22
import ActionTypes from 'mirador/dist/es/src/state/actions/action-types';
3-
import {getCanvasIndex} from "mirador/dist/es/src/state/selectors";
3+
import { getCanvasIndex } from 'mirador/dist/es/src/state/selectors';
44

5+
/**
6+
* Extract id from the url.
7+
* URLs are in the format of "https://domain-name/server/iiif/392363fe-015f-41e6-8cdd-b5c754605787/canvas/03c322b7-0182-44fa-8dc3-5d2efcece237"
8+
*/
9+
const extractCanvasId = (canvasUrl) => canvasUrl.split('/').pop();
510

611
/** This will be called every time the SET_CANVAS action is dispatched */
712
const onCanvasChange = function* (action) {
813
const { windowId, canvasId } = action;
914
if (windowId && canvasId) {
1015
const canvasIndex = yield select(getCanvasIndex, { windowId });
11-
// IDs are in the format of "https://dspaceglam7dev.4science.cloud/server/iiif/392363fe-015f-41e6-8cdd-b5c754605787/canvas/03c322b7-0182-44fa-8dc3-5d2efcece237"
12-
const id = action.canvasId.split('/').pop();
16+
const canvasId = extractCanvasId(action.canvasId);
17+
1318
const message = {
1419
type: 'update-url',
1520
// index here starts from 0, whilst for setting the index it starts from 1.
1621
canvasIndex: canvasIndex + 1,
17-
canvasId: id
22+
canvasId: canvasId
1823
};
19-
if (id && id !== 'undefined' && typeof window !== 'undefined') {
24+
25+
const isValidId = canvasId && canvasId !== 'undefined';
26+
const isBrowserEnvironment = typeof window !== 'undefined';
27+
28+
if (isValidId && isBrowserEnvironment) {
2029
window.parent.postMessage(message, '*');
2130
}
2231
}

0 commit comments

Comments
 (0)