Commit b984fba2 authored by Robert Knight's avatar Robert Knight

Cast `annotation.id` to a string in a few places

The `id` property only exists once an annotation has been saved. Add
casts in a few places where we know that this is the case.
parent 7651c8f1
......@@ -58,7 +58,10 @@ export default function AnnotationHeader({
const showReplyButton = replyCount > 0 && isCollapsedReply;
const showExtendedInfo = !isReply(annotation);
const onReplyCountClick = () => setExpanded(annotation.id, true);
const onReplyCountClick = () =>
// If an annotation has replies it must have been saved and therefore have
// an ID.
setExpanded(/** @type {string} */ (annotation.id), true);
return (
<header className="annotation-header">
......
......@@ -105,7 +105,10 @@ function Annotation({
}
};
const onToggleReplies = () => setExpanded(annotation.id, !!threadIsCollapsed);
const onToggleReplies = () =>
// nb. We assume the annotation has an ID here because it is not possible
// to create replies until the annotation has been saved.
setExpanded(/** @type {string} */ (annotation.id), !!threadIsCollapsed);
return (
/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */
......
......@@ -102,12 +102,13 @@ function receiveRealTimeUpdates({
ann.group === groups.selectors.focusedGroupId(getState()) ||
route.selectors.route(getState()) !== 'sidebar'
) {
pendingUpdates[ann.id] = ann;
pendingUpdates[/** @type {string} */ (ann.id)] = ann;
}
});
deletedAnnotations.forEach(ann => {
const id = /** @type {string} */ (ann.id);
// Discard any pending but not-yet-applied updates for this annotation
delete pendingUpdates[ann.id];
delete pendingUpdates[id];
// If we already have this annotation loaded, then record a pending
// deletion. We do not check the group of the annotation here because a)
......@@ -115,8 +116,8 @@ function receiveRealTimeUpdates({
// even if the annotation is from the current group, it might be for a
// new annotation (saved in pendingUpdates and removed above), that has
// not yet been loaded.
if (annotations.selectors.annotationExists(getState(), ann.id)) {
pendingDeletions[ann.id] = true;
if (annotations.selectors.annotationExists(getState(), id)) {
pendingDeletions[id] = true;
}
});
dispatch({
......
......@@ -191,5 +191,5 @@ export default function filterAnnotations(annotations, filters) {
.filter(ann => {
return ann.id && rootFilter.matches(ann);
})
.map(ann => ann.id);
.map(ann => /** @type {string} */ (ann.id));
}
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