Skip to content

fix double and more insert of links #107

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions imports/cyto-react-links-card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,44 @@ const variants = {
}
}
};
//fix double insert of links
const SubmitButton = ({ onSubmit, selectedLink, ...props }) => {
const [isSubmitting, setIsSubmitting] = useState(false);

const handleOnSubmit = async () => {
if (isSubmitting) return;

setIsSubmitting(true);
try {
if (onSubmit && selectedLink) {
await onSubmit(selectedLink);
}
} catch (error) {
console.error('Error during submitting', error);
} finally {
setIsSubmitting(false);
}
};

return (
<SlideFade in={!!selectedLink} offsetX='-0.5rem' style={{ position: 'absolute', bottom: 0, right: '-2.8rem' }}>
<IconButton
isRound
variant='solid'
bg='primary'
// color='white'
aria-label='submit button'
icon={<BsCheck2 />}
onClick={handleOnSubmit}
isDisabled={isSubmitting}
{...props}
/>
</SlideFade>
);
};

export default SubmitButton;


export const TypeIcon = React.memo<any>(({
src,
Expand Down Expand Up @@ -357,17 +395,14 @@ export const CytoReactLinksCard = React.memo<any>(({
: <Center height='100%'><DotsLoader /></Center>
}
</Box>
<SlideFade in={!!selectedLink} offsetX='-0.5rem' style={{position: 'absolute', bottom: 0, right: '-2.8rem'}}>
<IconButton
isRound
variant='solid'
bg='primary'
// color='white'
aria-label='submit button'
icon={<BsCheck2 />}
onClick={() => onSubmit && onSubmit(selectedLink)}
/>
</SlideFade>
<SubmitButton
selectedLink={selectedLink}
onSubmit={async () => {
if (selectedLink) {
await onSubmit(selectedLink);
}
}}
/>
{!!onClose && <Box pos='absolute' top={0} right='-2.8rem'>
<IconButton
isRound
Expand All @@ -379,4 +414,4 @@ export const CytoReactLinksCard = React.memo<any>(({
/>
</Box>}
</>);
})
})