-
Notifications
You must be signed in to change notification settings - Fork 80
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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 ``` 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
1 parent
a9c75aa
commit 2209727
Showing
2 changed files
with
52 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
python/src/aiconfig/editor/client/src/components/global/ShareButton.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
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} | ||
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> | ||
); | ||
}); |