Commit 72c5253b authored by Robert Knight's avatar Robert Knight

Add store state to hold content information banner data

parent 97da55d7
......@@ -26,4 +26,16 @@ describe('store/modules/viewer', () => {
assert.isTrue(store.hasSidebarOpened());
});
});
describe('getContentInfo', () => {
it('returns data for content info banner', () => {
const contentInfo = {
logo: {},
item: { title: 'Some article' },
links: {},
};
store.setContentInfo(contentInfo);
assert.deepEqual(store.getContentInfo(), contentInfo);
});
});
});
import { createStoreModule, makeAction } from '../create-store';
/**
* @typedef {import('../../../types/annotator').ContentInfoConfig} ContentInfoConfig
*/
/**
* This module defines actions and state related to the display mode of the
* sidebar.
......@@ -11,6 +15,13 @@ const initialState = {
* current state of the sidebar, but tracks whether it has ever been open
*/
sidebarHasOpened: false,
/**
* Data for the content information banner shown in the host frame.
*
* @type {ContentInfoConfig|null}
*/
contentInfo: null,
};
/** @typedef {typeof initialState} State */
......@@ -28,6 +39,14 @@ const reducers = {
// Otherwise, nothing to do here
return {};
},
/**
* @param {State} state
* @param {{ info: ContentInfoConfig }} action
*/
SET_CONTENT_INFO(state, action) {
return { contentInfo: action.info };
},
};
/**
......@@ -42,13 +61,25 @@ function hasSidebarOpened(state) {
return state.sidebarHasOpened;
}
/** @param {ContentInfoConfig} info */
function setContentInfo(info) {
return makeAction(reducers, 'SET_CONTENT_INFO', { info });
}
/** @param {State} state */
function getContentInfo(state) {
return state.contentInfo;
}
export const viewerModule = createStoreModule(initialState, {
namespace: 'viewer',
reducers,
actionCreators: {
setContentInfo,
setSidebarOpened,
},
selectors: {
getContentInfo,
hasSidebarOpened,
},
});
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