Skip to content

Commit

Permalink
Fix annotation on-click Canvas check in ramp-hooks
Browse files Browse the repository at this point in the history
  • Loading branch information
Dananji committed Dec 23, 2024
1 parent 86ef601 commit e0064dd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 19 deletions.
31 changes: 15 additions & 16 deletions src/components/MarkersDisplay/Annotations/AnnotationRow.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const AnnotationRow = ({ annotation, displayMotivations }) => {
const { start, end } = time;

const { player } = useMediaPlayer();
const { isCurrentCanvas } = useAnnotations({ canvasId });
const { checkCanvas } = useAnnotations({ canvasId });

/**
* Display only the annotations with at least one of the specified motivations
Expand All @@ -31,21 +31,20 @@ const AnnotationRow = ({ annotation, displayMotivations }) => {
*/
const handleOnClick = useCallback((e) => {
e.preventDefault();
if (isCurrentCanvas) {
const currentTime = start;
if (player) {
const { start, end } = player.targets[0];
switch (true) {
case currentTime >= start && currentTime <= end:
player.currentTime(currentTime);
break;
case currentTime < start:
player.currentTime(start);
break;
case currentTime > end:
player.currentTime(end);
break;
}
checkCanvas();
const currentTime = start;
if (player) {
const { start, end } = player.targets[0];
switch (true) {
case currentTime >= start && currentTime <= end:
player.currentTime(currentTime);
break;
case currentTime < start:
player.currentTime(start);
break;
case currentTime > end:
player.currentTime(end);
break;
}
}
}, [annotation, player]);
Expand Down
6 changes: 3 additions & 3 deletions src/services/ramp-hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -1075,7 +1075,7 @@ export const useTranscripts = ({
* @param {Object} obj
* @param {String} obj.canvasId
* @returns {
* isCurrentCanvas
* checkCanvas
* }
*/
export const useAnnotations = ({ canvasId }) => {
Expand All @@ -1092,7 +1092,7 @@ export const useAnnotations = ({ canvasId }) => {
* Update current Canvas in state if the clicked Annotation is pointing
* to a different Canvas within the given Manifest
*/
useEffect(() => {
const checkCanvas = useCallback(() => {
if (!isCurrentCanvas) {
const clickedCanvas = allCanvases.filter((c) => c.canvasId === canvasId);
if (clickedCanvas?.length > 0) {
Expand All @@ -1102,5 +1102,5 @@ export const useAnnotations = ({ canvasId }) => {
}
}, [isCurrentCanvas]);

return { isCurrentCanvas };
return { checkCanvas };
};

0 comments on commit e0064dd

Please sign in to comment.