Refactor community data (#115)

This commit is contained in:
Szymon Szlachtowicz 2021-11-05 15:50:40 +01:00 committed by GitHub
parent ee91965c32
commit faffa272e1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 19 additions and 33 deletions

View File

@ -16,11 +16,10 @@ import { EditModal } from "./Modals/EditModal";
import { CommunitySkeleton } from "./Skeleton/CommunitySkeleton"; import { CommunitySkeleton } from "./Skeleton/CommunitySkeleton";
interface ChatProps { interface ChatProps {
communityKey: string;
identity: Identity; identity: Identity;
} }
export function Chat({ communityKey, identity }: ChatProps) { export function Chat({ identity }: ChatProps) {
const [showMembers, setShowMembers] = useState(true); const [showMembers, setShowMembers] = useState(true);
const [showChannels, setShowChannels] = useState(true); const [showChannels, setShowChannels] = useState(true);
const [membersList, setMembersList] = useState([]); const [membersList, setMembersList] = useState([]);
@ -36,11 +35,10 @@ export function Chat({ communityKey, identity }: ChatProps) {
const showEditModal = () => setIsEditVisible(true); const showEditModal = () => setIsEditVisible(true);
const { community } = useMessengerContext(); const { community } = useMessengerContext();
const communityData = useMemo(() => { const communityData = useMemo(() => {
if (community?.description) { if (community?.description) {
return { return {
id: 1, id: community.publicKeyStr,
name: community.description.identity?.displayName ?? "", name: community.description.identity?.displayName ?? "",
icon: uintToImgUrl( icon: uintToImgUrl(
community.description?.identity?.images?.thumbnail.payload ?? community.description?.identity?.images?.thumbnail.payload ??
@ -59,7 +57,7 @@ export function Chat({ communityKey, identity }: ChatProps) {
<ChatWrapper> <ChatWrapper>
{showChannels && !narrow && ( {showChannels && !narrow && (
<ChannelsWrapper> <ChannelsWrapper>
{community && communityData ? ( {communityData ? (
<StyledCommunity onClick={showModal} community={communityData} /> <StyledCommunity onClick={showModal} community={communityData} />
) : ( ) : (
<CommunitySkeleton /> <CommunitySkeleton />
@ -108,11 +106,8 @@ export function Chat({ communityKey, identity }: ChatProps) {
<CommunityModal <CommunityModal
isVisible={isModalVisible} isVisible={isModalVisible}
onClose={() => setIsModalVisible(false)} onClose={() => setIsModalVisible(false)}
icon={communityData.icon} community={communityData}
name={communityData.name}
subtitle="Public Community" subtitle="Public Community"
description={communityData.description}
publicKey={communityKey}
/> />
)} )}
<EditModal <EditModal

View File

@ -16,7 +16,7 @@ export function ChatLoader({ communityKey }: ChatLoaderProps) {
if (identity) { if (identity) {
return ( return (
<MessengerProvider identity={identity} communityKey={communityKey}> <MessengerProvider identity={identity} communityKey={communityKey}>
<Chat communityKey={communityKey} identity={identity} /> <Chat identity={identity} />
</MessengerProvider> </MessengerProvider>
); );
} else { } else {

View File

@ -11,15 +11,12 @@ interface CommunityProps {
} }
export function Community({ community, onClick, className }: CommunityProps) { export function Community({ community, onClick, className }: CommunityProps) {
const { name, icon, members } = community;
return ( return (
<> <>
<button className={className} onClick={onClick}> <button className={className} onClick={onClick}>
<CommunityIdentity <CommunityIdentity
name={name} community={community}
icon={icon} subtitle={`${community.members} members`}
subtitle={`${members} members`}
/> />
</button> </button>
</> </>

View File

@ -1,26 +1,26 @@
import React from "react"; import React from "react";
import styled from "styled-components"; import styled from "styled-components";
import { CommunityData } from "../models/CommunityData";
import { textMediumStyles } from "./Text"; import { textMediumStyles } from "./Text";
export interface CommunityIdentityProps { export interface CommunityIdentityProps {
icon: string; community: CommunityData;
name: string;
subtitle: string; subtitle: string;
className?: string; className?: string;
} }
export const CommunityIdentity = ({ export const CommunityIdentity = ({
icon, community,
name,
subtitle, subtitle,
className, className,
}: CommunityIdentityProps) => { }: CommunityIdentityProps) => {
return ( return (
<Row className={className}> <Row className={className}>
<Logo src={icon} alt={`${name} logo`} /> <Logo src={community.icon} alt={`${name} logo`} />
<Column> <Column>
<Name>{name}</Name> <Name>{community.name}</Name>
<Subtitle>{subtitle}</Subtitle> <Subtitle>{subtitle}</Subtitle>
</Column> </Column>
</Row> </Row>

View File

@ -14,32 +14,26 @@ import { textSmallStyles } from "../Text";
import { BasicModalProps, Modal } from "./Modal"; import { BasicModalProps, Modal } from "./Modal";
import { Section, Text } from "./ModalStyle"; import { Section, Text } from "./ModalStyle";
interface CommunityModalProps extends BasicModalProps, CommunityIdentityProps { interface CommunityModalProps extends BasicModalProps, CommunityIdentityProps {}
description: string;
publicKey: string;
}
export const CommunityModal = ({ export const CommunityModal = ({
isVisible, isVisible,
onClose, onClose,
icon, community,
name,
subtitle, subtitle,
description,
publicKey,
}: CommunityModalProps) => { }: CommunityModalProps) => {
const narrow = useNarrow(); const narrow = useNarrow();
return ( return (
<Modal isVisible={isVisible} onClose={onClose}> <Modal isVisible={isVisible} onClose={onClose}>
<Section> <Section>
<CommunityIdentity icon={icon} name={name} subtitle={subtitle} /> <CommunityIdentity community={community} subtitle={subtitle} />
</Section> </Section>
<Section> <Section>
<Text>{description}</Text> <Text>{community.description}</Text>
</Section> </Section>
<Section> <Section>
<CopyInput value={publicKey} label="Community public key" /> <CopyInput value={community.id} label="Community public key" />
<Hint> <Hint>
To access this community, paste community public key in Status desktop To access this community, paste community public key in Status desktop
or mobile app. or mobile app.

View File

@ -1,5 +1,5 @@
export type CommunityData = { export type CommunityData = {
id: number; id: string;
name: string; name: string;
icon: string; icon: string;
members: number; members: number;