Group img preview (#196)

* Add group img preview

* Cut group default name

* Clear modal form
This commit is contained in:
Maria Rushkova 2022-01-20 02:17:02 +01:00 committed by GitHub
parent f5dd23ce97
commit 27b81243fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 6 deletions

View File

@ -22,6 +22,8 @@ export const EditModalName = "editModal";
export const EditModal = () => {
const { activeChannel, changeGroupChatName } = useMessengerContext();
const { setModal } = useModal(EditModalName);
const [groupName, setGroupName] = useState("");
const [image, setImage] = useState("");
@ -31,12 +33,16 @@ export const EditModal = () => {
}
};
const { setModal } = useModal(EditModalName);
const handleUpload = () => {
if (activeChannel) {
activeChannel.icon = image;
changeGroupChatName(groupName, activeChannel.id);
if (image) {
activeChannel.icon = image; // Need function to send image to waku
setImage("");
}
if (groupName) {
changeGroupChatName(groupName, activeChannel.id);
setGroupName("");
}
setModal(false);
}
};
@ -64,10 +70,11 @@ export const EditModal = () => {
</NameSection>
<LogoSection>
<Label>Group image</Label>
<GroupLogo icon={image || activeChannel?.icon}>
<GroupLogo icon={activeChannel?.icon}>
{!activeChannel?.icon &&
!image &&
activeChannel?.name?.slice(0, 1)?.toUpperCase()}
{image && <LogoPreview src={image} />}
<AddPictureInputWrapper>
<AddIcon />
<AddPictureInput
@ -128,6 +135,12 @@ const GroupLogo = styled(ChannelLogo)`
margin-right: 0;
`;
const LogoPreview = styled.img`
width: 128px;
height: 128px;
border-radius: 50%;
`;
const AddPictureInputWrapper = styled(AddWrapper)`
top: 0;
right: 8px;

View File

@ -38,7 +38,7 @@ export function useGroupChats(
.map(contactFromId);
const channel: ChannelData = {
id: chat.chatId,
name: chat.name ?? chat.chatId,
name: chat.name ?? chat.chatId.slice(0, 10),
type: "group",
description: `${chat.members.length} members`,
members: members,