From faffa272e16d88ae818ca140f92e1223f7b65601 Mon Sep 17 00:00:00 2001 From: Szymon Szlachtowicz <38212223+Szymx95@users.noreply.github.com> Date: Fri, 5 Nov 2021 15:50:40 +0100 Subject: [PATCH] Refactor community data (#115) --- packages/react-chat/src/components/Chat.tsx | 13 ++++--------- .../react-chat/src/components/ChatLoader.tsx | 2 +- packages/react-chat/src/components/Community.tsx | 7 ++----- .../src/components/CommunityIdentity.tsx | 12 ++++++------ .../src/components/Modals/CommunityModal.tsx | 16 +++++----------- packages/react-chat/src/models/CommunityData.ts | 2 +- 6 files changed, 19 insertions(+), 33 deletions(-) diff --git a/packages/react-chat/src/components/Chat.tsx b/packages/react-chat/src/components/Chat.tsx index b05be34f..e55cbb01 100644 --- a/packages/react-chat/src/components/Chat.tsx +++ b/packages/react-chat/src/components/Chat.tsx @@ -16,11 +16,10 @@ import { EditModal } from "./Modals/EditModal"; import { CommunitySkeleton } from "./Skeleton/CommunitySkeleton"; interface ChatProps { - communityKey: string; identity: Identity; } -export function Chat({ communityKey, identity }: ChatProps) { +export function Chat({ identity }: ChatProps) { const [showMembers, setShowMembers] = useState(true); const [showChannels, setShowChannels] = useState(true); const [membersList, setMembersList] = useState([]); @@ -36,11 +35,10 @@ export function Chat({ communityKey, identity }: ChatProps) { const showEditModal = () => setIsEditVisible(true); const { community } = useMessengerContext(); - const communityData = useMemo(() => { if (community?.description) { return { - id: 1, + id: community.publicKeyStr, name: community.description.identity?.displayName ?? "", icon: uintToImgUrl( community.description?.identity?.images?.thumbnail.payload ?? @@ -59,7 +57,7 @@ export function Chat({ communityKey, identity }: ChatProps) { {showChannels && !narrow && ( - {community && communityData ? ( + {communityData ? ( ) : ( @@ -108,11 +106,8 @@ export function Chat({ communityKey, identity }: ChatProps) { setIsModalVisible(false)} - icon={communityData.icon} - name={communityData.name} + community={communityData} subtitle="Public Community" - description={communityData.description} - publicKey={communityKey} /> )} - + ); } else { diff --git a/packages/react-chat/src/components/Community.tsx b/packages/react-chat/src/components/Community.tsx index 22aef94e..b4f9a26d 100644 --- a/packages/react-chat/src/components/Community.tsx +++ b/packages/react-chat/src/components/Community.tsx @@ -11,15 +11,12 @@ interface CommunityProps { } export function Community({ community, onClick, className }: CommunityProps) { - const { name, icon, members } = community; - return ( <> diff --git a/packages/react-chat/src/components/CommunityIdentity.tsx b/packages/react-chat/src/components/CommunityIdentity.tsx index d23a786d..066dcdea 100644 --- a/packages/react-chat/src/components/CommunityIdentity.tsx +++ b/packages/react-chat/src/components/CommunityIdentity.tsx @@ -1,26 +1,26 @@ import React from "react"; import styled from "styled-components"; +import { CommunityData } from "../models/CommunityData"; + import { textMediumStyles } from "./Text"; export interface CommunityIdentityProps { - icon: string; - name: string; + community: CommunityData; subtitle: string; className?: string; } export const CommunityIdentity = ({ - icon, - name, + community, subtitle, className, }: CommunityIdentityProps) => { return ( - + - {name} + {community.name} {subtitle} diff --git a/packages/react-chat/src/components/Modals/CommunityModal.tsx b/packages/react-chat/src/components/Modals/CommunityModal.tsx index 9bf1fec0..66ae46b2 100644 --- a/packages/react-chat/src/components/Modals/CommunityModal.tsx +++ b/packages/react-chat/src/components/Modals/CommunityModal.tsx @@ -14,32 +14,26 @@ import { textSmallStyles } from "../Text"; import { BasicModalProps, Modal } from "./Modal"; import { Section, Text } from "./ModalStyle"; -interface CommunityModalProps extends BasicModalProps, CommunityIdentityProps { - description: string; - publicKey: string; -} +interface CommunityModalProps extends BasicModalProps, CommunityIdentityProps {} export const CommunityModal = ({ isVisible, onClose, - icon, - name, + community, subtitle, - description, - publicKey, }: CommunityModalProps) => { const narrow = useNarrow(); return (
- +
- {description} + {community.description}
- + To access this community, paste community public key in Status desktop or mobile app. diff --git a/packages/react-chat/src/models/CommunityData.ts b/packages/react-chat/src/models/CommunityData.ts index a26fe4cf..6ebefd83 100644 --- a/packages/react-chat/src/models/CommunityData.ts +++ b/packages/react-chat/src/models/CommunityData.ts @@ -1,5 +1,5 @@ export type CommunityData = { - id: number; + id: string; name: string; icon: string; members: number;