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

View File

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