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

Feat/post message on parent for message #176

Merged
merged 6 commits into from
Nov 27, 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
5 changes: 5 additions & 0 deletions .changeset/angry-donkeys-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openassistantgpt/ui': patch
---

Add feature to remove all icons from chat
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ export default function ChatPage() {
displayFooterText: true,
footerLink: 'https://www.openassistantgpt.io',
footerTextName: 'OpenAssistantGPT',

messageSourceText: '',
withChatMessageIcon: true,
};

return (
Expand Down
1 change: 1 addition & 0 deletions examples/next-website/app/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export default function ChatPage() {
fontSize: '14px',

messageSourceText: '',
withChatMessageIcon: true,
};

useEffect(() => {
Expand Down
1 change: 1 addition & 0 deletions examples/website-chatbot-window/app/window/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function ChatPage() {
footerTextName: 'OpenAssistantGPT',

messageSourceText: 'Chatbot source:',
withChatMessageIcon: false,
};

return (
Expand Down
1 change: 1 addition & 0 deletions examples/website-custom-api/app/window/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ export default function ChatPage() {
fontSize: '15px',

messageSourceText: '',
withChatMessageIcon: true,
};

return (
Expand Down
66 changes: 37 additions & 29 deletions packages/ui/components/chat-message.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
isFirst?: boolean;
fontSize: string; // Keep as string for pixel values
references: Reference[];
withChatMessageIcon: boolean;
}

const getDirection = (isRTL: boolean) => (isRTL ? 'rtl' : 'ltr');
Expand All @@ -44,6 +45,7 @@
attachments,
references,
fontSize = '16px', // Default font size in pixels
withChatMessageIcon = true,
...props
}: ChatMessageProps) {
return (
Expand All @@ -59,52 +61,58 @@
background: chatbot.userReplyBackgroundColor,
fontSize, // Apply font size in pixels here
}}
className="p-2 rounded-lg mr-4 whitespace-pre-wrap"
className="p-2 rounded-lg mr-3 whitespace-pre-wrap"
dir={getDirection(chatbot.rightToLeftLanguage)} // Set text direction
>
<svg
fill={chatbot.userReplyBackgroundColor}
className="absolute bottom-[0px] right-11"
className={`absolute bottom-[0px] ${
chatbot.withChatMessageIcon ? 'right-14' : 'right-2'
}`}
height="14"
width="13"
>
<path d="M6 .246c-.175 5.992-1.539 8.89-5.5 13.5 6.117.073 9.128-.306 12.5-3L6 .246Z"></path>
</svg>
{message.content}
</p>
<div
className={cn(
'flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow',
'bg-background',
)}
>
<Icons.user />
</div>
</div>
) : (
<div
className={cn('pr-10 group relative mb-4 flex items-start ')}
{...props}
>
{chatbot.chatbotLogoURL ? (
<div className="size-8" style={{ width: '30px', height: '30px' }}>
<img
src={chatbot.chatbotLogoURL}
alt="chatbot logo"
width={50}
height={50}
/>
</div>
) : (

{withChatMessageIcon && (
<div
className={cn(
'flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow',
'bg-primary text-primary-foreground',
'flex size-8 shrink-0 mr-4 select-none items-center justify-center rounded-md border shadow',
'bg-background',
)}
>
<Icons.bot />
<Icons.user />
</div>
)}
</div>
) : (
<div
className={cn('pr-10 group relative mb-4 flex items-start ')}
{...props}
>
{withChatMessageIcon &&
(chatbot.chatbotLogoURL ? (
<div className="size-8" style={{ width: '30px', height: '30px' }}>
<img

Check warning on line 99 in packages/ui/components/chat-message.tsx

View workflow job for this annotation

GitHub Actions / ESLint

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
src={chatbot.chatbotLogoURL}
alt="chatbot logo"
width={50}
height={50}
/>
</div>
) : (
<div
className={cn(
'flex size-8 shrink-0 select-none items-center justify-center rounded-md border shadow',
'bg-primary text-primary-foreground',
)}
>
<Icons.bot />
</div>
))}
<div className="flex-1 px-1 ml-4">
{message.content == 'loading' ? (
<Icons.loading className="animate-spin" />
Expand Down
5 changes: 4 additions & 1 deletion packages/ui/components/chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,19 +111,19 @@
variant: 'destructive',
});
}
}, [error]);

Check warning on line 114 in packages/ui/components/chat.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'toast'. Either include it or remove the dependency array

useEffect(() => {
if (onThreadIdChange) {
onThreadIdChange(threadId);
}
}, [threadId]);

Check warning on line 120 in packages/ui/components/chat.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'onThreadIdChange'. Either include it or remove the dependency array. If 'onThreadIdChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
if (onMessagesChange) {
onMessagesChange(messages);
}
}, [messages]);

Check warning on line 126 in packages/ui/components/chat.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'onMessagesChange'. Either include it or remove the dependency array. If 'onMessagesChange' changes too often, find the parent component that defines it and wrap that definition in useCallback

useEffect(() => {
if (defaultMessage !== '') {
Expand All @@ -132,7 +132,7 @@
target: { value: defaultMessage },
} as React.ChangeEvent<HTMLInputElement>);
}
}, [defaultMessage]);

Check warning on line 135 in packages/ui/components/chat.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has missing dependencies: 'handleInputChange' and 'input'. Either include them or remove the dependency array

function closeChat() {
window.parent.postMessage('closeChat', '*');
Expand Down Expand Up @@ -224,7 +224,7 @@
setUploadQueue([]);
}
},
[setAttachments],

Check warning on line 227 in packages/ui/components/chat.tsx

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useCallback has a missing dependency: 'uploadFile'. Either include it or remove the dependency array
);

return (
Expand All @@ -249,13 +249,14 @@
<div
ref={messagesContainerRef}
className={cn(
'pb-[200px] overflow-auto max-h-max pl-6 sm:pl-20 pr-6 sm:pr-20 md:pb-[100px] pt-4 md:pt-10',
'pb-[200px] overflow-auto max-h-max pl-6 sm:pl-20 sm:pr-20 md:pb-[100px] pt-4 md:pt-10',
className,
)}
>
<ChatMessage
isFirst={true}
chatbot={chatbot}
withChatMessageIcon={chatbot.withChatMessageIcon}
message={{
id: '0',
role: 'assistant',
Expand All @@ -276,6 +277,7 @@
key={index}
message={message}
fontSize={chatbot.fontSize}
withChatMessageIcon={chatbot.withChatMessageIcon}
references={
annotationsArray
.map(a => {
Expand Down Expand Up @@ -306,6 +308,7 @@
<div className="mt-4" id="waiting">
<ChatMessage
chatbot={chatbot}
withChatMessageIcon={chatbot.withChatMessageIcon}
message={{
id: 'waiting',
role: 'assistant',
Expand Down
2 changes: 2 additions & 0 deletions packages/ui/src/chatbot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,6 @@ export type ChatbotConfig = {
footerLink: string;

messageSourceText: string;

withChatMessageIcon: boolean;
};
Loading