Skip to content

Commit

Permalink
Add loading state to link_content
Browse files Browse the repository at this point in the history
  • Loading branch information
kowalczyk-krzysztof committed Oct 18, 2024
1 parent 7178062 commit 5ae2230
Showing 1 changed file with 4 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export const LinkContent = ({
const [urlParams] = useState<UrlParams | undefined>(undefined);
const [isTextCopied, setTextCopied] = useState(false);
const [shortUrlCache, setShortUrlCache] = useState<string | undefined>(undefined);
const [isLoading, setIsLoading] = useState(false);

const getUrlWithUpdatedParams = useCallback(
(tempUrl: string): string => {
Expand Down Expand Up @@ -99,6 +100,7 @@ export const LinkContent = ({
}, [shareableUrlLocatorParams, urlService.shortUrls, getSnapshotUrl, setShortUrlCache]);

const copyUrlHelper = useCallback(async () => {
setIsLoading(true);
let urlToCopy = url;

if (!urlToCopy || delegatedShareUrlHandler) {
Expand All @@ -112,6 +114,7 @@ export const LinkContent = ({
copyToClipboard(urlToCopy);
setUrl(urlToCopy);
setTextCopied(true);
setIsLoading(false);
return urlToCopy;
}, [url, delegatedShareUrlHandler, allowShortUrl, createShortUrl, getSnapshotUrl]);

Expand Down Expand Up @@ -164,6 +167,7 @@ export const LinkContent = ({
onBlur={() => (objectType === 'lens' && isDirty ? null : setTextCopied(false))}
onClick={copyUrlHelper}
color={objectType === 'lens' && isDirty ? 'warning' : 'primary'}
isLoading={isLoading}
>
<FormattedMessage id="share.link.copyLinkButton" defaultMessage="Copy link" />
</EuiButton>
Expand Down

0 comments on commit 5ae2230

Please sign in to comment.