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
28 changes: 28 additions & 0 deletions packages/mobile/app/providers/file-import-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { ActivityIndicator, Text, TouchableOpacity } from "react-native";
import { colors } from "../../theme";
import { styles } from "./styles.ts";

export function FileImportButton({
disabled,
loading,
onPress,
}: {
disabled: boolean;
loading: boolean;
onPress: () => void;
}) {
return (
<TouchableOpacity
style={[styles.syncButton, disabled && styles.syncButtonDisabled]}
onPress={onPress}
activeOpacity={0.7}
disabled={disabled}
>
{loading ? (
<ActivityIndicator color={colors.text} size="small" />
) : (
<Text style={styles.syncButtonText}>Import file</Text>
)}
</TouchableOpacity>
);
}
44 changes: 44 additions & 0 deletions packages/mobile/app/providers/file-import-provider-card.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import type { ProviderStats } from "@dofek/providers/provider-stats";
import type { ImportProviderId } from "../../lib/share-import";
import { getFileImportProviderConfig } from "./file-import-providers.ts";
import { type Provider, ProviderCard } from "./provider-card.tsx";

export function FileImportProviderCard({
provider,
stats,
syncing,
importing,
syncProgress,
onSync,
onFullSync,
onConnect,
onImportProvider,
onPress,
}: {
provider: Provider;
stats: ProviderStats | undefined;
syncing: boolean;
importing?: boolean;
syncProgress: { percentage?: number; message?: string } | undefined;
onSync: () => void;
onFullSync: () => void;
onConnect: () => void;
onImportProvider: (providerId: ImportProviderId) => void;
onPress: () => void;
}) {
const providerConfig = getFileImportProviderConfig(provider.id);
return (
<ProviderCard
provider={provider}
stats={stats}
syncing={syncing}
importing={importing}
syncProgress={syncProgress}
onSync={onSync}
onFullSync={onFullSync}
onConnect={onConnect}
onImport={providerConfig ? () => onImportProvider(providerConfig.providerId) : undefined}
onPress={onPress}
/>
);
}
64 changes: 64 additions & 0 deletions packages/mobile/app/providers/file-import-providers.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import type { ImportProviderId } from "../../lib/share-import";

type FileImportProviderConfig = {
providerId: ImportProviderId;
documentTypes: string[];
selectionErrorMessage: string;
};

const csvDocumentTypes = [
"text/csv",
"text/comma-separated-values",
"application/csv",
"text/plain",
];

const fileImportProviderConfigs = {
"apple-health": {
providerId: "apple-health",
documentTypes: [
"application/zip",
"application/x-zip-compressed",
"application/xml",
"text/xml",
],
selectionErrorMessage: "Unable to select Apple Health export",
},
"strong-csv": {
providerId: "strong-csv",
documentTypes: csvDocumentTypes,
selectionErrorMessage: "Unable to select Strong export",
},
"cronometer-csv": {
providerId: "cronometer-csv",
documentTypes: csvDocumentTypes,
selectionErrorMessage: "Unable to select Cronometer export",
},
"garmin-dump": {
providerId: "garmin-dump",
documentTypes: ["application/zip", "application/x-zip-compressed"],
selectionErrorMessage: "Unable to select Garmin export",
},
"kaya-export": {
providerId: "kaya-export",
documentTypes: csvDocumentTypes,
selectionErrorMessage: "Unable to select Kaya export",
},
} satisfies Partial<Record<ImportProviderId, FileImportProviderConfig>>;

export function getFileImportProviderConfig(
providerId: string,
): FileImportProviderConfig | undefined {
switch (providerId) {
case "apple-health":
case "apple_health":
return fileImportProviderConfigs["apple-health"];
case "strong-csv":
case "cronometer-csv":
case "garmin-dump":
case "kaya-export":
return fileImportProviderConfigs[providerId];
default:
return undefined;
}
}
16 changes: 16 additions & 0 deletions packages/mobile/app/providers/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,22 @@ export const ImportOnly: ProviderCardStory = {
},
};

export const GarminDumpImport: ProviderCardStory = {
args: {
provider: {
id: "garmin-dump",
label: "Garmin Dump",
enabled: false,
authStatus: "connected",
authType: "none",
lastSyncAt: null,
importOnly: true,
pushOnly: false,
},
onImport: () => {},
},
};

export const AppleHealthImportOnly: ProviderCardStory = {
args: {
provider: {
Expand Down
Loading
Loading