Skip to content
Snippets Groups Projects
Commit 8c9dab0c authored by Chris Beer's avatar Chris Beer
Browse files

Add a separate action for selecting search annotations

parent 8cfbc285
No related branches found
No related tags found
No related merge requests found
...@@ -67,6 +67,7 @@ const ActionTypes = { ...@@ -67,6 +67,7 @@ const ActionTypes = {
REMOVE_SEARCH: 'mirador/REMOVE_SEARCH', REMOVE_SEARCH: 'mirador/REMOVE_SEARCH',
SELECT_CONTENT_SEARCH_ANNOTATION: 'mirador/SELECT_CONTENT_SEARCH_ANNOTATION', SELECT_CONTENT_SEARCH_ANNOTATION: 'mirador/SELECT_CONTENT_SEARCH_ANNOTATION',
SELECT_CONTENT_SEARCH_ANNOTATIONS: 'mirador/SELECT_CONTENT_SEARCH_ANNOTATIONS',
UPDATE_LAYERS: 'mirador/UPDATE_LAYERS', UPDATE_LAYERS: 'mirador/UPDATE_LAYERS',
ADD_RESOURCE: 'mirador/ADD_RESOURCE', ADD_RESOURCE: 'mirador/ADD_RESOURCE',
......
...@@ -139,3 +139,8 @@ export function selectContentSearchAnnotation(windowId, companionWindowId, annot ...@@ -139,3 +139,8 @@ export function selectContentSearchAnnotation(windowId, companionWindowId, annot
}); });
}; };
} }
/** */
export function selectContentSearchAnnotations(windowId, annotationsBySearch) {
return { annotationsBySearch, type: ActionTypes.SELECT_CONTENT_SEARCH_ANNOTATIONS, windowId };
}
...@@ -105,16 +105,14 @@ export const searchesReducer = (state = {}, action) => { ...@@ -105,16 +105,14 @@ export const searchesReducer = (state = {}, action) => {
}, },
}, },
}; };
case ActionTypes.SET_CANVAS: case ActionTypes.SELECT_CONTENT_SEARCH_ANNOTATIONS:
if (Object.keys(action.searches).length === 0) return state;
return { return {
...state, ...state,
[action.windowId]: Object.keys(state[action.windowId]).reduce((object, key) => { [action.windowId]: Object.keys(state[action.windowId]).reduce((object, key) => {
if (Object.keys(action.searches).includes(key)) { if (Object.keys(action.annotationsBySearch).includes(key)) {
object[key] = { // eslint-disable-line no-param-reassign object[key] = { // eslint-disable-line no-param-reassign
...state[action.windowId][key], ...state[action.windowId][key],
selectedContentSearchAnnotation: action.searches[key], selectedContentSearchAnnotation: action.annotationsBySearch[key],
}; };
} }
return object; return object;
......
...@@ -113,7 +113,7 @@ export const windowsReducer = (state = {}, action) => { ...@@ -113,7 +113,7 @@ export const windowsReducer = (state = {}, action) => {
case ActionTypes.SET_CANVAS: case ActionTypes.SET_CANVAS:
return updateIn(state, [action.windowId], orig => merge(orig, { return updateIn(state, [action.windowId], orig => merge(orig, {
canvasId: action.canvasId, canvasId: action.canvasId,
selectedContentSearchAnnotation: action.selectedContentSearchAnnotation, visibleCanvases: action.visibleCanvases || [],
})); }));
case ActionTypes.ADD_COMPANION_WINDOW: case ActionTypes.ADD_COMPANION_WINDOW:
return { return {
...@@ -154,6 +154,14 @@ export const windowsReducer = (state = {}, action) => { ...@@ -154,6 +154,14 @@ export const windowsReducer = (state = {}, action) => {
selectedContentSearchAnnotation: action.annotationId, selectedContentSearchAnnotation: action.annotationId,
}, },
}; };
case ActionTypes.SELECT_CONTENT_SEARCH_ANNOTATIONS:
return {
...state,
[action.windowId]: {
...state[action.windowId],
selectedContentSearchAnnotation: Object.values(action.annotationsBySearch)[0],
},
};
case ActionTypes.SELECT_ANNOTATION: case ActionTypes.SELECT_ANNOTATION:
return { return {
...state, ...state,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment