Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: added prefillChatList #1122

Merged
merged 2 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

104 changes: 58 additions & 46 deletions packages/uiweb/src/lib/components/chat/ChatPreview/ChatPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import { formatAddress, formatDate } from '../helpers';
import { resolveNewEns, shortenText } from '../../../helpers';
import { CoreContractChainId, InfuraAPIKey } from '../../../config';
import { ethers } from 'ethers';
import { FaFile } from "react-icons/fa";
import { CiImageOn } from "react-icons/ci";
import { FaFile } from 'react-icons/fa';
import { CiImageOn } from 'react-icons/ci';
/**
* @interface IThemeProps
* this interface is used for defining the props for styled components
Expand All @@ -27,34 +27,37 @@ export const ChatPreview: React.FC<IChatPreviewProps> = (
options: IChatPreviewProps
) => {
const theme = useContext(ThemeContext);
const {env} = useChatData();
const provider = new ethers.providers.InfuraProvider(CoreContractChainId[env], InfuraAPIKey);
const [formattedAddress,setFormattedAddress] = useState<string>('');
const { env } = useChatData();
const provider = new ethers.providers.InfuraProvider(
CoreContractChainId[env],
InfuraAPIKey
);
const [formattedAddress, setFormattedAddress] = useState<string>('');
const [web3Name, setWeb3Name] = useState<string | null>(null);

useEffect(()=>{
(async()=>{
const address = await formatAddress(options.chatPreviewPayload,env);
setFormattedAddress(address);
if(!options.chatPreviewPayload?.chatGroup){
const result = await resolveNewEns(address, provider,env);
setWeb3Name(result);
}
useEffect(() => {
(async () => {
const address = await formatAddress(options.chatPreviewPayload, env);
setFormattedAddress(address);
if (!options.chatPreviewPayload?.chatGroup) {
try {
const result = await resolveNewEns(address, provider, env);
if (result) setWeb3Name(result);
} catch (e) {
// console.debug(e);
}
}
})();
}, []);


},[])

const getProfileName = (formattedAddress:string) => {
const getProfileName = (formattedAddress: string) => {
return options.chatPreviewPayload?.chatGroup
? formattedAddress
: web3Name
? web3Name
: formattedAddress

: formattedAddress;
};


return (
<ChatPreviewContainer>
<Button
Expand All @@ -76,7 +79,10 @@ export const ChatPreview: React.FC<IChatPreviewProps> = (
onClick={() => {
// set chatid as selected
if (options?.setSelected)
options.setSelected(options?.chatPreviewPayload?.chatId || '',options?.chatPreviewPayload?.chatParticipant);
options.setSelected(
options?.chatPreviewPayload?.chatId || '',
options?.chatPreviewPayload?.chatParticipant
);
}}
>
<Section
Expand Down Expand Up @@ -112,8 +118,13 @@ export const ChatPreview: React.FC<IChatPreviewProps> = (
overflow="hidden"
flex="1"
>
<Account theme={theme}>{ shortenText(getProfileName(formattedAddress),8,true) || shortenText(formattedAddress,8,true)}</Account>
<Dated theme={theme}>{formatDate(options.chatPreviewPayload)}</Dated>
<Account theme={theme}>
{shortenText(getProfileName(formattedAddress), 8, true) ||
shortenText(formattedAddress, 8, true)}
</Account>
<Dated theme={theme}>
{formatDate(options.chatPreviewPayload)}
</Dated>
</Section>
<Section
justifyContent="flex-start"
Expand All @@ -124,23 +135,24 @@ export const ChatPreview: React.FC<IChatPreviewProps> = (
flex="1"
>
<Message theme={theme}>
{
(options?.chatPreviewPayload?.chatMsg?.messageType === "Image" || options?.chatPreviewPayload?.chatMsg?.messageType === "GIF" || options?.chatPreviewPayload?.chatMsg?.messageType === "MediaEmbed" )
?
(
{options?.chatPreviewPayload?.chatMsg?.messageType === 'Image' ||
options?.chatPreviewPayload?.chatMsg?.messageType === 'GIF' ||
options?.chatPreviewPayload?.chatMsg?.messageType ===
'MediaEmbed' ? (
<Section
justifyContent="flex-start"
flexDirection="row"
alignItems="center"
alignSelf="stretch"
overflow="hidden"
flex="1"
gap="4px"
justifyContent="flex-start"
flexDirection="row"
alignItems="center"
alignSelf="stretch"
overflow="hidden"
flex="1"
gap="4px"
>
<CiImageOn />
Media
</Section>
) : (options?.chatPreviewPayload?.chatMsg?.messageType === "File" ?
) : options?.chatPreviewPayload?.chatMsg?.messageType ===
'File' ? (
<Section
justifyContent="flex-start"
flexDirection="row"
Expand All @@ -149,16 +161,17 @@ export const ChatPreview: React.FC<IChatPreviewProps> = (
overflow="hidden"
flex="1"
gap="4px"
>
<FaFile/>
File
>
<FaFile />
File
</Section>

: options?.chatPreviewPayload?.chatMsg?.messageContent )

}
) : (
options?.chatPreviewPayload?.chatMsg?.messageContent
)}
</Message>
{!!options?.badge?.count && <Badge theme={theme}>{options.badge.count}</Badge>}
{!!options?.badge?.count && (
<Badge theme={theme}>{options.badge.count}</Badge>
)}
</Section>
</Section>
</Button>
Expand Down Expand Up @@ -197,7 +210,6 @@ const Account = styled.div<IThemeProps>`
white-space: nowrap;
overflow: hidden;
margin-right: 10px;

`;

const Dated = styled.div<IThemeProps>`
Expand All @@ -221,13 +233,13 @@ const Message = styled.div<IThemeProps>`
`;

const Badge = styled.div<IThemeProps>`
background: ${(props) => props.theme.backgroundColor?.chatPreviewBadgeBackground};
background: ${(props) =>
props.theme.backgroundColor?.chatPreviewBadgeBackground};
font-weight: ${(props) => props.theme.fontWeight?.chatPreviewBadgeText};
font-size: ${(props) => props.theme.fontSize?.chatPreviewBadgeText};
color: ${(props) => props.theme.textColor?.chatPreviewBadgeText};
padding: 0px 8px;
min-height: 24px;
border-radius: 24px;
align-self: center;

`;
Loading
Loading