From 7bb7f059b87509c55e28d4030b30c9fa4497d059 Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Tue, 12 Oct 2021 14:58:28 +0200 Subject: [PATCH] Add link modal and fix input (#67) --- .../src/components/Chat/ChatInput.tsx | 2 +- .../components/Chat/ChatMessageContent.tsx | 10 +-- .../src/components/Chat/ChatMessages.tsx | 5 +- .../src/components/Modals/LinkModal.tsx | 67 +++++++++++++++++++ 4 files changed, 77 insertions(+), 7 deletions(-) create mode 100644 packages/react-chat/src/components/Modals/LinkModal.tsx diff --git a/packages/react-chat/src/components/Chat/ChatInput.tsx b/packages/react-chat/src/components/Chat/ChatInput.tsx index fd1ddfc..9a148b8 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 fc1815f..85cd4fc 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 5ab7e0e..0650df2 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 0000000..9b34883 --- /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; +`;