Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/screens/ModelsScreen/ModelCard/ModelCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import {
checkModelFileIntegrity,
} from '../../../utils';
import {SkillsDisplay} from '../../../components';
import { exportModel } from '../../../utils/exportUtils';
import {exportModel} from '../../../utils/exportUtils';

type ChatScreenNavigationProp = DrawerNavigationProp<RootDrawerParamList>;

Expand Down Expand Up @@ -176,7 +176,7 @@ export const ModelCard: React.FC<ModelCardProps> = observer(
});
}
}, [model.hfUrl]);

const ShareModel = async () => {
const fullpath = await modelStore.getModelFullPath(model);
if (fullpath) {
Expand Down Expand Up @@ -331,9 +331,8 @@ export const ModelCard: React.FC<ModelCardProps> = observer(
style={styles.hfButton}
/>
)}
{model.hfUrl && (
{isDownloaded && (
<IconButton
testID="share-huggingface-url"
icon="share"
size={14}
iconColor={theme.colors.onSurfaceVariant}
Expand Down
10 changes: 0 additions & 10 deletions src/screens/ModelsScreen/ModelCard/__tests__/ModelCard.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Share from 'react-native-share';
import React from 'react';
import {Linking, Alert} from 'react-native';

Expand Down Expand Up @@ -151,15 +150,6 @@ describe('ModelCard', () => {
expect(Linking.openURL).toHaveBeenCalledWith(basicModel.hfUrl);
});


it('opens the HuggingFace URL share when the icon button is pressed', () => {
const {getByTestId} = customRender(<ModelCard model={basicModel} />);

const openButton = getByTestId('share-huggingface-url');
fireEvent.press(openButton);
expect(Linking.openURL).toHaveBeenCalledWith(basicModel.hfUrl);
});

it('handles model load correctly', async () => {
const {getByTestId} = customRender(<ModelCard model={downloadedModel} />);

Expand Down
103 changes: 51 additions & 52 deletions src/utils/exportUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,10 @@ export const exportLegacyChatSessions = async (): Promise<void> => {
* @param modelFullPath The fullpath of the model to export
* @param modelFileName The filename of the model to export
*/
export const exportModel = async (modelFullPath: string, modelFileName: string): Promise<void> => {
export const exportModel = async (
modelFullPath: string,
modelFileName: string,
): Promise<void> => {
const currentL10n = uiStore.l10n;
try {
const tempFilePath = modelFullPath;
Expand Down Expand Up @@ -186,8 +189,8 @@ export const exportModel = async (modelFullPath: string, modelFileName: string):
const permissionGranted = await ensureLegacyStoragePermission();
if (!permissionGranted) {
// If permission denied, fall back to direct sharing
console.log('Model FullPath',tempFilePath)
console.log('Model Filename',filename)
console.log('Model FullPath', tempFilePath);
console.log('Model Filename', filename);
try {
await Share.open({
url: `file://${tempFilePath}`,
Expand All @@ -201,61 +204,57 @@ export const exportModel = async (modelFullPath: string, modelFileName: string):
throw error;
}
}
try {
try {
// Save to appropriate directory based on platform
const savePath = modelFullPath;

Alert.alert(
currentL10n.components.exportUtils.share,
filename,
[
{
text: currentL10n.components.exportUtils.share,
onPress: async () => {
// Use react-native-share for both platforms
try {
const options = {
title: `Share ${filename}`,
message: 'PocketPal AI Chat Export',
url: `file://${savePath}`,
type: 'application/octet-stream',
failOnCancel: false,
};

await Share.open(options);
} catch (error) {
const shareError = error as any;
console.error('Error sharing file:', shareError);

// Fallback to sharing content directly if file sharing fails
if (shareError.message !== 'User did not share') {
try {
await Share.open({
title: `Share ${filename}`,
message: filename,
});
} catch (err) {
const fallbackError = err as any;
console.error(
'Error with fallback sharing:',
fallbackError,
Alert.alert(currentL10n.components.exportUtils.share, filename, [
{
text: currentL10n.components.exportUtils.share,
onPress: async () => {
// Use react-native-share for both platforms
try {
const options = {
title: `Share ${filename}`,
message: 'PocketPal AI Chat Export',
url: `file://${savePath}`,
type: 'application/octet-stream',
failOnCancel: false,
};

await Share.open(options);
} catch (error) {
const shareError = error as any;
console.error('Error sharing file:', shareError);

// Fallback to sharing content directly if file sharing fails
if (shareError.message !== 'User did not share') {
try {
await Share.open({
title: `Share ${filename}`,
message: filename,
});
} catch (err) {
const fallbackError = err as any;
console.error(
'Error with fallback sharing:',
fallbackError,
);
// Ignore cancellation errors
if (fallbackError.message !== 'User did not share') {
Alert.alert(
currentL10n.components.exportUtils.shareError,
currentL10n.components.exportUtils.shareErrorMessage,
[{text: currentL10n.components.exportUtils.ok}],
);
// Ignore cancellation errors
if (fallbackError.message !== 'User did not share') {
Alert.alert(
currentL10n.components.exportUtils.shareError,
currentL10n.components.exportUtils.shareErrorMessage,
[{text: currentL10n.components.exportUtils.ok}],
);
}
}
}
}
},
}
},
{text: currentL10n.components.exportUtils.ok},
],
);
},
{text: currentL10n.components.exportUtils.ok},
]);
} catch (error) {
console.error('Error saving to Downloads:', error);

Expand Down Expand Up @@ -292,10 +291,10 @@ export const exportModel = async (modelFullPath: string, modelFileName: string):
],
);
}
}
}
} catch (error) {
console.error('Error exporting model:', error);
// Show a more user-friendly error message
// Show a more user-friendly error message
Alert.alert(
currentL10n.components.exportUtils.exportError,
currentL10n.components.exportUtils.exportErrorMessage,
Expand Down
Loading