From 7d90ad9ae4f0606cdec396681426c6b0e1a54411 Mon Sep 17 00:00:00 2001 From: Maria Rushkova <66270386+mrushkova@users.noreply.github.com> Date: Mon, 13 Dec 2021 18:09:26 +0100 Subject: [PATCH] Toast message (#155) --- packages/react-chat/src/components/Chat.tsx | 3 + .../src/components/Modals/ProfileModal.tsx | 12 +++ .../react-chat/src/components/ReactChat.tsx | 13 ++- .../src/components/Skeleton/Loading.tsx | 3 +- .../components/ToastMessages/ToastMessage.tsx | 91 +++++++++++++++++++ .../ToastMessages/ToastMessageList.tsx | 31 +++++++ .../react-chat/src/contexts/toastProvider.tsx | 26 ++++++ packages/react-chat/src/models/Toast.ts | 4 + packages/react-chat/src/styles/themes.ts | 5 + 9 files changed, 181 insertions(+), 7 deletions(-) create mode 100644 packages/react-chat/src/components/ToastMessages/ToastMessage.tsx create mode 100644 packages/react-chat/src/components/ToastMessages/ToastMessageList.tsx create mode 100644 packages/react-chat/src/contexts/toastProvider.tsx create mode 100644 packages/react-chat/src/models/Toast.ts diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx index 99149afb..64bad96c 100644 --- a/packages/react-chat/src/components/Chat.tsx +++ b/packages/react-chat/src/components/Chat.tsx @@ -12,6 +12,7 @@ import { Members } from "./Members/Members"; import { CommunityModal } from "./Modals/CommunityModal"; import { EditModal } from "./Modals/EditModal"; import { ProfileModal } from "./Modals/ProfileModal"; +import { ToastMessageList } from "./ToastMessages/ToastMessageList"; function Modals() { return ( @@ -45,6 +46,7 @@ export function Chat() { {showMembers && !narrow && state === ChatState.ChatBody && } {state === ChatState.ChatCreation && } + ); } @@ -53,6 +55,7 @@ const ChatWrapper = styled.div` width: 100%; height: 100%; display: flex; + position: relative; `; const ChannelsWrapper = styled.div` diff --git a/packages/react-chat/src/components/Modals/ProfileModal.tsx b/packages/react-chat/src/components/Modals/ProfileModal.tsx index 153c30f1..2d85e124 100644 --- a/packages/react-chat/src/components/Modals/ProfileModal.tsx +++ b/packages/react-chat/src/components/Modals/ProfileModal.tsx @@ -5,6 +5,7 @@ import styled from "styled-components"; import { useActivities } from "../../contexts/activityProvider"; import { useIdentity } from "../../contexts/identityProvider"; import { useModal } from "../../contexts/modalProvider"; +import { useToasts } from "../../contexts/toastProvider"; import { useManageContact } from "../../hooks/useManageContact"; import { copy } from "../../utils"; import { buttonStyles } from "../Buttons/buttonStyle"; @@ -42,6 +43,8 @@ export const ProfileModal = () => { ); const { setActivities } = useActivities(); + const { setToasts } = useToasts(); + const { setModal } = useModal(ProfileModalName); const identity = useIdentity(); const isUser = useMemo( @@ -160,6 +163,7 @@ export const ProfileModal = () => { maxLength={280} onInput={(e) => setRequest(e.currentTarget.value)} required + autoFocus /> )} @@ -201,7 +205,15 @@ export const ProfileModal = () => { status: "sent", }, ]), + setToasts((prev) => [ + ...prev, + { + id: id + request, + type: "request", + }, + ]), setRequestCreation(false), + setModal(false), setRequest(""); }} > diff --git a/packages/react-chat/src/components/ReactChat.tsx b/packages/react-chat/src/components/ReactChat.tsx index c1bdaa96..4af8590f 100644 --- a/packages/react-chat/src/components/ReactChat.tsx +++ b/packages/react-chat/src/components/ReactChat.tsx @@ -6,6 +6,7 @@ import { ActivityProvider } from "../contexts/activityProvider"; import { FetchMetadataProvider } from "../contexts/fetchMetadataProvider"; import { ModalProvider } from "../contexts/modalProvider"; import { NarrowProvider } from "../contexts/narrowProvider"; +import { ToastProvider } from "../contexts/toastProvider"; import { Metadata } from "../models/Metadata"; import { GlobalStyle } from "../styles/GlobalStyle"; import { Theme } from "../styles/themes"; @@ -30,11 +31,13 @@ export function ReactChat({ - - - -