diff --git a/packages/react-chat/src/components/Form/ContactMenu.tsx b/packages/react-chat/src/components/Form/ContactMenu.tsx index c5597fd..7378b87 100644 --- a/packages/react-chat/src/components/Form/ContactMenu.tsx +++ b/packages/react-chat/src/components/Form/ContactMenu.tsx @@ -2,11 +2,13 @@ import React, { useMemo } from "react"; import styled from "styled-components"; import { useBlockedUsers } from "../../contexts/blockedUsersProvider"; +import { useFriends } from "../../contexts/friendsProvider"; import { useModal } from "../../contexts/modalProvider"; import { ChatMessage } from "../../models/ChatMessage"; import { Icon } from "../Chat/ChatMessages"; import { AddContactSvg } from "../Icons/AddContactIcon"; import { BlockSvg } from "../Icons/BlockIcon"; +import { ChatSvg } from "../Icons/ChatIcon"; import { EditSvg } from "../Icons/EditIcon"; import { ProfileSvg } from "../Icons/ProfileIcon"; import { UntrustworthIcon } from "../Icons/UntrustworthIcon"; @@ -38,6 +40,10 @@ export function ContactMenu({ [blockedUsers, id] ); + const { friends, setFriends } = useFriends(); + + const userIsFriend = useMemo(() => friends.includes(id), [friends, id]); + const { setModal } = useModal(ProfileModalName); return ( @@ -65,10 +71,18 @@ export function ContactMenu({ View Profile - - - Send Contact Request - + {!userIsFriend && ( + setFriends((prev) => [...prev, id])}> + + Send Contact Request + + )} + {userIsFriend && ( + + + Send Message + + )} Rename @@ -88,7 +102,7 @@ export function ContactMenu({ - {!userInBlocked && ( + {!userIsFriend && ( { userInBlocked diff --git a/packages/react-chat/src/components/Icons/ChatIcon.tsx b/packages/react-chat/src/components/Icons/ChatIcon.tsx new file mode 100644 index 0000000..dbf998a --- /dev/null +++ b/packages/react-chat/src/components/Icons/ChatIcon.tsx @@ -0,0 +1,38 @@ +import React from "react"; +import styled from "styled-components"; + +type ChatSvgProps = { + width: number; + height: number; +}; + +export function ChatSvg({ width, height }: ChatSvgProps) { + return ( + + + + ); +} + +export const ChatIcon = () => { + return ; +}; + +const Icon = styled(ChatSvg)` + & > path { + fill: ${({ theme }) => theme.tertiary}; + } + + &:hover > path { + fill: ${({ theme }) => theme.bodyBackgroundColor}; + } +`; diff --git a/packages/react-chat/src/components/Modals/ProfileModal.tsx b/packages/react-chat/src/components/Modals/ProfileModal.tsx index bc96f0f..962cb59 100644 --- a/packages/react-chat/src/components/Modals/ProfileModal.tsx +++ b/packages/react-chat/src/components/Modals/ProfileModal.tsx @@ -1,6 +1,8 @@ -import React, { useState } from "react"; +import React, { useMemo, useState } from "react"; import styled from "styled-components"; +import { useBlockedUsers } from "../../contexts/blockedUsersProvider"; +import { useFriends } from "../../contexts/friendsProvider"; import { copy } from "../../utils"; import { buttonStyles } from "../Buttons/buttonStyle"; import { CopySvg } from "../Icons/CopyIcon"; @@ -22,6 +24,17 @@ interface ProfileModalProps { export const ProfileModal = ({ user, image }: ProfileModalProps) => { const [isUntrustworthy, setIsUntrustworthy] = useState(false); + const { blockedUsers, setBlockedUsers } = useBlockedUsers(); + + const userInBlocked = useMemo( + () => blockedUsers.includes(user), + [blockedUsers, user] + ); + + const { friends, setFriends } = useFriends(); + + const userIsFriend = useMemo(() => friends.includes(user), [friends, user]); + return (
@@ -57,7 +70,26 @@ export const ProfileModal = ({ user, image }: ProfileModalProps) => { 🎩🍞πŸ₯‘πŸ¦πŸŒˆπŸ“‘πŸ’…πŸ»β™£οΈπŸ””β›ΈπŸ‘΅πŸ…±
- Remove Contact + {!userIsFriend && ( + { + userInBlocked + ? setBlockedUsers((prev) => prev.filter((e) => e != user)) + : setBlockedUsers((prev) => [...prev, user]); + }} + > + {userInBlocked ? "Unblock" : "Block"} + + )} + {userIsFriend && ( + setFriends((prev) => prev.filter((e) => e != user))} + > + Remove Contact + + )} setIsUntrustworthy(!isUntrustworthy)} @@ -66,6 +98,11 @@ export const ProfileModal = ({ user, image }: ProfileModalProps) => { ? "Remove Untrustworthy Mark" : "Mark as Untrustworthy"} + {!userIsFriend && ( + setFriends((prev) => [...prev, user])}> + Send Contact Request + + )}
); @@ -151,6 +188,10 @@ const ProfileBtn = styled.button` color: ${({ theme }) => theme.redColor}; } + &.red:hover { + background: ${({ theme }) => theme.buttonNoBgHover}; + } + &:hover { background: ${({ theme }) => theme.buttonBgHover}; } @@ -161,3 +202,13 @@ const CopyButton = styled.button` fill: ${({ theme }) => theme.tertiary}; } `; + +const Btn = styled.button` + padding: 11px 24px; + margin-left: 8px; + ${buttonStyles} + + &:hover { + background: ${({ theme }) => theme.buttonBgHover}; + } +`; diff --git a/packages/react-chat/src/contexts/friendsProvider.tsx b/packages/react-chat/src/contexts/friendsProvider.tsx new file mode 100644 index 0000000..d94e69d --- /dev/null +++ b/packages/react-chat/src/contexts/friendsProvider.tsx @@ -0,0 +1,27 @@ +import React, { createContext, useContext, useState } from "react"; + +const FriendsContext = createContext<{ + friends: string[]; + setFriends: React.Dispatch>; +}>({ + friends: [], + setFriends: () => undefined, +}); + +export function useFriends() { + return useContext(FriendsContext); +} + +interface FriendsProviderProps { + children: React.ReactNode; +} + +export function FriendsProvider({ children }: FriendsProviderProps) { + const [friends, setFriends] = useState([]); + return ( + + ); +}