Skip to content

Commit

Permalink
Push Chat Flow fixed and recommended chats done
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishek-01k committed Mar 7, 2024
2 parents 385d49b + 324dfc8 commit e598b8f
Show file tree
Hide file tree
Showing 8 changed files with 223 additions and 107 deletions.
8 changes: 6 additions & 2 deletions src/components/Dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ type DropdownProps = {
textColor?: string;
iconFilter?: string;
hoverBGColor?: string;
setShowDropdown?:any;
};


// Create Dropdown
function Dropdown({ dropdownValues, textColor, iconFilter, hoverBGColor }: DropdownProps) {
function Dropdown({ dropdownValues, textColor, iconFilter, hoverBGColor,setShowDropdown }: DropdownProps) {

const theme = useTheme();
const {mode} = useContext(GlobalContext);
Expand All @@ -59,6 +60,7 @@ function Dropdown({ dropdownValues, textColor, iconFilter, hoverBGColor }: Dropd
document.body.removeChild(el);
}
};

return (
<>
{dropdownValues.map((dropdownValue) =>
Expand All @@ -71,7 +73,9 @@ function Dropdown({ dropdownValues, textColor, iconFilter, hoverBGColor }: Dropd
margin="0px 0 8px 0"
width="max-content"
style={{cursor: "pointer"}}
onClick={() => dropdownValue?.function()}
onClick={() => {
dropdownValue?.function()
}}
>
<Span
margin="11px 22px 11px 2px"
Expand Down
6 changes: 5 additions & 1 deletion src/components/ProfileModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,11 @@ const ProfileModal = ({ showDropdown, setShowDropdown, dropdownValues })=>{
size="16px"
cursor="pointer"
width="max-content"
onClick={() => dropdownValue?.function()}
onClick={() => {
setShowDropdown(false);
dropdownValue?.function()

}}
>
{dropdownValue.title}
</Span>
Expand Down
74 changes: 74 additions & 0 deletions src/components/chat/recommended/Recommended.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
// React + Web3 Essentials
import React, { useState } from "react";

// External Packages
import { ChatPreview } from '@pushprotocol/uiweb';
import styled, { css, useTheme } from 'styled-components';

// Internal Compoonents
import { ItemVV2 } from 'components/reusables/SharedStylingV2';

// Internal Configs
import recommendedChatsList from 'config/RecommendedChatsList';

// Interface

// Constants

// Create Module
const Recommended = ({ bg, onChatSelected }) => {
// States
const [chatId, setChatId] = useState('');

const getChatParticipant = (chatParticipant) => {
let chatParticipantAlias;

for (let i = 0; i < recommendedChatsList.length; i++) {
if (recommendedChatsList[i].payload.chatParticipant === chatParticipant) {
chatParticipantAlias = recommendedChatsList[i].chatParticipantAlias;
}
}

return chatParticipantAlias;
}

// RENDER
return (
<Container
bg={bg}
>
{recommendedChatsList.map((item, index) => {
return (
<ChatPreview
key={index}
chatPreviewPayload={item.payload}
selected={item.payload.chatId === chatId ? true : false}
setSelected={(chatId, chatParticipant) => {const chatParticipantRemapped = getChatParticipant(chatParticipant); setChatId(chatId); onChatSelected(chatId, chatParticipantRemapped)}}
/>
)
})}
</Container>
);
}
export default Recommended;

// css styles
const Container = styled(ItemVV2)`
flex: initial;
flex-wrap: nowrap;
background: ${props => props.bg || 'transparent'};
border-radius: 24px;
padding: 10px;
&:before {
content: "RECOMMENDED";
font-size: 12px;
font-weight: 600;
margin-bottom: 10px;
letter-spacing: 0.05em;
color: #657795;
display: flex;
align-self: flex-start;
padding: 5px 10px 0px 10px;
}
`
76 changes: 37 additions & 39 deletions src/components/chat/w2wChat/chatBox/ChatBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,28 @@ import { useLocation, useNavigate } from 'react-router-dom';
import MuiAlert, { AlertProps } from '@mui/material/Alert';
import Snackbar from '@mui/material/Snackbar';
import * as PushAPI from '@pushprotocol/restapi';
import { ChatProfile, ChatViewList, MessageInput, UserProfile } from '@pushprotocol/uiweb';
import 'font-awesome/css/font-awesome.min.css';
import { produce } from 'immer';
import { CID } from 'ipfs-http-client';
import { BsDashLg } from 'react-icons/bs';
import { MdOutlineArrowBackIos } from 'react-icons/md';
import ScrollToBottom from 'react-scroll-to-bottom';
import { useClickAway } from 'react-use';
import styled, { useTheme } from 'styled-components';
import { produce } from 'immer';
import { ChatProfile, ChatViewList, MessageInput, UserProfile } from '@pushprotocol/uiweb';
import { useSelector } from 'react-redux';

// Internal Components
import { ReactComponent as Info } from 'assets/chat/group-chat/info.svg';
import { ReactComponent as InfoDark } from 'assets/chat/group-chat/infodark.svg';
import { ReactComponent as More } from 'assets/chat/group-chat/more.svg';
import { ReactComponent as MoreDark } from 'assets/chat/group-chat/moredark.svg';
import videoCallIcon from 'assets/icons/videoCallIcon.svg';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import { Content } from 'components/SharedStyling';
import Recommended from 'components/chat/recommended/Recommended';
import { ButtonV2, ImageV2, ItemHV2, ItemVV2, SpanV2 } from 'components/reusables/SharedStylingV2';
import LoaderSpinner, { LOADER_TYPE } from 'components/reusables/loaders/LoaderSpinner';
import Tooltip from 'components/reusables/tooltip/Tooltip';
import { Content } from 'components/SharedStyling';
import { checkIfChatExist } from 'helpers/w2w/user';
import { useAccount, useDeviceWidthCheck } from 'hooks';
import { useResolveWeb3Name } from 'hooks/useResolveWeb3Name';
Expand Down Expand Up @@ -59,10 +62,14 @@ const Alert = React.forwardRef<HTMLDivElement, AlertProps>(function Alert(props,
});

const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
const { currentChat, viewChatBox, receivedIntents, activeTab,setViewChatBox, setChat, selectedChatId }: ContextType =
const { currentChat, viewChatBox, receivedIntents, activeTab, setViewChatBox, setChat, selectedChatId }: ContextType =
useContext<ContextType>(Context);
const { web3NameList }: AppContextType = useContext(AppContext);

const { userPushSDKInstance } = useSelector((state: any) => {
return state.user;
});

const { account } = useAccount();
const [Loading, setLoading] = useState<boolean>(true);
const [imageSource, setImageSource] = useState<string>('');
Expand All @@ -86,12 +93,12 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
if (!isGroup && currentChat?.wallets?.split(',')[0].toString()) {
const walletLowercase = currentChat.wallets.includes(':nft')
? caip10ToWallet(
currentChat?.wallets
.replace(/eip155:\d+:/, 'eip155:')
.split(':nft')[0]
.toString()
.toLowerCase()
)
currentChat?.wallets
.replace(/eip155:\d+:/, 'eip155:')
.split(':nft')[0]
.toString()
.toLowerCase()
)
: caip10ToWallet(currentChat?.wallets?.split(',')[0].toString())?.toLowerCase();
const checksumWallet = ethers.utils.getAddress(walletLowercase);
ensName = web3NameList[checksumWallet];
Expand Down Expand Up @@ -128,15 +135,14 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
const getChatId = () => {
let chatId = selectedChatId || currentChat?.did;

console.log("Chat Id in ChatBox >>>>>>>",chatId);

if(chatId){
if (chatId) {
return (chatId?.includes(':nft:')
? chatId.replace(/eip155:\d+:/, 'eip155:').split(':nft')[0]
: chatId) ;
: chatId);
}
return chatId;

};
const handleCloseSuccessSnackbar = (event?: React.SyntheticEvent | Event, reason?: string): void => {
if (reason === 'clickaway') {
Expand All @@ -157,23 +163,12 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
};

const InfoMessages = [
{ id: 1, content: 'You can send up to 10 group requests in alpha' },
// { id: 2, content: 'You can send a chat request to anyone including non-whitelisted users' },
// { id: 3, content: 'You can chat with non-whitelisted users but they cannot send a chat request to anyone.' },
{
id: 4,
content: 'You will have access to 1000 latest messages. Encryption is enabled after a chat request is accepted',
},
{ id: 5, content: 'Messages will only be encrypted if the receiver has encryption keys' },
// {
// id: 6,
// content:
// 'Due to certain limitations Push Chat does not support Ledger Wallet yet. We are working on adding support.',
// },
{ id: 7, content: 'Access to more chat requests and messages will be added in the near future' },
{ id: 1, content: 'Say Hi to your wallet friends!' },
{ id: 2, content: 'Or join groups of your favorite projects and chat with other members.' },
{ id: 3, content: 'Or create your own gated groups based on your requirements' },
{ id: 4, content: 'And experience the future of Web3 communication!' },
];

console.log("viewChatBox >>>>><<<<<<<<<>>>>>>>><<<<<<<",viewChatBox,getChatId());

return (
<Container>
Expand Down Expand Up @@ -218,6 +213,7 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
</Atag>

<ItemBody>
<Recommended bg="#e2078021" onChatSelected={(chatId, chatParticipant) => setChat(chatId, chatParticipant)} />
{InfoMessages.map((item) => (
<WelcomeContent key={item.id}>
<BsDashLg className="icon" />
Expand Down Expand Up @@ -260,15 +256,14 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
fontWeight="500"
zIndex="1"
>

{getChatId() && (
<ChatProfile
chatProfileLeftHelperComponent = {
isMobile?
<SpanV2 onClick={()=>setViewChatBox(false)}>
<MdOutlineArrowBackIos />
</SpanV2>
:null
chatProfileLeftHelperComponent={
isMobile ?
<SpanV2 onClick={() => setViewChatBox(false)}>
<MdOutlineArrowBackIos />
</SpanV2>
: null
}
chatProfileRightHelperComponent={
<Tooltip
Expand Down Expand Up @@ -318,7 +313,7 @@ const ChatBox = ({ showGroupInfoModal }): JSX.Element => {
)}
</>
)}
</Container>
</Container >
);
};

Expand Down Expand Up @@ -414,7 +409,8 @@ const Container = styled(Content)`
`;

const WelcomeItem = styled(ItemVV2)`
width: 369px;
width: 420px;
min-width: 300px;
display: flex;
justify-content: center;
margin: auto auto;
Expand Down Expand Up @@ -442,6 +438,8 @@ const WelcomeContent = styled.div`
`;

const ItemBody = styled.div`
padding: 0px 20px;
@media (min-width: 768px) and (max-height: 1080px) {
overflow-y: scroll;
height: 300px;
Expand Down
46 changes: 46 additions & 0 deletions src/config/RecommendedChatsList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
const RecommendedChatLists = [
{
"chatParticipantAlias": "eip155:0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666",
"payload": {
"chatId": "0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666",
"chatPic": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAAMVJREFUSEtjvOC34D8DFNzaWghjMqh598PZyOJwQTwMXHqRxRlHnsWrmAXhQY0r9PJ4HOFSk77sx6qMGDXIGhlHnsW4EhcxqZdUNUSlalINJUb94LMY2dW4Cg1kV1OiHqUAocQgUh06cBYTk49xBS+uBEVM2U5UATIyLCbVl6QGO86gHr4Wk1pWk1qAIEcBRUXm0Ld4tADBlh9JzVpEFZnIqdrj4CaCjTpSExdyI3CHvR/cfJTaaeRZPNqFwdaZI7U1iSsUAZha8UXyHURfAAAAAElFTkSuQmCC",
"chatParticipant": "Push AI Bot",
"chatGroup": true,
"chatTimestamp": null,
"chatMsg": {
"messageType": "Text",
"messageContent": "Interact for Humor, Sassyness gauranteed!"
}
}
},
{
"chatParticipantAlias": "eip155:0x71Ffa5771E8019787190D098586EFe02026a3c8C",
"payload": {
"chatId": "0x71Ffa5771E8019787190D098586EFe02026a3c8C",
"chatPic": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAB4AAAAeCAYAAAA7MK6iAAAAAXNSR0IArs4c6QAAANNJREFUSEtjTPF78p8BC1gYvw2bMMli8Qu9sOphHNkWX3aqJhiU52StsaoxenyUoF7dfa1wNShBPTIsZl07C2uqRk6NyCkcVyrFpQZX7mAceRbjysfISZSSoMaV1HEWIMPXYuTEhSslI/uemFSNSz1ylKGk6pFhMam1EyVBjRwFJFeLI8NiXL7EVTgQU+AQFdTDy2LzCfHwahG5hYCryCTYzGBgYMAVQsgNDcaRZzGpBQgxQU1M2U5UqibVssFtMXK1iNw2xtV+JtX3uMxEqRZHhMUA5oH9q+BaxVUAAAAASUVORK5CYII=",
"chatParticipant": "Push Developer",
"chatGroup": true,
"chatTimestamp": null,
"chatMsg": {
"messageType": "Text",
"messageContent": "Ask any coding related questions here!"
}
}
},
{
"chatParticipantAlias": "eip155:0x99A08ac6254dcf7ccc37CeC662aeba8eFA666666",
"payload": {
"chatId": "4ac5ab85c9c3d57adbdf2dba79357e56b2f9ef0256befe750d9f93af78d2ca68",
"chatPic": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAAxElEQVR4AcXBsU1DUQyG0S/WW4EGMQETMIRX8BxpXFpCLMACXuGOlC5DhNZKcaUnBP85l8+P7wcntBc7sZIzDDFDzBA7eNJeTLGSKVZyRnsxxUomQ8wQM8SO9uI/tReTIWaIGWJHrGRqL6b2Yrq/fbHzcruyEyuZDDFDzBA7eBIr2Wm/shMrOcMQM8QMsaO9mGIlf6m9mAwxQ8wQO2IlU3vxG+3FTqxkMsQMMUPs8l6vDzZiJVN7sRMrmdqLHUPMEDPEfgBK0S/MKDp40gAAAABJRU5ErkJggg==",
"chatParticipant": "eip155:0xf8250D363BD1F25f52F10C21188fe82c68C049c4",
"chatGroup": true,
"chatTimestamp": null,
"chatMsg": {
"messageType": "Text",
"messageContent": "Hi! Stay tuned, while BRB IRL dev tour has wrapped up, We still have BRB Online with challenges from global projects that still needs to be solved: https://push.org/brb"
}
}
}
]

export default RecommendedChatLists;
5 changes: 1 addition & 4 deletions src/modules/chat/ChatModule.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,6 @@ function Chat({ chatid }) {

let formattedchatId = selectedChatId || chatid;

console.log("Formatted Chat Id: " + formattedchatId);

if (formattedchatId) {
formattedchatId = reformatChatId(formattedchatId);
// navigate(`/chat/${formattedchatId}`);
Expand All @@ -392,14 +390,13 @@ function Chat({ chatid }) {

useEffect(() => { }, [account, connectedUser?.privateKey]);

console.log("userPushSDKInstance in Chat Module <<<>>>><<<>>>",userPushSDKInstance);
return (
<Container>
<ChatUIProvider
theme={theme.scheme === 'dark' && darkChatTheme}
// signer={signerData}
env={appConfig?.appEnv}
account={wallet?.accounts?.length > 0 ? account : readOnlyWallet}
account={account}
pgpPrivateKey={pgpPvtKey}
user={userPushSDKInstance}
>
Expand Down
5 changes: 3 additions & 2 deletions src/primaries/Profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ const Profile = ({ isDarkMode }) => {

// Get theme
const theme = useTheme();
const [showDropdown, setShowDropdown] = React.useState(false);
const [showDropdown, setShowDropdown] = React.useState<boolean>(false);
useClickAway(modalRef, dropdownRef, () => showDropdown && setShowDropdown(false));

const dropdownValues = [
Expand Down Expand Up @@ -77,6 +77,7 @@ const Profile = ({ isDarkMode }) => {
await disconnect(wallet);
setMode(ReadOnlyWalletMode.GUEST_MODE);
setReadOnlyWallet('0x0000000000000000000000000000000000000001');
setShowDropdown(false);
},
title: 'Logout',
invertedIcon: './logout.svg',
Expand Down Expand Up @@ -148,7 +149,7 @@ const Profile = ({ isDarkMode }) => {
align="flex-start"
ref={dropdownRef}
>
<Dropdown dropdownValues={dropdownValues} />
<Dropdown dropdownValues={dropdownValues} setShowDropdown={setShowDropdown}/>
</DropdownItem>
<ItemModal ref={modalRef}>
<ProfileModal
Expand Down
Loading

0 comments on commit e598b8f

Please sign in to comment.