Repository navigation
⚙️ feat: Move Chat Actions Into a Header Options Menu #16775
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
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
3246f94
feat: Move Chat Actions Into a Header Options Menu
berry-13 5f02e94
fix: Address Review Findings on the Header Chat Options Menu
berry-13 a2b5331
fix: Scope Header Chat Option Dialogs to the Conversation They Opened…
berry-13 45431d6
fix: Settle Header Delete and Rename Dialogs Against the Open Chat
berry-13 73a7319
fix: Ignore a Late Rename Result After the Dialog Is Gone
berry-13 536ae32
fix: Dismiss Header Chat Options When the Route Leaves Their Chat
berry-13 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| import { useState, useEffect, useRef } from 'react'; | ||
| import { | ||
| Label, | ||
| Input, | ||
| Button, | ||
| Spinner, | ||
| OGDialog, | ||
| OGDialogClose, | ||
| OGDialogTitle, | ||
| OGDialogHeader, | ||
| OGDialogContent, | ||
| useToastContext, | ||
| } from '@librechat/client'; | ||
| import type { FormEvent, RefObject } from 'react'; | ||
| import { useUpdateConversationMutation } from '~/data-provider'; | ||
| import { NotificationSeverity } from '~/common'; | ||
| import { useLocalize } from '~/hooks'; | ||
| import { logger } from '~/utils'; | ||
|
|
||
| const TITLE_MAX_LENGTH = 100; | ||
| const INPUT_ID = 'chat-rename-input'; | ||
|
|
||
| type RenameProps = { | ||
| conversationId: string; | ||
| title: string; | ||
| /** Saving an unchanged title is how a user claims an automatic one, so only an owned title short-circuits. */ | ||
| titleSetByUser: boolean; | ||
| open: boolean; | ||
| onOpenChange: (open: boolean) => void; | ||
| triggerRef?: RefObject<HTMLButtonElement>; | ||
| }; | ||
|
|
||
| function RenameContent({ | ||
| conversationId, | ||
| title, | ||
| titleSetByUser, | ||
| onClose, | ||
| }: Pick<RenameProps, 'conversationId' | 'title' | 'titleSetByUser'> & { onClose: () => void }) { | ||
| const localize = useLocalize(); | ||
| const { showToast } = useToastContext(); | ||
| const [value, setValue] = useState(title); | ||
| const inputRef = useRef<HTMLInputElement>(null); | ||
| const updateMutation = useUpdateConversationMutation(conversationId); | ||
|
|
||
| const mountedRef = useRef(true); | ||
|
|
||
| useEffect(() => { | ||
| mountedRef.current = true; | ||
| inputRef.current?.focus(); | ||
| inputRef.current?.select(); | ||
| return () => { | ||
| mountedRef.current = false; | ||
| }; | ||
| }, []); | ||
|
|
||
| const handleSubmit = async (event: FormEvent) => { | ||
| event.preventDefault(); | ||
| const next = value.trim() || localize('com_ui_untitled'); | ||
| if (next === title && titleSetByUser) { | ||
| onClose(); | ||
| return; | ||
| } | ||
| try { | ||
| await updateMutation.mutateAsync({ conversationId, title: next }); | ||
| /** A rename that settles after the dialog went away has no dialog left to close or focus. */ | ||
| if (mountedRef.current) { | ||
| onClose(); | ||
| } | ||
| } catch (error) { | ||
| logger.error('Error renaming conversation', error); | ||
| showToast({ | ||
| message: localize('com_ui_rename_failed'), | ||
| severity: NotificationSeverity.ERROR, | ||
| showIcon: true, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <OGDialogContent | ||
| id="rename-conversation-dialog" | ||
| className="w-11/12 max-w-md" | ||
| showCloseButton={false} | ||
| > | ||
| <OGDialogHeader> | ||
| <OGDialogTitle>{localize('com_ui_rename_conversation')}</OGDialogTitle> | ||
| </OGDialogHeader> | ||
| <form onSubmit={handleSubmit} className="flex flex-col gap-4"> | ||
| <div className="flex flex-col gap-2"> | ||
| <Label htmlFor={INPUT_ID}>{localize('com_ui_new_conversation_title')}</Label> | ||
| <Input | ||
| id={INPUT_ID} | ||
| ref={inputRef} | ||
| value={value} | ||
| maxLength={TITLE_MAX_LENGTH} | ||
| onChange={(event) => setValue(event.target.value)} | ||
| /> | ||
| </div> | ||
| <div className="flex justify-end gap-4"> | ||
| <OGDialogClose asChild> | ||
| <Button type="button" variant="outline"> | ||
| {localize('com_ui_cancel')} | ||
| </Button> | ||
| </OGDialogClose> | ||
| <Button type="submit" variant="submit" disabled={updateMutation.isLoading}> | ||
| {updateMutation.isLoading ? <Spinner /> : localize('com_ui_save')} | ||
| </Button> | ||
| </div> | ||
| </form> | ||
| </OGDialogContent> | ||
| ); | ||
| } | ||
|
|
||
| /** Rename for the open chat. The sidebar renames inline in its row, which the header has no row for. */ | ||
| export default function Rename({ | ||
| conversationId, | ||
| title, | ||
| titleSetByUser, | ||
| open, | ||
| onOpenChange, | ||
| triggerRef, | ||
| }: RenameProps) { | ||
| /** Closing from a save bypasses the dialog's own handler, which is what returns focus to the | ||
| * menu item that opened it, so the same return is done here. */ | ||
| const close = () => { | ||
| setTimeout(() => triggerRef?.current?.focus(), 0); | ||
|
berry-13 marked this conversation as resolved.
|
||
| onOpenChange(false); | ||
| }; | ||
|
|
||
| return ( | ||
| <OGDialog open={open} onOpenChange={onOpenChange} triggerRef={triggerRef}> | ||
| <RenameContent | ||
| conversationId={conversationId} | ||
| title={title} | ||
| titleSetByUser={titleSetByUser} | ||
| onClose={close} | ||
| /> | ||
| </OGDialog> | ||
| ); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.