Commit 94be4cad authored by Robert Knight's avatar Robert Knight Committed by GitHub

Merge pull request #340 from hypothesis/show-flagged-annots

Show the flagged status for annotations that user has flagged.
parents 1195af43 02fa8ab5
...@@ -207,7 +207,7 @@ function AnnotationController( ...@@ -207,7 +207,7 @@ function AnnotationController(
}; };
annotationMapper.flagAnnotation(vm.annotation).then(function(){ annotationMapper.flagAnnotation(vm.annotation).then(function(){
analytics.track(analytics.events.ANNOTATION_FLAGGED); analytics.track(analytics.events.ANNOTATION_FLAGGED);
vm.isFlagged = true; annotationUI.updateFlagStatus(vm.annotation.id, true);
}, onRejected); }, onRejected);
}; };
...@@ -482,6 +482,10 @@ function AnnotationController( ...@@ -482,6 +482,10 @@ function AnnotationController(
return annotationUI.isHiddenByModerator(vm.annotation.id); return annotationUI.isHiddenByModerator(vm.annotation.id);
}; };
vm.isFlagged = function() {
return vm.annotation.flagged;
};
vm.isReply = function () { vm.isReply = function () {
return isReply(vm.annotation); return isReply(vm.annotation);
}; };
......
...@@ -146,6 +146,7 @@ describe('annotation', function() { ...@@ -146,6 +146,7 @@ describe('annotation', function() {
fakeAnnotationUI = { fakeAnnotationUI = {
isHiddenByModerator: sandbox.stub().returns(false), isHiddenByModerator: sandbox.stub().returns(false),
updateFlagStatus: sandbox.stub().returns(true),
}; };
fakeDrafts = { fakeDrafts = {
......
...@@ -146,6 +146,20 @@ var update = { ...@@ -146,6 +146,20 @@ var update = {
return {annotations: []}; return {annotations: []};
}, },
UPDATE_FLAG_STATUS: function (state, action) {
var annotations = state.annotations.map(function (annot) {
var match = (annot.id && annot.id === action.id);
if (match) {
return Object.assign({}, annot, {
flagged: action.isFlagged,
});
} else {
return annot;
}
});
return {annotations: annotations};
},
UPDATE_ANCHOR_STATUS: function (state, action) { UPDATE_ANCHOR_STATUS: function (state, action) {
var annotations = state.annotations.map(function (annot) { var annotations = state.annotations.map(function (annot) {
var match = (annot.id && annot.id === action.id) || var match = (annot.id && annot.id === action.id) ||
...@@ -166,6 +180,22 @@ var update = { ...@@ -166,6 +180,22 @@ var update = {
var actions = util.actionTypes(update); var actions = util.actionTypes(update);
/**
* Updating the flagged status of an annotation.
*
* @param {string} id - Annotation ID
* @param {boolean} isFlagged - The flagged status of the annotation. True if
* the user has flagged the annotation.
*
*/
function updateFlagStatus(id, isFlagged) {
return {
type: actions.UPDATE_FLAG_STATUS,
id: id,
isFlagged: isFlagged,
};
}
/** Add annotations to the currently displayed set. */ /** Add annotations to the currently displayed set. */
function addAnnotations(annotations, now) { function addAnnotations(annotations, now) {
now = now || new Date(); now = now || new Date();
...@@ -297,6 +327,7 @@ module.exports = { ...@@ -297,6 +327,7 @@ module.exports = {
clearAnnotations: clearAnnotations, clearAnnotations: clearAnnotations,
removeAnnotations: removeAnnotations, removeAnnotations: removeAnnotations,
updateAnchorStatus: updateAnchorStatus, updateAnchorStatus: updateAnchorStatus,
updateFlagStatus: updateFlagStatus,
}, },
// Selectors // Selectors
......
...@@ -190,7 +190,7 @@ ...@@ -190,7 +190,7 @@
</span> </span>
<span ng-if="vm.isThirdPartyUser()"> <span ng-if="vm.isThirdPartyUser()">
<button class="btn btn-clean annotation-action-btn" <button class="btn btn-clean annotation-action-btn"
ng-if="!vm.isFlagged" ng-if="!vm.isFlagged()"
ng-click="vm.flag()" ng-click="vm.flag()"
ng-disabled="vm.isDeleted()" ng-disabled="vm.isDeleted()"
aria-label="Flag" aria-label="Flag"
...@@ -198,7 +198,7 @@ ...@@ -198,7 +198,7 @@
<i class="h-icon-annotation-flag btn-icon"></i> <i class="h-icon-annotation-flag btn-icon"></i>
</button> </button>
<button class="btn btn-clean annotation-action-btn" <button class="btn btn-clean annotation-action-btn"
ng-if="vm.isFlagged" ng-if="vm.isFlagged()"
ng-disabled="vm.isDeleted()" ng-disabled="vm.isDeleted()"
aria-label="Annotation has been flagged" aria-label="Annotation has been flagged"
h-tooltip> h-tooltip>
......
...@@ -507,6 +507,15 @@ describe('annotationUI', function () { ...@@ -507,6 +507,15 @@ describe('annotationUI', function () {
}); });
}); });
describe('#updateFlagStatus', function () {
it('updates the flaged status of an annotation', function () {
var annot = defaultAnnotation();
annotationUI.addAnnotations([annot]);
annotationUI.updateFlagStatus(annot.id, true);
assert.equal(annotationUI.getState().annotations[0].flagged, true);
});
});
describe('selector functions', function () { describe('selector functions', function () {
// The individual state management modules in reducers/*.js define various // The individual state management modules in reducers/*.js define various
// 'selector' functions for extracting data from the app state. These are // 'selector' functions for extracting data from the app state. These are
......
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