Skip to content

Commit 10672f6

Browse files
committed
fix: fixed the issues
moved the funcs to helpers and also removed the commented code
1 parent 45d647f commit 10672f6

File tree

6 files changed

+44
-59
lines changed

6 files changed

+44
-59
lines changed

packages/uiweb/src/lib/components/chat/ChatViewBubbleCore/ChatViewBubbleCore.tsx

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import styled from 'styled-components';
88
import { useChatData } from '../../../hooks';
99
import { ThemeContext } from '../theme/ThemeProvider';
1010

11-
import { isMessageEncrypted, pCAIP10ToWallet } from '../../../helpers';
11+
import { deepCopy, isMessageEncrypted, pCAIP10ToWallet } from '../../../helpers';
1212
import { IMessagePayload, TwitterFeedReturnType } from '../exportedTypes';
1313

1414
import { Section } from '../../reusables';
@@ -25,34 +25,6 @@ interface ChatViewBubbleCoreProps extends React.ComponentProps<typeof Section> {
2525
previewMode?: boolean;
2626
}
2727

28-
// Main Logic
29-
// Deep Copy Helper Function
30-
function deepCopy<T>(obj: T): T {
31-
if (obj === null || typeof obj !== 'object') {
32-
return obj;
33-
}
34-
35-
if (obj instanceof Date) {
36-
return new Date(obj.getTime()) as any;
37-
}
38-
39-
if (obj instanceof Array) {
40-
return obj.reduce((arr, item, i) => {
41-
arr[i] = deepCopy(item);
42-
return arr;
43-
}, [] as any[]) as any;
44-
}
45-
46-
if (obj instanceof Object) {
47-
return Object.keys(obj).reduce((newObj, key) => {
48-
newObj[key as keyof T] = deepCopy((obj as any)[key]);
49-
return newObj;
50-
}, {} as T);
51-
}
52-
53-
throw new Error(`Unable to copy obj! Its type isn't supported.`);
54-
}
55-
5628
// Exported Default Component
5729
export const ChatViewBubbleCore = ({
5830
chat,

packages/uiweb/src/lib/components/chat/ChatViewBubbleCore/cards/image/ImageCard.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Image, Section, Span } from '../../../../reusables';
88
import { ThemeContext } from '../../../theme/ThemeProvider';
99
import { Tag } from '../../tag/Tag';
1010

11+
// Helper functions
12+
import { getParsedMessage } from '../../../helpers';
13+
1114
// Internal Configs
1215

1316
// Assets
@@ -19,15 +22,6 @@ import { IMessagePayload } from '../../../exportedTypes';
1922

2023
// Exported Interfaces & Types
2124

22-
// Exported Functions
23-
const getParsedMessage = (message: string) => {
24-
try {
25-
return JSON.parse(message);
26-
} catch (error) {
27-
console.error('UIWeb::components::ChatViewBubble::ImageCard::error while parsing image', error);
28-
return null;
29-
}
30-
};
3125

3226
const getImageContent = (message: string) => getParsedMessage(message)?.content ?? '';
3327

packages/uiweb/src/lib/components/chat/ChatViewBubbleCore/cards/message/MessageCard.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ export const MessageCard = ({
211211
<MessageCardSection
212212
className={initialized.additionalClasses}
213213
justifyContent="stretch"
214-
width={'fill-available'}
214+
width="fill-available"
215215
>
216216
{/* Preview Renderer - Start with assuming preview is there, callback handles no preview */}
217217
<MessagePreviewSection

packages/uiweb/src/lib/components/chat/ChatViewList/ChatViewList.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,15 +216,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
216216
scrollLocked = true;
217217
}
218218

219-
// Turning it off as it overfills debug
220-
// console.debug(
221-
// `UIWeb::ChatViewList::onScroll::scrollLocked ${new Date().toISOString()}`,
222-
// scrollRef.current.scrollTop,
223-
// scrollRef.current.clientHeight,
224-
// scrollRef.current.scrollHeight,
225-
// scrollLocked
226-
// );
227-
228219
// update scroll-locked attribute
229220
scrollRef.current.setAttribute('data-scroll-locked', scrollLocked.toString());
230221

@@ -248,15 +239,6 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
248239
if (scrollRef.current && height !== 0) {
249240
const scrollLocked = scrollRef.current.getAttribute('data-scroll-locked') === 'true' ? true : false;
250241

251-
// Turning it off as it overfills debug
252-
// console.debug(
253-
// `UIWeb::ChatViewList::onScroll::scrollLocked Observer ${new Date().toISOString()}`,
254-
// scrollRef.current.scrollTop,
255-
// scrollRef.current.clientHeight,
256-
// scrollRef.current.scrollHeight,
257-
// scrollLocked
258-
// );
259-
260242
if (height !== 0 && scrollLocked) {
261243
// update programmable-scroll attribute
262244
scrollRef.current.setAttribute('data-programmable-scroll', 'true');
@@ -589,7 +571,7 @@ export const ChatViewList: React.FC<IChatViewListProps> = (options: IChatViewLis
589571
};
590572

591573
//styles
592-
const ChatViewListCard = styled(Section)<IThemeProps>`
574+
const ChatViewListCard = styled(Section) <IThemeProps>`
593575
&::-webkit-scrollbar-thumb {
594576
background: ${(props) => props.theme.scrollbarColor};
595577
border-radius: 10px;
@@ -602,6 +584,6 @@ const ChatViewListCard = styled(Section)<IThemeProps>`
602584
overscroll-behavior: contain;
603585
`;
604586

605-
const ChatViewListCardInner = styled(Section)<IThemeProps>`
587+
const ChatViewListCardInner = styled(Section) <IThemeProps>`
606588
filter: ${(props) => (props.blur ? 'blur(12px)' : 'none')};
607589
`;

packages/uiweb/src/lib/components/chat/helpers/helper.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,15 @@ export const transformStreamToIMessageIPFSWithCID: (item: any) => IMessageIPFSWi
268268
return transformedItem;
269269
};
270270

271+
export const getParsedMessage = (message: string) => {
272+
try {
273+
return JSON.parse(message);
274+
} catch (error) {
275+
console.error('UIWeb::components::ChatViewBubble::ImageCard::error while parsing image', error);
276+
return null;
277+
}
278+
};
279+
271280
export const getChatParticipantDisplayName = (derivedChatId: string, chatId: string) => {
272281
return derivedChatId ? getDomainIfExists(chatId) ?? derivedChatId : derivedChatId;
273282
};

packages/uiweb/src/lib/helpers/utils.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,34 @@ export const deriveChatId = async (chatId: string, user: PushAPI | undefined): P
3535
return chatId;
3636
};
3737

38+
// Main Logic
39+
// Deep Copy Helper Function
40+
export function deepCopy<T>(obj: T): T {
41+
if (obj === null || typeof obj !== 'object') {
42+
return obj;
43+
}
44+
45+
if (obj instanceof Date) {
46+
return new Date(obj.getTime()) as any;
47+
}
48+
49+
if (obj instanceof Array) {
50+
return obj.reduce((arr, item, i) => {
51+
arr[i] = deepCopy(item);
52+
return arr;
53+
}, [] as any[]) as any;
54+
}
55+
56+
if (obj instanceof Object) {
57+
return Object.keys(obj).reduce((newObj, key) => {
58+
newObj[key as keyof T] = deepCopy((obj as any)[key]);
59+
return newObj;
60+
}, {} as T);
61+
}
62+
63+
throw new Error(`Unable to copy obj! Its type isn't supported.`);
64+
}
65+
3866
export const isMessageEncrypted = (message: string) => {
3967
if (!message) return false;
4068

0 commit comments

Comments
 (0)