From 23d3ee01ea2ed5131d96a0513e9db8923338c5ae Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Fri, 5 Nov 2021 16:31:35 +0100 Subject: [PATCH] Add identity provider (#117) --- packages/react-chat/src/components/Chat.tsx | 10 +--------- .../src/components/Chat/ChatBody.tsx | 5 ----- .../src/components/Chat/ChatCreation.tsx | 5 ++--- .../react-chat/src/components/ChatLoader.tsx | 9 ++++++--- .../src/components/Members/Members.tsx | 9 +-------- .../src/components/Members/MembersList.tsx | 6 +++--- .../components/NarrowMode/NarrowMembers.tsx | 4 ---- .../src/contexts/identityProvider.tsx | 20 +++++++++++++++++++ 8 files changed, 33 insertions(+), 35 deletions(-) create mode 100644 packages/react-chat/src/contexts/identityProvider.tsx diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx index e55cbb01..408ad164 100644 --- a/packages/react-chat/src/components/Chat.tsx +++ b/packages/react-chat/src/components/Chat.tsx @@ -1,5 +1,4 @@ import React, { useMemo, useState } from "react"; -import { Identity } from "status-communities/dist/cjs"; import styled from "styled-components"; import { useMessengerContext } from "../contexts/messengerProvider"; @@ -15,11 +14,7 @@ import { CommunityModal } from "./Modals/CommunityModal"; import { EditModal } from "./Modals/EditModal"; import { CommunitySkeleton } from "./Skeleton/CommunitySkeleton"; -interface ChatProps { - identity: Identity; -} - -export function Chat({ identity }: ChatProps) { +export function Chat() { const [showMembers, setShowMembers] = useState(true); const [showChannels, setShowChannels] = useState(true); const [membersList, setMembersList] = useState([]); @@ -72,7 +67,6 @@ export function Chat({ identity }: ChatProps) { {!createChat && ( setShowMembers(!showMembers)} showMembers={showMembers} community={communityData} @@ -88,14 +82,12 @@ export function Chat({ identity }: ChatProps) { )} {showMembers && !narrow && !createChat && ( )} {createChat && communityData && ( void; showMembers: boolean; @@ -36,7 +34,6 @@ interface ChatBodyProps { } export function ChatBody({ - identity, community, onClick, showMembers, @@ -78,7 +75,6 @@ export function ChatBody({ {editGroup && community ? ( ([]); diff --git a/packages/react-chat/src/components/ChatLoader.tsx b/packages/react-chat/src/components/ChatLoader.tsx index 1a300cbc..f58e44ab 100644 --- a/packages/react-chat/src/components/ChatLoader.tsx +++ b/packages/react-chat/src/components/ChatLoader.tsx @@ -1,6 +1,7 @@ import React, { useState } from "react"; import { Identity } from "status-communities/dist/cjs"; +import { IdentityProvider } from "../contexts/identityProvider"; import { MessengerProvider } from "../contexts/messengerProvider"; import { Chat } from "./Chat"; @@ -15,9 +16,11 @@ export function ChatLoader({ communityKey }: ChatLoaderProps) { if (identity) { return ( - - - + + + + + ); } else { return ; diff --git a/packages/react-chat/src/components/Members/Members.tsx b/packages/react-chat/src/components/Members/Members.tsx index d5a33242..9b9ba134 100644 --- a/packages/react-chat/src/components/Members/Members.tsx +++ b/packages/react-chat/src/components/Members/Members.tsx @@ -1,25 +1,18 @@ import React from "react"; -import { Identity } from "status-communities/dist/cjs"; import styled from "styled-components"; import { MembersList } from "./MembersList"; interface MembersProps { - identity: Identity; setShowChannels: (val: boolean) => void; setMembersList: any; } -export function Members({ - identity, - setShowChannels, - setMembersList, -}: MembersProps) { +export function Members({ setShowChannels, setMembersList }: MembersProps) { return ( Members diff --git a/packages/react-chat/src/components/Members/MembersList.tsx b/packages/react-chat/src/components/Members/MembersList.tsx index 8d9b1625..fba80e35 100644 --- a/packages/react-chat/src/components/Members/MembersList.tsx +++ b/packages/react-chat/src/components/Members/MembersList.tsx @@ -1,27 +1,27 @@ import React from "react"; -import { Identity, utils } from "status-communities/dist/cjs"; +import { utils } from "status-communities/dist/cjs"; import { bufToHex } from "status-communities/dist/cjs/utils"; import styled from "styled-components"; +import { useIdentity } from "../../contexts/identityProvider"; import { useMessengerContext } from "../../contexts/messengerProvider"; import { UserIcon } from "../Icons/UserIcon"; import { Member, MemberData, MemberIcon } from "./Member"; interface MembersListProps { - identity: Identity; setShowChannels: (val: boolean) => void; setShowMembers?: (val: boolean) => void; setMembersList: any; } export function MembersList({ - identity, setShowChannels, setShowMembers, setMembersList, }: MembersListProps) { const { contacts } = useMessengerContext(); + const identity = useIdentity(); return ( diff --git a/packages/react-chat/src/components/NarrowMode/NarrowMembers.tsx b/packages/react-chat/src/components/NarrowMode/NarrowMembers.tsx index d8e77347..23207814 100644 --- a/packages/react-chat/src/components/NarrowMode/NarrowMembers.tsx +++ b/packages/react-chat/src/components/NarrowMode/NarrowMembers.tsx @@ -1,5 +1,4 @@ import React from "react"; -import { Identity } from "status-communities/dist/cjs"; import styled from "styled-components"; import { CommunityData } from "../../models/CommunityData"; @@ -8,7 +7,6 @@ import { MembersList } from "../Members/MembersList"; import { NarrowTopbar } from "./NarrowTopbar"; interface NarrowMembersProps { - identity: Identity; community: CommunityData; setShowChannels: (val: boolean) => void; setShowMembersList: (val: boolean) => void; @@ -16,7 +14,6 @@ interface NarrowMembersProps { } export function NarrowMembers({ - identity, community, setShowChannels, setShowMembersList, @@ -26,7 +23,6 @@ export function NarrowMembers({ ; +}