From e39bcd6bda20bc6ccfa5d36b90be901ae8817495 Mon Sep 17 00:00:00 2001
From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com>
Date: Tue, 4 Jan 2022 10:06:01 +0100
Subject: [PATCH] Disable input without identity (#168)
---
packages/react-chat/src/components/Chat/ChatBody.tsx | 11 ++++++++---
packages/react-chat/src/components/Chat/ChatInput.tsx | 11 ++++++++---
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/packages/react-chat/src/components/Chat/ChatBody.tsx b/packages/react-chat/src/components/Chat/ChatBody.tsx
index 0ca2ba63..03b05d46 100644
--- a/packages/react-chat/src/components/Chat/ChatBody.tsx
+++ b/packages/react-chat/src/components/Chat/ChatBody.tsx
@@ -1,6 +1,7 @@
import React, { useCallback, useEffect, useMemo, useState } from "react";
import styled from "styled-components";
+import { useIdentity } from "../../contexts/identityProvider";
import { useMessengerContext } from "../../contexts/messengerProvider";
import { useNarrow } from "../../contexts/narrowProvider";
import { Reply } from "../../hooks/useReply";
@@ -29,7 +30,7 @@ interface ChatBodyProps {
export function ChatBody({ onClick, showMembers, permission }: ChatBodyProps) {
const { messenger, activeChannel, communityData } = useMessengerContext();
const narrow = useNarrow();
-
+ const identity = useIdentity();
const [editGroup, setEditGroup] = useState(false);
const className = useMemo(() => (narrow ? "narrow" : ""), [narrow]);
@@ -78,7 +79,11 @@ export function ChatBody({ onClick, showMembers, permission }: ChatBodyProps) {
) : (
)}
-
+
>
)}
@@ -98,7 +103,7 @@ export function ChatBody({ onClick, showMembers, permission }: ChatBodyProps) {
) : (
<>
-
+
>
)}
diff --git a/packages/react-chat/src/components/Chat/ChatInput.tsx b/packages/react-chat/src/components/Chat/ChatInput.tsx
index 63f3d513..689364ea 100644
--- a/packages/react-chat/src/components/Chat/ChatInput.tsx
+++ b/packages/react-chat/src/components/Chat/ChatInput.tsx
@@ -28,9 +28,10 @@ import { textMediumStyles, textSmallStyles } from "../Text";
interface ChatInputProps {
reply: Reply | undefined;
setReply: (val: Reply | undefined) => void;
+ disabled: boolean;
}
-export function ChatInput({ reply, setReply }: ChatInputProps) {
+export function ChatInput({ reply, setReply, disabled }: ChatInputProps) {
const { sendMessage, contacts } = useMessengerContext();
const theme = useTheme() as Theme;
const [content, setContent] = useState("");
@@ -228,6 +229,7 @@ export function ChatInput({ reply, setReply }: ChatInputProps) {
)}
{
e.stopPropagation();
- setShowEmoji(!showEmoji);
+ if (!disabled) {
+ setShowEmoji(!showEmoji);
+ }
}}
>