Skip to content

Commit ea1a808

Browse files
author
tfomkin
committed
feat: export archived chat
1 parent f0d927a commit ea1a808

23 files changed

Lines changed: 254 additions & 55 deletions

File tree

libs/mobile/chat/features/archived-chat-item/src/lib/component.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ import { BottomSheetModal } from '@gorhom/bottom-sheet';
22
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
33
import { compact } from 'lodash-es';
44
import { Fragment, ReactElement, useRef } from 'react';
5+
import { DownloadChatOptionsSheet } from '@open-webui-react-native/mobile/shared/features/download-chat-options-sheet';
56
import { ChatListRow, ChatListRowProps } from '@open-webui-react-native/mobile/shared/ui/chat-list-row';
67
import { ActionsBottomSheet, ActionSheetItemProps } from '@open-webui-react-native/mobile/shared/ui/ui-kit';
78
import { chatApi, ChatListItem } from '@open-webui-react-native/shared/data-access/api';
89
import { withOfflineGuard } from '@open-webui-react-native/shared/features/network';
910
import { alertService } from '@open-webui-react-native/shared/utils/alert-service';
1011
import { FeatureID, isFeatureEnabled } from '@open-webui-react-native/shared/utils/feature-flag';
11-
import { ToastService } from '@open-webui-react-native/shared/utils/toast-service';
1212

1313
interface ArchivedChatItemProps extends Partial<ChatListRowProps> {
1414
onItemPress: (id: string) => void;
@@ -19,6 +19,7 @@ export function ArchivedChatItem({ item, onItemPress, ...restProps }: ArchivedCh
1919
const translate = useTranslation('CHAT.ARCHIVED_CHATS_LIST.CHAT_ITEM');
2020

2121
const actionsSheetRef = useRef<BottomSheetModal>(null);
22+
const downloadOptionsModalRef = useRef<BottomSheetModal>(null);
2223

2324
const { mutateAsync: deleteChat, isPending: isDeleting } = chatApi.useDelete();
2425
const { mutateAsync: unarchiveChat, isPending: isUnarchiving } = chatApi.useUnarchiveChat();
@@ -46,7 +47,8 @@ export function ArchivedChatItem({ item, onItemPress, ...restProps }: ArchivedCh
4647
await unarchiveChat(item.id);
4748
actionsSheetRef.current?.close();
4849
};
49-
const handleExportChatPress = (): void => ToastService.showFeatureNotImplemented();
50+
51+
const handleExportChatPress = (): void => downloadOptionsModalRef.current?.present();
5052

5153
const actions: Array<ActionSheetItemProps> = compact([
5254
{
@@ -80,6 +82,7 @@ export function ArchivedChatItem({ item, onItemPress, ...restProps }: ArchivedCh
8082
{...restProps}
8183
/>
8284
<ActionsBottomSheet actions={actions} ref={actionsSheetRef} />
85+
<DownloadChatOptionsSheet ref={downloadOptionsModalRef} chatId={item.id} />
8386
</Fragment>
8487
);
8588
}

libs/mobile/chat/features/archived-chats-list/src/lib/components/archived-chats-actions-sheet/component.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface ArchivedChatsActionsSheetProps {
1919
export function ArchivedChatsActionsSheet({ renderTrigger }: ArchivedChatsActionsSheetProps): ReactElement {
2020
const translate = useTranslation('CHAT.ARCHIVED_CHATS_LIST.ARCHIVED_CHATS_ACTIONS_SHEET');
2121

22-
const actionsHSeetRef = useRef<BottomSheetModal>(null);
22+
const actionsSheetRef = useRef<BottomSheetModal>(null);
2323

2424
const { unarchiveAllChats, isUnarchiving: isUnarchivingAllChats } = useUnarchiveChats();
2525

@@ -35,12 +35,12 @@ export function ArchivedChatsActionsSheet({ renderTrigger }: ArchivedChatsAction
3535

3636
const handleConfirmUnarchiveAll = async (): Promise<void> => {
3737
await unarchiveAllChats();
38-
actionsHSeetRef.current?.close();
38+
actionsSheetRef.current?.close();
3939
};
4040

4141
const handleExportArchivedChats = async (): Promise<void> => {
4242
await exportArchivedChats();
43-
actionsHSeetRef.current?.close();
43+
actionsSheetRef.current?.close();
4444
};
4545

4646
const actions: Array<ActionSheetItemProps> = compact([
@@ -61,5 +61,5 @@ export function ArchivedChatsActionsSheet({ renderTrigger }: ArchivedChatsAction
6161
return <ActionsBottomSheet
6262
actions={actions}
6363
renderTrigger={renderTrigger}
64-
ref={actionsHSeetRef} />;
64+
ref={actionsSheetRef} />;
6565
}

libs/mobile/shared/features/chat-actions-menu-sheet/src/lib/component.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import {
1111
UpsertFolderSheet,
1212
UpsertFolderSheetMethods,
1313
} from '@open-webui-react-native/mobile/folder/features/upsert-folder-sheet';
14+
import { DownloadChatOptionsSheet } from '@open-webui-react-native/mobile/shared/features/download-chat-options-sheet';
1415
import {
1516
ActionButtonsModal,
1617
ActionButtonsModalMethods,
@@ -31,7 +32,6 @@ import {
3132
import { withOfflineGuard } from '@open-webui-react-native/shared/features/network';
3233
import { alertService } from '@open-webui-react-native/shared/utils/alert-service';
3334
import { FeatureID, isFeatureEnabled } from '@open-webui-react-native/shared/utils/feature-flag';
34-
import { DownloadChatOptionsSheet } from './components';
3535
import { ChatAction } from './enums';
3636

3737
export type ChatActionsMenuSheetMethods = {

libs/mobile/shared/features/chat-actions-menu-sheet/src/lib/components/index.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"presets": [
3+
[
4+
"@nx/react/babel",
5+
{
6+
"runtime": "automatic",
7+
"useBuiltIns": "usage"
8+
}
9+
]
10+
],
11+
"plugins": []
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# mobile/shared/features/download-chat-options-sheet
2+
3+
This library was generated with [Nx](https://nx.dev).
4+
5+
## Running unit tests
6+
7+
Run `nx test mobile/shared/features/download-chat-options-sheet` to execute the unit tests via [Jest](https://jestjs.io).
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const nx = require('@nx/eslint-plugin');
2+
const baseConfig = require('../../../../../eslint.config.cjs');
3+
4+
module.exports = [
5+
...baseConfig,
6+
...nx.configs['flat/react'],
7+
{
8+
files: ['**/*.ts', '**/*.tsx', '**/*.js', '**/*.jsx'],
9+
// Override or add rules here
10+
rules: {},
11+
},
12+
];
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"name": "mobile/shared/features/download-chat-options-sheet",
3+
"$schema": "../../../../../node_modules/nx/schemas/project-schema.json",
4+
"sourceRoot": "libs/mobile/shared/features/download-chat-options-sheet/src",
5+
"projectType": "library",
6+
"tags": ["app:mobile", "scope:shared", "type:features"],
7+
"// targets": "to see all targets run: nx show project mobile/shared/features/download-chat-options-sheet --web",
8+
"targets": {}
9+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export * from './lib';

libs/mobile/shared/features/chat-actions-menu-sheet/src/lib/components/download-chat-options-sheet/component.tsx renamed to libs/mobile/shared/features/download-chat-options-sheet/src/lib/component.tsx

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,9 @@
11
import { BottomSheetModal } from '@gorhom/bottom-sheet';
22
import { useTranslation } from '@ronas-it/react-native-common-modules/i18n';
33
import { ReactElement, useState } from 'react';
4-
import {
5-
FileExtension,
6-
fileSystemService,
7-
} from '@open-webui-react-native/mobile/shared/data-access/file-system-service';
4+
import { FileExtension } from '@open-webui-react-native/mobile/shared/data-access/file-system-service';
5+
import { createChatDownloadHandlers } from '@open-webui-react-native/mobile/shared/features/download-chat';
86
import { ActionsBottomSheet, ActionSheetItemProps } from '@open-webui-react-native/mobile/shared/ui/ui-kit';
9-
import { chatQueriesKeys, ChatResponse } from '@open-webui-react-native/shared/data-access/api';
10-
import { queryClient } from '@open-webui-react-native/shared/data-access/query-client';
11-
import { getChatAsText } from '@open-webui-react-native/shared/features/get-chat-as-text';
127

138
export interface DownloadChatOptionsSheetProps {
149
chatId: string;
@@ -22,37 +17,23 @@ export function DownloadChatOptionsSheet({ chatId, ref }: DownloadChatOptionsShe
2217
FileExtension.JSON | FileExtension.TXT | FileExtension.PDF | null
2318
>(null);
2419

25-
const getChat = async (): Promise<ChatResponse> =>
26-
await queryClient.fetchQuery<ChatResponse>({ queryKey: chatQueriesKeys.get(chatId).queryKey });
27-
28-
const onDownloadText = async (): Promise<void> => {
29-
setFileTypeLoading(FileExtension.TXT);
30-
const { chat } = await getChat();
31-
const text = getChatAsText(chat);
32-
await fileSystemService.shareTextFile(`chat-${chat.title}`, text);
33-
setFileTypeLoading(null);
34-
};
35-
36-
const onDownloadJson = async (): Promise<void> => {
37-
setFileTypeLoading(FileExtension.JSON);
38-
const { chat } = await getChat();
39-
const jsonData = JSON.stringify([chat], null, 2);
40-
await fileSystemService.shareJsonFile(`chat-export-${Date.now()}`, jsonData);
41-
setFileTypeLoading(null);
42-
};
20+
const { downloadJson, downloadText } = createChatDownloadHandlers({
21+
chatId,
22+
setFileTypeLoading,
23+
});
4324

4425
const actions: Array<ActionSheetItemProps> = [
4526
{
4627
title: translate('TEXT_EXPORT_CHAT_JSON'),
4728
iconName: 'jsonFile',
48-
onPress: onDownloadJson,
29+
onPress: downloadJson,
4930
disabled: !!fileTypeLoading,
5031
isLoading: fileTypeLoading === FileExtension.JSON,
5132
},
5233
{
5334
title: translate('TEXT_PLAIN_TEXT'),
5435
iconName: 'txtFile',
55-
onPress: onDownloadText,
36+
onPress: downloadText,
5637
disabled: !!fileTypeLoading,
5738
isLoading: fileTypeLoading === FileExtension.TXT,
5839
},

0 commit comments

Comments
 (0)