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