Skip to content
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

Prevent double click on links (logout bug) #1633

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
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
17 changes: 14 additions & 3 deletions src/components/atoms/links/Link.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState } from "react";
import { getLinkHandler } from "./getLinkHandler";

export interface LinkProps {
Expand Down Expand Up @@ -28,6 +28,8 @@ const Link: React.FC<LinkProps> = ({
stopPropagation = false,
isHiddenFromScreenReaders
}) => {
const [isLoading, setIsLoading] = useState(false);

const handleClick = getLinkHandler({
type: "click",
isNewTab,
Expand All @@ -45,11 +47,20 @@ const Link: React.FC<LinkProps> = ({
});

const onclickHandler = onClick
? (
? async (
e:
| React.MouseEvent<HTMLAnchorElement>
| React.KeyboardEvent<HTMLAnchorElement>
) => onClick().then(() => handleClick(e))
) => {
if (isLoading) return; // Prevent further clicks
setIsLoading(true); // Set loading state to true
try {
await onClick(); // Await the provided onClick
handleClick(e); // Call handleClick after onClick resolves
} finally {
setIsLoading(false); // Reset loading state
}
}
: handleClick;

return (
Expand Down
Loading