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

Share Button [7/n]: Display loading UI #1044

Merged
merged 1 commit into from
Jan 26, 2024
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import {
import { IconDeviceFloppy } from "@tabler/icons-react";
import CopyButton from "./CopyButton";
import AIConfigEditorThemeProvider from "../themes/AIConfigEditorThemeProvider";
import ShareButton from "./global/ShareButton";
import PromptsContainer from "./prompt/PromptsContainer";

type Props = {
Expand Down Expand Up @@ -155,10 +156,8 @@ export default function AIConfigEditor({
return;
}
try {
// TODO: While uploading, show a loader state for share button
const { share_url: shareUrl } = await shareCallback();
// TODO: display the shareUrl in a dialog
// console.log("Share URL: ", shareUrl);
return shareUrl;
} catch (err: unknown) {
const message = (err as RequestCallbackError).message ?? null;
showNotification({
Expand Down Expand Up @@ -962,19 +961,7 @@ export default function AIConfigEditor({
<Flex justify="flex-end" mt="md" mb="xs">
{!readOnly && (
<Group>
{shareCallback && (
<Tooltip label={"Create a link to share your AIConfig!"}>
<Button
loading={undefined}
onClick={onShare}
size="xs"
variant="filled"
>
Share
</Button>
</Tooltip>
)}

{shareCallback && <ShareButton onShare={onShare} />}
{onClearOutputs && (
<Button
loading={undefined}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Button, Tooltip } from "@mantine/core";
import { memo, useState } from "react";

type Props = {
onShare: () => Promise<string | void>;
};

export default memo(function ShareButton({ onShare }: Props) {
const [isLoading, setIsLoading] = useState<boolean>(false);

const onClick = async () => {
if (isLoading) {
return;
}

setIsLoading(true);
const shareUrl: string | void = await onShare();
setIsLoading(false);

if (!shareUrl) {
return;
}

console.log("Share URL: ", shareUrl);
};

const button = (
<Button
loaderPosition="center"
loading={isLoading}
onClick={onClick}
p="xs"
size="xs"
variant="filled"
>
Share
</Button>
);

const tooltipMessage: string = isLoading
? "Generating share link..."
: "Create a link to share your AIConfig!";
return (
<Tooltip label={tooltipMessage} withArrow>
<div>{button}</div>
</Tooltip>
);
});
Loading