Skip to content

Commit

Permalink
Share Button [7/n]: Display loading UI
Browse files Browse the repository at this point in the history
Created a separate component for the shareButton to manage the `isLoading` state and show that in the UI

## Test Plan
Rebase on then do: #1045

Go to `aiconfig/python/src/aiconfig/editor/client` and run this command:
```
rm -rf node_modules && yarn && yarn build
```

Then go to `aiconfig` dir and run this command:
```
aiconfig_path  =./cookbooks/Gradio/huggingface.aiconfig.json
parsers_path=./cookbooks/Gradio/hf_model_parsers.py
aiconfig edit --aiconfig-path=$aiconfig_path --server-port=8080 --server-mode=debug_servers --parsers-module-path=$parsers_path
```

No Error Testing

https://github.com/lastmile-ai/aiconfig/assets/151060367/0c177c59-54b8-4d04-adfa-aea6d78f5f07

Error Testing

https://github.com/lastmile-ai/aiconfig/assets/151060367/1abcce37-8ba4-4513-b826-ea0f9d7bb720
  • Loading branch information
Rossdan Craig rossdan@lastmileai.dev committed Jan 26, 2024
1 parent a9c75aa commit cc17dab
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 16 deletions.
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,50 @@
import { Button, Flex, Loader, Tooltip } from "@mantine/core";
import { IconPlayerPlayFilled, IconPlayerStop } from "@tabler/icons-react";
import { memo, useContext, useState } from "react";
import AIConfigContext from "../../contexts/AIConfigContext";

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
loading={isLoading}
disabled={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>
);
});

0 comments on commit cc17dab

Please sign in to comment.