Commit 18fd3307 authored by Lyza Danger Gardner's avatar Lyza Danger Gardner

Add `sidebarHasOpened` to track whether sidebar has ever been opened

parent d4777fa5
......@@ -176,7 +176,7 @@ export default function FrameSync($rootScope, $window, store, bridge) {
});
bridge.on('sidebarOpened', function () {
$rootScope.$broadcast('sidebarOpened');
store.setSidebarOpened(true);
});
// These invoke the matching methods by name on the Guests
......
......@@ -66,6 +66,7 @@ describe('sidebar/services/frame-sync', function () {
openSidebarPanel: sinon.stub(),
selectAnnotations: sinon.stub(),
selectTab: sinon.stub(),
setSidebarOpened: sinon.stub(),
toggleSelectedAnnotations: sinon.stub(),
updateAnchorStatus: sinon.stub(),
}
......@@ -376,9 +377,10 @@ describe('sidebar/services/frame-sync', function () {
});
describe('on "sidebarOpened" message', function () {
it('broadcasts a sidebarOpened event', function () {
it('sets the sidebar open in the store', function () {
fakeBridge.emit('sidebarOpened');
assert.calledWith($rootScope.$broadcast, 'sidebarOpened');
assert.calledWith(fakeStore.setSidebarOpened, true);
});
});
......
......@@ -19,4 +19,23 @@ describe('store/modules/viewer', function () {
assert.isFalse(store.getState().viewer.visibleHighlights);
});
});
describe('hasSidebarOpened', () => {
it('is `false` if sidebar has never been opened', () => {
assert.isFalse(store.hasSidebarOpened());
store.setSidebarOpened(false);
assert.isFalse(store.hasSidebarOpened());
});
it('is `true` if sidebar has been opened', () => {
store.setSidebarOpened(true);
assert.isTrue(store.hasSidebarOpened());
});
it('is `true` if sidebar is closed after being opened', () => {
store.setSidebarOpened(true);
store.setSidebarOpened(false);
assert.isTrue(store.hasSidebarOpened());
});
});
});
......@@ -7,6 +7,9 @@ import * as util from '../util';
function init() {
return {
// Has the sidebar ever been opened? NB: This is not necessarily the
// current state of the sidebar, but tracks whether it has ever been open
sidebarHasOpened: false,
visibleHighlights: false,
};
}
......@@ -15,10 +18,20 @@ const update = {
SET_HIGHLIGHTS_VISIBLE: function (state, action) {
return { visibleHighlights: action.visible };
},
SET_SIDEBAR_OPENED: (state, action) => {
if (action.opened === true) {
// If the sidebar is open, track that it has ever been opened
return { sidebarHasOpened: true };
}
// Otherwise, nothing to do here
return {};
},
};
const actions = util.actionTypes(update);
// Action creators
/**
* Sets whether annotation highlights in connected documents are shown
* or not.
......@@ -27,12 +40,28 @@ function setShowHighlights(show) {
return { type: actions.SET_HIGHLIGHTS_VISIBLE, visible: show };
}
/**
* @param {boolean} sidebarState - If the sidebar is open
*/
function setSidebarOpened(opened) {
return { type: actions.SET_SIDEBAR_OPENED, opened };
}
// Selectors
function hasSidebarOpened(state) {
return state.viewer.sidebarHasOpened;
}
export default {
init: init,
namespace: 'viewer',
update: update,
actions: {
setShowHighlights: setShowHighlights,
setShowHighlights,
setSidebarOpened,
},
selectors: {
hasSidebarOpened,
},
selectors: {},
};
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