Skip to content

Commit

Permalink
💭 fix: Message Labels and Typing Issues (#3602)
Browse files Browse the repository at this point in the history
* 💭 fix: message labels due to typing issues

* feat: Fix empty message text in MessageRender component
  • Loading branch information
danny-avila authored Aug 9, 2024
1 parent 1ff4841 commit 22c8b6f
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 10 deletions.
10 changes: 5 additions & 5 deletions client/src/components/Chat/Messages/MessageIcon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Icon from '~/components/Endpoints/Icon';

function MessageIcon(
props: Pick<TMessageProps, 'message' | 'conversation'> & {
assistant?: false | Assistant;
assistant?: Assistant;
},
) {
const { data: endpointsConfig } = useGetEndpointsQuery();
Expand All @@ -21,19 +21,19 @@ function MessageIcon(
() => ({
...(conversation ?? {}),
...({
...message,
...(message ?? {}),
iconURL: message?.iconURL ?? '',
} as TMessage),
}),
[conversation, message],
);

const iconURL = messageSettings?.iconURL;
let endpoint = messageSettings?.endpoint;
const iconURL = messageSettings.iconURL;
let endpoint = messageSettings.endpoint;
endpoint = getIconEndpoint({ endpointsConfig, iconURL, endpoint });
const endpointIconURL = getEndpointField(endpointsConfig, endpoint, 'iconURL');

if (!message?.isCreatedByUser && iconURL && iconURL.includes('http')) {
if (message?.isCreatedByUser !== true && iconURL != null && iconURL.includes('http')) {
return (
<ConvoIconURL
preset={messageSettings as typeof messageSettings & TPreset}
Expand Down
4 changes: 3 additions & 1 deletion client/src/components/Chat/Messages/SearchMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ export default function Message({ message }: Pick<TMessageProps, 'message'>) {

let messageLabel = '';
if (isCreatedByUser) {
messageLabel = UsernameDisplay ? user?.name || user?.username : localize('com_user_message');
messageLabel = UsernameDisplay
? (user?.name ?? '') || user?.username
: localize('com_user_message');
} else {
messageLabel = message.sender;
}
Expand Down
9 changes: 6 additions & 3 deletions client/src/components/Chat/Messages/ui/MessageRender.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,10 @@ const MessageRender = memo(
</div>
</div>
<div
className={cn('relative flex w-11/12 flex-col', msg.isCreatedByUser ? '' : 'agent-turn')}
className={cn(
'relative flex w-11/12 flex-col',
msg.isCreatedByUser === true ? '' : 'agent-turn',
)}
>
<h2 className={cn('select-none font-semibold', fontSize)}>{messageLabel}</h2>
<div className="flex-col gap-1 md:gap-3">
Expand All @@ -124,10 +127,10 @@ const MessageRender = memo(
ask={ask}
edit={edit}
isLast={isLast}
text={msg.text ?? ''}
text={msg.text || ''}
message={msg}
enterEdit={enterEdit}
error={!!error}
error={!!(error ?? false)}
isSubmitting={isSubmitting}
unfinished={unfinished ?? false}
isCreatedByUser={isCreatedByUser ?? true}
Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/Messages/useMessageActions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default function useMessageActions(props: TMessageActions) {

const messageLabel = useMemo(() => {
if (message?.isCreatedByUser === true) {
return UsernameDisplay ? user?.name != null || user?.username : localize('com_user_message');
return UsernameDisplay ? (user?.name ?? '') || user?.username : localize('com_user_message');
} else if (assistant) {
return assistant.name ?? 'Assistant';
} else {
Expand Down

0 comments on commit 22c8b6f

Please sign in to comment.