Skip to content

Commit

Permalink
Fix lint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
RobinNagpal committed Nov 10, 2021
1 parent dad25ef commit bdf1426
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
9 changes: 5 additions & 4 deletions src/components/Annotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ function Annotation(options: AnnotationProps & WithRelativeMousePosProps) {
idFunction,

onSelectedAnnotationUpdate,
onAnnotationClick: onAnnotationClickProp,

renderShape,
renderEditor,
Expand Down Expand Up @@ -132,7 +133,7 @@ function Annotation(options: AnnotationProps & WithRelativeMousePosProps) {
removeTargetTouchEventListeners();
}
}
}, [options.allowTouch]);
});

const setInnerRef = (el: HTMLImageElement | null) => {
if (el) {
Expand Down Expand Up @@ -247,10 +248,10 @@ function Annotation(options: AnnotationProps & WithRelativeMousePosProps) {
const onAnnotationClick = useCallback(
(annotation: IAnnotation) => {
setSelectedAnnotation(annotation);
props.onSelectedAnnotationUpdate(annotation, true);
props.onAnnotationClick(annotation);
onSelectedAnnotationUpdate(annotation, true);
onAnnotationClickProp(annotation);
},
[props.onAnnotationClick, props.onSelectedAnnotationUpdate]
[onAnnotationClickProp, onSelectedAnnotationUpdate]
);

useHandleEscapeEvent(unselectSelectedAnnotation, selectedAnnotation);
Expand Down
6 changes: 1 addition & 5 deletions src/components/Image/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React from 'react';
import { useEffect, useRef } from 'react';
import React, { useRef } from 'react';
import styled from 'styled-components';

const Img = styled.img`
Expand All @@ -18,9 +17,6 @@ interface ImageProps {

export default function Image(props: ImageProps) {
const imageRef = useRef<HTMLImageElement>(null);
useEffect(() => {
props.setInnerRef(imageRef.current);
}, [imageRef.current]);

const { alt, className, draggable, src, style } = props;
return (
Expand Down
44 changes: 23 additions & 21 deletions src/components/Stories/Common/AnnotationStoryTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,31 @@ export const argTypes: ArgTypes = {
},
};

export const BaseStoryTemplate: (
const StoryComponent: (args: AnnotationPropsOptional) => React.ReactElement = (
args: AnnotationPropsOptional
) => {
const [annotations, setAnnotations] = useState<any[]>(args.annotations || []);

return (
<div style={{ width: '800px' }}>
<Annotation
annotations={annotations}
onAnnotationsUpdate={setAnnotations}
{...args}
/>
</div>
);
};

export const BaseStoryTemplateWithAnnotations: (
config: AnnotationPropsOptional
) => Story<AnnotationPropsOptional> = (config: AnnotationPropsOptional) => {
let element = (args: AnnotationPropsOptional) => {
const [annotations, setAnnotations] = useState<any[]>(
config.annotations || []
);

return (
<div style={{ width: '800px' }}>
<Annotation
annotations={annotations}
onAnnotationsUpdate={setAnnotations}
{...args}
/>
</div>
);
};
return element;
return (args: AnnotationPropsOptional) =>
StoryComponent({ ...args, annotations: config.annotations });
};

export const DefaultAnnotationStoryTemplate: Story<AnnotationPropsOptional> =
BaseStoryTemplate({});
BaseStoryTemplateWithAnnotations({ annotations: [] });

export const ovalAnnotations = [
{
Expand Down Expand Up @@ -83,7 +85,7 @@ export const ovalAnnotations = [
];

export const OvalTemplateWithExistingAnnotations: Story<AnnotationPropsOptional> =
BaseStoryTemplate({
BaseStoryTemplateWithAnnotations({
annotations: ovalAnnotations,
});

Expand Down Expand Up @@ -143,7 +145,7 @@ export const rectangularAnnotations = [
];

export const RectangleTemplateWithExistingAnnotations: Story<AnnotationPropsOptional> =
BaseStoryTemplate({
BaseStoryTemplateWithAnnotations({
annotations: rectangularAnnotations,
});

Expand Down Expand Up @@ -216,6 +218,6 @@ export const pointAnnotations = [
];

export const PointTemplateWithExistingAnnotations: Story<AnnotationPropsOptional> =
BaseStoryTemplate({
BaseStoryTemplateWithAnnotations({
annotations: pointAnnotations,
});
2 changes: 1 addition & 1 deletion src/utils/useHandleEscapeEvent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,5 +18,5 @@ export default function useHandleEscapeEvent(
// Unbind the event listener on clean up
document.removeEventListener('keydown', handleKeyDown);
};
}, [selectedItem]);
}, [selectedItem, unselectSelectedAnnotation]);
}

0 comments on commit bdf1426

Please sign in to comment.