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 [8/n] Show modal on UI click #1049

Merged
merged 1 commit into from
Jan 28, 2024
Merged
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
@@ -1,12 +1,17 @@
import { Button, Tooltip } from "@mantine/core";
import { Button, Container, Flex, Modal, Text, Tooltip } from "@mantine/core";
import { memo, useState } from "react";
import { useDisclosure } from "@mantine/hooks";
import CopyButton from "../CopyButton";

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

export default memo(function ShareButton({ onShare }: Props) {
const [isModalOpened, { open: openModal, close: closeModal }] =
useDisclosure(false);
const [isLoading, setIsLoading] = useState<boolean>(false);
const [shareUrl, setShareUrl] = useState<string>("");

const onClick = async () => {
if (isLoading) {
Expand All @@ -20,29 +25,39 @@ export default memo(function ShareButton({ onShare }: Props) {
if (!shareUrl) {
return;
}

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

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 (
const button = (
<Tooltip label={tooltipMessage} withArrow>
<div>{button}</div>
<Button
loaderPosition="center"
loading={isLoading}
onClick={onClick}
p="xs"
size="xs"
variant="filled"
>
Share
</Button>
</Tooltip>
);

return (
<>
<Modal opened={isModalOpened} onClose={closeModal} title="AIConfig URL">
<Container p={0} mr={-8}>
<Flex direction="row">
<Text truncate>{shareUrl}</Text>
<CopyButton value={shareUrl} contentLabel="AIConfig URL" />
</Flex>
</Container>
</Modal>
{button}
</>
);
});
Loading