Skip to content

Commit

Permalink
Fix focusing of imported chats. #233
Browse files Browse the repository at this point in the history
  • Loading branch information
enricoros committed Nov 27, 2023
1 parent 57f277f commit 0a593fb
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/apps/chat/AppChat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ export function AppChat() {
{!!flattenConversationId && <FlattenerModal conversationId={flattenConversationId} onClose={() => setFlattenConversationId(null)} />}

{/* Import / Export */}
{!!tradeConfig && <TradeModal config={tradeConfig} onClose={() => setTradeConfig(null)} />}
{!!tradeConfig && <TradeModal config={tradeConfig} onConversationActivate={setFocusedConversationId} onClose={() => setTradeConfig(null)} />}


{/* [confirmation] Reset Conversation */}
Expand Down
9 changes: 6 additions & 3 deletions src/modules/trade/ImportChats.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const chatGptMedia: FormRadioOption<'source' | 'link'>[] = [
* Components and functionality to import conversations
* Supports our own JSON files, and ChatGPT Share Links
*/
export function ImportConversations(props: { onClose: () => void }) {
export function ImportConversations(props: { onConversationActivate: (conversationId: DConversationId) => void, onClose: () => void }) {

// state
const [importMedia, importMediaControl] = useFormRadio('link', chatGptMedia);
Expand Down Expand Up @@ -71,8 +71,10 @@ export function ImportConversations(props: { onClose: () => void }) {

// import conversations (warning - will overwrite things)
for (const conversation of [...outcome.conversations].reverse()) {
if (conversation.success)
useChatStore.getState().importConversation(conversation.conversation, false);
if (conversation.success) {
const conversationId: DConversationId = useChatStore.getState().importConversation(conversation.conversation, false);
props.onConversationActivate(conversationId);
}
}

// show the outcome of the import
Expand Down Expand Up @@ -128,6 +130,7 @@ export function ImportConversations(props: { onClose: () => void }) {
const success = conversation.messages.length >= 1;
if (success) {
useChatStore.getState().importConversation(conversation, false);
props.onConversationActivate(conversationId);
outcome.conversations.push({ success: true, fileName: 'chatgpt', conversation });
} else
outcome.conversations.push({ success: false, fileName: 'chatgpt', error: `Empty conversation` });
Expand Down
5 changes: 3 additions & 2 deletions src/modules/trade/TradeModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,19 @@ import * as React from 'react';

import { Divider } from '@mui/joy';

import { DConversationId } from '~/common/state/store-chats';
import { GoodModal } from '~/common/components/GoodModal';

import { ExportChats, ExportConfig } from './ExportChats';
import { ImportConfig, ImportConversations } from './ImportChats';

export type TradeConfig = ImportConfig | ExportConfig;

export function TradeModal(props: { config: TradeConfig, onClose: () => void }) {
export function TradeModal(props: { config: TradeConfig, onConversationActivate: (conversationId: DConversationId) => void, onClose: () => void }) {
return (
<GoodModal title={<><b>{props.config.dir === 'import' ? 'Import ' : props.config.dir === 'export' ? 'Export ' : ''}</b> conversations</>} open onClose={props.onClose}>
<Divider />
{props.config.dir === 'import' && <ImportConversations onClose={props.onClose} />}
{props.config.dir === 'import' && <ImportConversations onConversationActivate={props.onConversationActivate} onClose={props.onClose} />}
{props.config.dir === 'export' && <ExportChats config={props.config} onClose={props.onClose} />}
<Divider />
</GoodModal>
Expand Down

1 comment on commit 0a593fb

@vercel
Copy link

@vercel vercel bot commented on 0a593fb Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

big-agi – ./

big-agi-git-main-enricoros.vercel.app
big-agi-enricoros.vercel.app
get.big-agi.com

Please sign in to comment.