Skip to content

Commit

Permalink
Only show trashcan when it will do something
Browse files Browse the repository at this point in the history
  • Loading branch information
RoyEJohnson committed Sep 18, 2024
1 parent 20b7c5c commit c6f5135
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
5 changes: 3 additions & 2 deletions src/app/content/highlights/components/ColorPicker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ const ColorPicker = ({className, ...props}: Props) => {
},
[color]
);
const hasOnRemove = 'onRemove' in props && props.onRemove;

React.useEffect(focusOnSelected, [focusOnSelected]);

Expand Down Expand Up @@ -142,10 +143,10 @@ const ColorPicker = ({className, ...props}: Props) => {
? props.onRemove ? props.onRemove() : null
: props.onChange(style.label)}
/>)}
{ props.size === 'small' ? null :
{ (!hasOnRemove || props.size === 'small') ? null :
<TrashButton
size={props.size}
onClick={() => 'onRemove' in props && props.onRemove ? props.onRemove() : null}
onClick={props.onRemove}
/>
}
</fieldset>
Expand Down
16 changes: 10 additions & 6 deletions src/app/content/highlights/components/EditCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -251,13 +251,17 @@ function ActiveEditCard({
function useOnRemove(props: EditCardProps, pendingAnnotation: string) {
const onRemove = props.onRemove;
const trackDeleteHighlight = useAnalyticsEvent('deleteHighlight');
const removeAndTrack = React.useCallback(
() => {
if (props.data) {
onRemove();
trackDeleteHighlight(props.data.color);
}
},
[onRemove, props.data, trackDeleteHighlight]
);

return React.useCallback(() => {
if (props.data && !props.data.annotation && !pendingAnnotation) {
onRemove();
trackDeleteHighlight(props.data.color);
}
}, [onRemove, pendingAnnotation, props.data, trackDeleteHighlight]);
return props.data && !props.data.annotation && !pendingAnnotation && props.data.color ? removeAndTrack : null;
}

function AnnotationEditor({
Expand Down

0 comments on commit c6f5135

Please sign in to comment.