Unverified Commit e1cb9919 authored by Kyle Keating's avatar Kyle Keating Committed by GitHub

Merge pull request #1349 from hypothesis/namespace-viewer-module

Namespace viewer module
parents 3c3017b3 7d332653
......@@ -68,7 +68,7 @@ function RootThread($rootScope, store, searchFilter, viewFilter) {
}
let threadFilterFn;
if (state.base.isSidebar && !shouldFilterThread()) {
if (state.viewer.isSidebar && !shouldFilterThread()) {
threadFilterFn = function(thread) {
if (!thread.annotation) {
return false;
......
......@@ -36,6 +36,8 @@ describe('rootThread', function() {
state: {
base: {
annotations: [],
},
viewer: {
isSidebar: true,
visibleHighlights: false,
},
......@@ -288,7 +290,7 @@ describe('rootThread', function() {
it('does not filter annotations when not in the sidebar', function() {
fakeBuildThread.reset();
fakeStore.state.base.isSidebar = false;
fakeStore.state.viewer.isSidebar = false;
rootThread.thread(fakeStore.state);
const threadFilterFn = fakeBuildThread.args[0][1].threadFilterFn;
......
......@@ -252,7 +252,7 @@ function addAnnotations(annotations, now) {
currentAnnotationCount: getState().base.annotations.length,
});
if (!getState().base.isSidebar) {
if (!getState().viewer.isSidebar) {
return;
}
......
......@@ -97,8 +97,8 @@ function receiveRealTimeUpdates({
// group and reload all annotations and discard pending updates
// when switching groups.
if (
ann.group === groupSelectors.focusedGroupId(getState().base) ||
!viewerSelectors.isSidebar(getState().base)
ann.group === groupSelectors.focusedGroupId(getState()) ||
!viewerSelectors.isSidebar(getState())
) {
pendingUpdates[ann.id] = ann;
}
......
......@@ -5,6 +5,7 @@ const createStoreFromModules = require('../../create-store');
const drafts = require('../drafts');
const fixtures = require('../../../test/annotation-fixtures');
const selection = require('../selection');
const viewer = require('../viewer');
const uiConstants = require('../../../ui-constants');
const unroll = require('../../../../shared/test/util').unroll;
......@@ -14,7 +15,7 @@ const { actions, selectors } = annotations;
* Create a Redux store which handles annotation, selection and draft actions.
*/
function createStore() {
return createStoreFromModules([annotations, selection, drafts], [{}, {}, {}]);
return createStoreFromModules([annotations, selection, drafts, viewer], [{}]);
}
// Tests for most of the functionality in reducers/annotations.js are currently
......
'use strict';
const viewer = require('../viewer');
const createStore = require('../../create-store');
const util = require('../../util');
describe('store/modules/viewer', function() {
let store;
const { init, actions, selectors } = viewer;
const update = util.createReducer(viewer.update);
describe('viewer reducer', function() {
beforeEach(() => {
store = createStore([viewer]);
});
describe('#setAppIsSidebar', function() {
it('sets a flag indicating that the app is not the sidebar', function() {
store.setAppIsSidebar(false);
assert.isFalse(store.isSidebar());
});
it('sets a flag indicating that the app is the sidebar', function() {
const state = update(init(), actions.setAppIsSidebar(true));
assert.isTrue(selectors.isSidebar(state));
store.setAppIsSidebar(true);
assert.isTrue(store.isSidebar());
});
it('sets a flag indicating that the app is not the sidebar', function() {
const state = update(init(), actions.setAppIsSidebar(false));
assert.isFalse(selectors.isSidebar(state));
it('sets a flag indicating that highlights are visible', function() {
store.setShowHighlights(true);
assert.isTrue(store.getRootState().viewer.visibleHighlights);
});
it('sets a flag indicating that highlights are not visible', function() {
store.setShowHighlights(false);
assert.isFalse(store.getRootState().viewer.visibleHighlights);
});
});
});
......@@ -49,11 +49,12 @@ function setShowHighlights(show) {
* client, as opposed to the standalone annotation page or stream views.
*/
function isSidebar(state) {
return state.isSidebar;
return state.viewer.isSidebar;
}
module.exports = {
init: init,
namespace: 'viewer',
update: update,
actions: {
setAppIsSidebar: setAppIsSidebar,
......
......@@ -363,7 +363,10 @@ describe('store', function() {
'sets the visibleHighlights state flag to #state',
function(testCase) {
store.setShowHighlights(testCase.state);
assert.equal(store.getState().visibleHighlights, testCase.state);
assert.equal(
store.getRootState().viewer.visibleHighlights,
testCase.state
);
},
[{ state: true }, { state: false }]
);
......
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