diff --git a/packages/react-chat/src/components/Chat/ChatInput.tsx b/packages/react-chat/src/components/Chat/ChatInput.tsx index fd1ddfc6..9a148b8c 100644 --- a/packages/react-chat/src/components/Chat/ChatInput.tsx +++ b/packages/react-chat/src/components/Chat/ChatInput.tsx @@ -56,7 +56,7 @@ export function ChatInput({ theme, addMessage }: ChatInputProps) { setContent(""); } }, - [] + [content, imageUint] ); return ( diff --git a/packages/react-chat/src/components/Chat/ChatMessageContent.tsx b/packages/react-chat/src/components/Chat/ChatMessageContent.tsx index fc1815fe..85cd4fcc 100644 --- a/packages/react-chat/src/components/Chat/ChatMessageContent.tsx +++ b/packages/react-chat/src/components/Chat/ChatMessageContent.tsx @@ -15,12 +15,14 @@ type ChatMessageContentProps = { message: ChatMessage; fetchMetadata?: (url: string) => Promise; setImage: (image: string) => void; + setLinkOpen: (link: string) => void; }; export function ChatMessageContent({ message, fetchMetadata, setImage, + setLinkOpen, }: ChatMessageContentProps) { const { content, image } = useMemo(() => message, [message]); const [elements, setElements] = useState<(string | React.ReactElement)[]>([ @@ -40,7 +42,7 @@ export function ChatMessageContent({ ? match : "https://" + match; newSplit.push( - + setLinkOpen(link)}> {match} , split[idx + 1] @@ -88,9 +90,7 @@ export function ChatMessageContent({ )} {openGraph && ( - window?.open(link, "_blank", "noopener")?.focus()} - > + setLinkOpen(link ?? "")}> {openGraph["og:title"]} @@ -167,7 +167,7 @@ const ContentWrapper = styled.div` flex-direction: column; `; -const Link = styled.a` +const Link = styled.div` text-decoration: underline; color: ${({ theme }) => theme.memberNameColor}; `; diff --git a/packages/react-chat/src/components/Chat/ChatMessages.tsx b/packages/react-chat/src/components/Chat/ChatMessages.tsx index 5ab7e0e4..0650df27 100644 --- a/packages/react-chat/src/components/Chat/ChatMessages.tsx +++ b/packages/react-chat/src/components/Chat/ChatMessages.tsx @@ -5,6 +5,7 @@ import { ChatMessage } from "../../models/ChatMessage"; import { Metadata } from "../../models/Metadata"; import { LoadingIcon } from "../Icons/LoadingIcon"; import { UserIcon } from "../Icons/UserIcon"; +import { LinkModal } from "../Modals/LinkModal"; import { PictureModal } from "../Modals/PictureModal"; import { textSmallStyles } from "../Text"; @@ -53,7 +54,7 @@ export function ChatMessages({ }, [ref, scrollOnBot]); const [image, setImage] = useState(""); - + const [link, setLink] = useState(""); return ( setImage("")} image={image} /> + setLink("")} link={link} /> @@ -93,6 +95,7 @@ export function ChatMessages({ message={message} fetchMetadata={fetchMetadata} setImage={setImage} + setLinkOpen={setLink} /> diff --git a/packages/react-chat/src/components/Modals/LinkModal.tsx b/packages/react-chat/src/components/Modals/LinkModal.tsx new file mode 100644 index 00000000..9b34883a --- /dev/null +++ b/packages/react-chat/src/components/Modals/LinkModal.tsx @@ -0,0 +1,67 @@ +import React from "react"; +import styled from "styled-components"; + +import { textMediumStyles } from "../Text"; + +import { BasicModalProps, Modal } from "./Modal"; + +interface LinkModalProps extends BasicModalProps { + link: string; +} + +export const LinkModal = ({ isVisible, onClose, link }: LinkModalProps) => { + return ( + +
+ Are you sure you want to visit {link} +
+ + No + { + window?.open(link, "_blank", "noopener")?.focus(); + onClose(); + }} + > + Yes + + +
+ ); +}; + +const ButtonSection = styled.div` + display: flex; +`; + +const Section = styled.div` + padding: 20px 16px; + + & + & { + border-top: 1px solid ${({ theme }) => theme.border}; + } +`; + +const Text = styled.p` + color: ${({ theme }) => theme.primary}; + + ${textMediumStyles} +`; + +const ButtonYes = styled.button` + background-color: ${({ theme }) => theme.tertiary}; + padding: 10px; + width: 50px; + height: 40px; + border-radius: 10px; + margin: 10px; +`; + +const ButtonNo = styled.button` + background-color: ${({ theme }) => theme.secondary}; + padding: 10px; + width: 50px; + height: 40px; + border-radius: 10px; + margin: 10px; +`;