Skip to content

Commit 5b2d21f

Browse files
author
Rossdan Craig rossdan@lastmileai.dev
committed
Share Button [7/n]: Display loading UI
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 ``` https://github.com/lastmile-ai/aiconfig/assets/151060367/0c177c59-54b8-4d04-adfa-aea6d78f5f07 https://github.com/lastmile-ai/aiconfig/assets/151060367/1abcce37-8ba4-4513-b826-ea0f9d7bb720 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 ```
1 parent a9c75aa commit 5b2d21f

File tree

2 files changed

+53
-16
lines changed

2 files changed

+53
-16
lines changed

python/src/aiconfig/editor/client/src/components/AIConfigEditor.tsx

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ import {
5656
import { IconDeviceFloppy } from "@tabler/icons-react";
5757
import CopyButton from "./CopyButton";
5858
import AIConfigEditorThemeProvider from "../themes/AIConfigEditorThemeProvider";
59+
import ShareButton from "./global/ShareButton";
5960
import PromptsContainer from "./prompt/PromptsContainer";
6061

6162
type Props = {
@@ -155,10 +156,8 @@ export default function AIConfigEditor({
155156
return;
156157
}
157158
try {
158-
// TODO: While uploading, show a loader state for share button
159159
const { share_url: shareUrl } = await shareCallback();
160-
// TODO: display the shareUrl in a dialog
161-
// console.log("Share URL: ", shareUrl);
160+
return shareUrl;
162161
} catch (err: unknown) {
163162
const message = (err as RequestCallbackError).message ?? null;
164163
showNotification({
@@ -962,19 +961,7 @@ export default function AIConfigEditor({
962961
<Flex justify="flex-end" mt="md" mb="xs">
963962
{!readOnly && (
964963
<Group>
965-
{shareCallback && (
966-
<Tooltip label={"Create a link to share your AIConfig!"}>
967-
<Button
968-
loading={undefined}
969-
onClick={onShare}
970-
size="xs"
971-
variant="filled"
972-
>
973-
Share
974-
</Button>
975-
</Tooltip>
976-
)}
977-
964+
{shareCallback && <ShareButton onShare={onShare} />}
978965
{onClearOutputs && (
979966
<Button
980967
loading={undefined}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import { Button, Flex, Loader, Tooltip } from "@mantine/core";
2+
import { IconPlayerPlayFilled, IconPlayerStop } from "@tabler/icons-react";
3+
import { memo, useContext, useState } from "react";
4+
import AIConfigContext from "../../contexts/AIConfigContext";
5+
6+
type Props = {
7+
onShare: () => Promise<string | void>;
8+
};
9+
10+
export default memo(function ShareButton({ onShare }: Props) {
11+
const [isLoading, setIsLoading] = useState<boolean>(false);
12+
13+
const onClick = async () => {
14+
if (isLoading) {
15+
return;
16+
}
17+
18+
setIsLoading(true);
19+
const shareUrl: string | void = await onShare();
20+
setIsLoading(false);
21+
22+
if (!shareUrl) {
23+
return;
24+
}
25+
26+
console.log("Share URL: ", shareUrl);
27+
};
28+
29+
const button = (
30+
<Button
31+
loading={isLoading}
32+
disabled={isLoading}
33+
onClick={onClick}
34+
p="xs"
35+
size="xs"
36+
variant="filled"
37+
>
38+
Share
39+
</Button>
40+
);
41+
42+
const tooltipMessage: string = isLoading
43+
? "Generating share link..."
44+
: "Create a link to share your AIConfig!";
45+
return (
46+
<Tooltip label={tooltipMessage} withArrow>
47+
<div>{button}</div>
48+
</Tooltip>
49+
);
50+
});

0 commit comments

Comments
 (0)