Skip to content

Commit f133bb9

Browse files
🖌️ feat: Optional Display Username in Messages, Send/Stop Button Style, Localization (danny-avila#1592)
* 👤add: Username instead of 'You' when sending messages. * 🌎: Added a new translation for 'You' and updated the existing translation for Spanish. * fix: remove "!" * Added: New setting Account for show username in messages chore (StopButon and SendButon): Updated to new style of ChatGPT chore Update and Added news translations: Spanish, English and Portuguese Brazilian * fix: message component definition and imports order, remove unnecessary useEffect and localStorage set, fix localStorage key in store * chore: update readme.md * chore: optimize condition for messageLabel * chore(Message.tsx): remove empty blocks --------- Co-authored-by: Raí Santos <140329135+itzraiss@users.noreply.github.com>
1 parent 3df5853 commit f133bb9

File tree

8 files changed

+223
-115
lines changed

8 files changed

+223
-115
lines changed

README.md

+4
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,10 @@ Please consult the breaking changes before updating.
8585

8686
## ⭐ Star History
8787

88+
<p align="center">
89+
<a href="https://trendshift.io/repositories/4685" target="_blank"><img src="https://trendshift.io/api/badge/repositories/4685" alt="danny-avila%2FLibreChat | Trendshift" style="width: 250px; height: 55px;" width="250" height="55"/></a>
90+
</p>
91+
8892
<a href="https://star-history.com/#danny-avila/LibreChat&Date">
8993
<img alt="Star History Chart" src="https://api.star-history.com/svg?repos=danny-avila/LibreChat&type=Date&theme=dark" onerror="this.src='https://api.star-history.com/svg?repos=danny-avila/LibreChat&type=Date'" />
9094
</a>

client/src/components/Chat/Input/SendButton.tsx

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@ export default function SendButton({ text, disabled }) {
66
<button
77
disabled={!text || disabled}
88
className={cn(
9-
'absolute rounded-lg rounded-md border border-black p-0.5 p-1 text-white transition-colors enabled:bg-black enabled:dark:bg-white disabled:bg-black disabled:text-gray-400 disabled:opacity-10 dark:border-white dark:bg-white dark:disabled:bg-white ',
10-
'bottom-1.5 right-1.5 md:bottom-2.5 md:right-3 md:p-[2px]',
9+
'absolute bottom-1.5 right-2 rounded-lg border border-black p-0.5 text-white transition-colors enabled:bg-black disabled:bg-black disabled:text-gray-400 disabled:opacity-10 dark:border-white dark:bg-white dark:hover:bg-gray-900 dark:disabled:bg-white dark:disabled:hover:bg-transparent md:bottom-3 md:right-3',
1110
)}
1211
data-testid="send-button"
1312
type="submit"

client/src/components/Chat/Messages/Message.tsx

+19-8
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1+
import { useRecoilValue } from 'recoil';
2+
import { useAuthContext, useMessageHelpers, useLocalize } from '~/hooks';
3+
import type { TMessageProps } from '~/common';
14
import { Plugin } from '~/components/Messages/Content';
25
import MessageContent from './Content/MessageContent';
3-
import type { TMessageProps } from '~/common';
46
import SiblingSwitch from './SiblingSwitch';
5-
import { useMessageHelpers } from '~/hooks';
67
// eslint-disable-next-line import/no-cycle
78
import MultiMessage from './MultiMessage';
89
import HoverButtons from './HoverButtons';
910
import SubRow from './SubRow';
1011
import { cn } from '~/utils';
12+
import store from '~/store';
1113

1214
export default function Message(props: TMessageProps) {
13-
const { message, siblingIdx, siblingCount, setSiblingIdx, currentEditId, setCurrentEditId } =
14-
props;
15+
const UsernameDisplay = useRecoilValue<boolean>(store.UsernameDisplay);
16+
const { user } = useAuthContext();
17+
const localize = useLocalize();
1518

1619
const {
1720
ask,
@@ -28,12 +31,22 @@ export default function Message(props: TMessageProps) {
2831
regenerateMessage,
2932
} = useMessageHelpers(props);
3033

31-
const { text, children, messageId = null, isCreatedByUser, error, unfinished } = message ?? {};
34+
const { message, siblingIdx, siblingCount, setSiblingIdx, currentEditId, setCurrentEditId } =
35+
props;
3236

3337
if (!message) {
3438
return null;
3539
}
3640

41+
const { text, children, messageId = null, isCreatedByUser, error, unfinished } = message ?? {};
42+
43+
let messageLabel = '';
44+
if (isCreatedByUser) {
45+
messageLabel = UsernameDisplay ? user?.name : localize('com_user_message');
46+
} else {
47+
messageLabel = message.sender;
48+
}
49+
3750
return (
3851
<>
3952
<div
@@ -59,9 +72,7 @@ export default function Message(props: TMessageProps) {
5972
<div
6073
className={cn('relative flex w-full flex-col', isCreatedByUser ? '' : 'agent-turn')}
6174
>
62-
<div className="select-none font-semibold">
63-
{isCreatedByUser ? 'You' : message.sender}
64-
</div>
75+
<div className="select-none font-semibold">{messageLabel}</div>
6576
<div className="flex-col gap-1 md:gap-3">
6677
<div className="flex max-w-full flex-grow flex-col gap-0">
6778
{/* Legacy Plugins */}

client/src/components/Nav/SettingsTabs/Account/Account.tsx

+25-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,23 @@
11
import React from 'react';
2+
import { useRecoilState } from 'recoil';
23
import * as Tabs from '@radix-ui/react-tabs';
34
import { SettingsTabValues } from 'librechat-data-provider';
5+
import { Switch } from '~/components/ui';
6+
import { useLocalize } from '~/hooks';
47
import Avatar from './Avatar';
8+
import store from '~/store';
9+
10+
function Account({ onCheckedChange }: { onCheckedChange?: (value: boolean) => void }) {
11+
const [UsernameDisplay, setUsernameDisplay] = useRecoilState<boolean>(store.UsernameDisplay);
12+
const localize = useLocalize();
13+
14+
const handleCheckedChange = (value: boolean) => {
15+
setUsernameDisplay(value);
16+
if (onCheckedChange) {
17+
onCheckedChange(value);
18+
}
19+
};
520

6-
function Account() {
721
return (
822
<Tabs.Content
923
value={SettingsTabValues.ACCOUNT}
@@ -14,6 +28,16 @@ function Account() {
1428
<div className="border-b pb-3 last-of-type:border-b-0 dark:border-gray-700">
1529
<Avatar />
1630
</div>
31+
<div className="flex items-center justify-between">
32+
<div> {localize('com_nav_user_name_display')} </div>
33+
<Switch
34+
id="UsernameDisplay"
35+
checked={UsernameDisplay}
36+
onCheckedChange={handleCheckedChange}
37+
className="ml-4 mt-2"
38+
data-testid="UsernameDisplay"
39+
/>
40+
</div>
1741
</div>
1842
<div className="border-b pb-3 last-of-type:border-b-0 dark:border-gray-700"></div>
1943
</Tabs.Content>

client/src/localization/languages/Br.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ export default {
4040
com_ui_cancel: 'Cancelar',
4141
com_ui_save: 'Salvar',
4242
com_ui_save_submit: 'Salvar e Enviar',
43+
com_user_message: 'Você',
4344
com_ui_copy_to_clipboard: 'Copiar para a área de transferência',
4445
com_ui_copied_to_clipboard: 'Copiado para a área de transferência',
4546
com_ui_regenerate: 'Regenerar',
@@ -292,6 +293,7 @@ export default {
292293
com_nav_theme_system: 'Sistema',
293294
com_nav_theme_dark: 'Escuro',
294295
com_nav_theme_light: 'Claro',
296+
com_nav_user_name_display: 'Mostrar nome de usuário nas mensagens',
295297
com_nav_clear_all_chats: 'Limpar todos os chats',
296298
com_nav_confirm_clear: 'Confirmar Limpeza',
297299
com_nav_close_sidebar: 'Fechar barra lateral',

client/src/localization/languages/Eng.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ export default {
3939
com_ui_cancel: 'Cancel',
4040
com_ui_save: 'Save',
4141
com_ui_save_submit: 'Save & Submit',
42+
com_user_message: 'You',
4243
com_ui_copy_to_clipboard: 'Copy to clipboard',
4344
com_ui_copied_to_clipboard: 'Copied to clipboard',
4445
com_ui_regenerate: 'Regenerate',
@@ -291,6 +292,7 @@ export default {
291292
com_nav_theme_system: 'System',
292293
com_nav_theme_dark: 'Dark',
293294
com_nav_theme_light: 'Light',
295+
com_nav_user_name_display: 'Display username in messages',
294296
com_nav_clear_all_chats: 'Clear all chats',
295297
com_nav_confirm_clear: 'Confirm Clear',
296298
com_nav_close_sidebar: 'Close sidebar',

0 commit comments

Comments
 (0)