Skip to content

armgit / papra

Public Imported from GitHub
0

The minimalistic document archiving platform.

feat(mobile): scan a document (#688)

Jibran Iqbalabc2a2a800d3
diff --git a/apps/mobile/package.json b/apps/mobile/package.json
index 49f7abbb..5981e737 100644
--- a/apps/mobile/package.json
+++ b/apps/mobile/package.json
@@ -36,6 +36,7 @@
"expo-image": "~3.0.10",
"expo-linking": "~8.0.8",
"expo-network": "^8.0.8",
+ "expo-print": "^15.0.7",
"expo-router": "~6.0.14",
"expo-secure-store": "^15.0.7",
"expo-sharing": "^14.0.7",
@@ -48,6 +49,7 @@
"react": "19.1.0",
"react-dom": "19.1.0",
"react-native": "0.81.5",
+ "react-native-document-scanner-plugin": "^2.0.2",
"react-native-gesture-handler": "~2.28.0",
"react-native-pdf": "^7.0.3",
"react-native-reanimated": "~4.1.1",
diff --git a/apps/mobile/src/modules/documents/components/import-drawer.tsx b/apps/mobile/src/modules/documents/components/import-drawer.tsx
index 2b832c47..460d0b90 100644
--- a/apps/mobile/src/modules/documents/components/import-drawer.tsx
+++ b/apps/mobile/src/modules/documents/components/import-drawer.tsx
@@ -1,6 +1,8 @@
import type { LocalDocument } from '@/modules/api/api.models';
import type { ThemeColors } from '@/modules/ui/theme.constants';
import * as DocumentPicker from 'expo-document-picker';
+import * as FileSystem from 'expo-file-system/legacy';
+import { useState } from 'react';
import {
Modal,
StyleSheet,
@@ -8,13 +10,18 @@ import {
TouchableOpacity,
View,
} from 'react-native';
+import DocumentScanner from 'react-native-document-scanner-plugin';
import { useApiClient } from '@/modules/api/providers/api.provider';
import { queryClient } from '@/modules/api/providers/query.provider';
import { useOrganizations } from '@/modules/organizations/organizations.provider';
import { Icon } from '@/modules/ui/components/icon';
import { useAlert } from '@/modules/ui/providers/alert-provider';
import { useThemeColor } from '@/modules/ui/providers/use-theme-color';
+import { convertImagesToPdf } from '../documents-scan.services';
+import { documentsLocalStorage } from '../documents.local-storage';
import { uploadDocument } from '../documents.services';
+import { syncUnsyncedDocuments } from '../documents.sync.services';
+import { RenameDocumentDialog } from './rename-document-dialog';
type ImportDrawerProps = {
visible: boolean;
@@ -27,6 +34,9 @@ export function ImportDrawer({ visible, onClose }: ImportDrawerProps) {
const styles = createStyles({ themeColors });
const apiClient = useApiClient();
const { currentOrganizationId } = useOrganizations();
+ const [renameModalVisible, setRenameModalVisible] = useState(false);
+ const [scannedImageUris, setScannedImageUris] = useState<string[]>([]);
+ const [defaultDocumentName, setDefaultDocumentName] = useState('');
const handleImportFromFiles = async () => {
onClose();
@@ -84,74 +94,179 @@ export function ImportDrawer({ visible, onClose }: ImportDrawerProps) {
}
};
- // const handleScanDocument = () => {
- // onClose();
- // showAlert({
- // title: 'Coming Soon',
- // message: 'Camera document scanning will be available soon!',
- // });
- // };
+ const processScannedImages = async (imageUris: string[], fileName: string) => {
+ try {
+ if (currentOrganizationId == null) {
+ showAlert({
+ title: 'No Organization Selected',
+ message: 'Please select an organization before importing documents.',
+ });
+ return;
+ }
+
+ const timestamp = Date.now();
+ const finalFileName = fileName.endsWith('.pdf') ? fileName : `${fileName}.pdf`;
+
+ const pdfUri = await convertImagesToPdf(imageUris);
+
+ // Copy PDF to permanent location
+ const permanentUri = `${FileSystem.documentDirectory}${timestamp}_${finalFileName}`;
+ await FileSystem.copyAsync({
+ from: pdfUri,
+ to: permanentUri,
+ });
+
+ // Get file size
+ const fileInfo = await FileSystem.getInfoAsync(permanentUri);
+ const fileSize = fileInfo.exists && 'size' in fileInfo ? fileInfo.size : 0;
+
+ // Save as unsynced document
+ const unsyncedDoc = {
+ id: `local_${timestamp}_${Math.random().toString(36).substring(7)}`,
+ name: finalFileName,
+ mimeType: 'application/pdf',
+ localUri: permanentUri,
+ organizationId: currentOrganizationId,
+ createdAt: new Date().toISOString(),
+ updatedAt: new Date().toISOString(),
+ tags: [],
+ originalSize: fileSize,
+ };
+
+ await documentsLocalStorage.addUnsyncedDocument(unsyncedDoc);
+
+ try {
+ await FileSystem.deleteAsync(pdfUri, { idempotent: true });
+ } catch (error) {
+ console.error('Error cleaning up temporary PDF:', error);
+ }
+
+ await queryClient.invalidateQueries({ queryKey: ['organizations', currentOrganizationId, 'documents'] });
+ // Trigger background sync
+ void syncUnsyncedDocuments({ organizationId: currentOrganizationId, apiClient });
+ } catch (error) {
+ console.error('Error processing scanned image:', error);
+ showAlert({
+ title: 'Scan Error',
+ message: error instanceof Error ? error.message : 'Failed to process scanned document',
+ });
+ }
+ };
+
+ const handleRenameConfirm = async (name: string) => {
+ setRenameModalVisible(false);
+ await processScannedImages(scannedImageUris, name);
+ setScannedImageUris([]);
+ setDefaultDocumentName('');
+ };
+
+ const handleRenameCancel = () => {
+ setRenameModalVisible(false);
+ setScannedImageUris([]);
+ setDefaultDocumentName('');
+ };
+
+ const handleScanDocument = async () => {
+ onClose();
+
+ try {
+ const { scannedImages, status } = await DocumentScanner.scanDocument({
+ croppedImageQuality: 100,
+ });
+
+ if (status === 'cancel') {
+ return;
+ }
+
+ if (scannedImages && scannedImages.length > 0) {
+ const timestamp = Date.now();
+ setDefaultDocumentName(`scanned_document_${timestamp}`);
+ setScannedImageUris(scannedImages);
+ setRenameModalVisible(true);
+ } else {
+ showAlert({
+ title: 'Scan Error',
+ message: 'No images were scanned',
+ });
+ }
+ } catch (error) {
+ console.error('Error in handleScan:', error);
+ showAlert({
+ title: 'Scan Error',
+ message: error instanceof Error ? error.message : 'Failed to scan document',
+ });
+ }
+ };
return (
- <Modal
- visible={visible}
- transparent
- animationType="slide"
- onRequestClose={onClose}
- >
- <TouchableOpacity
- style={styles.backdrop}
- activeOpacity={1}
- onPress={onClose}
+ <>
+ <Modal
+ visible={visible}
+ transparent
+ animationType="slide"
+ onRequestClose={onClose}
>
- <View style={styles.drawer}>
- <View style={styles.header}>
- <Text style={styles.title}>Import Document</Text>
- </View>
+ <TouchableOpacity
+ style={styles.backdrop}
+ activeOpacity={1}
+ onPress={onClose}
+ >
+ <View style={styles.drawer}>
+ <View style={styles.header}>
+ <Text style={styles.title}>Import Document</Text>
+ </View>
+
+ <View style={styles.optionsContainer}>
+ <TouchableOpacity
+ style={styles.optionItem}
+ onPress={handleImportFromFiles}
+ >
+ <View style={styles.optionIconContainer}>
+ <Icon name="file-plus" size={24} style={styles.optionIcon} />
+ </View>
+ <View style={styles.optionTextContainer}>
+ <Text style={styles.optionTitle}>Import from Files</Text>
+ <Text style={styles.optionDescription}>
+ Choose a document from your device
+ </Text>
+ </View>
+ <Icon name="chevron-right" size={18} style={styles.chevronIcon} />
+ </TouchableOpacity>
+
+ <TouchableOpacity
+ style={styles.optionItem}
+ onPress={handleScanDocument}
+ >
+ <View style={styles.optionIconContainer}>
+ <Icon name="camera" size={24} style={styles.optionIcon} />
+ </View>
+ <View style={styles.optionTextContainer}>
+ <Text style={styles.optionTitle}>Scan Document</Text>
+ <Text style={styles.optionDescription}>
+ Use camera to scan a document
+ </Text>
+ </View>
+ <Icon name="chevron-right" size={18} style={styles.chevronIcon} />
+ </TouchableOpacity>
+ </View>
- <View style={styles.optionsContainer}>
<TouchableOpacity
- style={styles.optionItem}
- onPress={handleImportFromFiles}
+ style={styles.cancelButton}
+ onPress={onClose}
>
- <View style={styles.optionIconContainer}>
- <Icon name="file-plus" size={24} style={styles.optionIcon} />
- </View>
- <View style={styles.optionTextContainer}>
- <Text style={styles.optionTitle}>Import from Files</Text>
- <Text style={styles.optionDescription}>
- Choose a document from your device
- </Text>
- </View>
- <Icon name="chevron-right" size={18} style={styles.chevronIcon} />
+ <Text style={styles.cancelButtonText}>Cancel</Text>
</TouchableOpacity>
-
- {/* <TouchableOpacity
- style={styles.optionItem}
- onPress={handleScanDocument}
- >
- <View style={styles.optionIconContainer}>
- <Icon name="camera" size={24} style={styles.optionIcon} />
- </View>
- <View style={styles.optionTextContainer}>
- <Text style={styles.optionTitle}>Scan Document</Text>
- <Text style={styles.optionDescription}>
- Use camera to scan (Coming soon)
- </Text>
- </View>
- <Icon name="chevron-right" size={18} style={styles.chevronIcon} />
- </TouchableOpacity> */}
</View>
+ </TouchableOpacity>
+ </Modal>
- <TouchableOpacity
- style={styles.cancelButton}
- onPress={onClose}
- >
- <Text style={styles.cancelButtonText}>Cancel</Text>
- </TouchableOpacity>
- </View>
- </TouchableOpacity>
- </Modal>
+ <RenameDocumentDialog
+ visible={renameModalVisible}
+ defaultName={defaultDocumentName}
+ onConfirm={handleRenameConfirm}
+ onCancel={handleRenameCancel}
+ />
+ </>
);
}
diff --git a/apps/mobile/src/modules/documents/components/rename-document-dialog.tsx b/apps/mobile/src/modules/documents/components/rename-document-dialog.tsx
new file mode 100644
index 00000000..51456416
--- /dev/null
+++ b/apps/mobile/src/modules/documents/components/rename-document-dialog.tsx
@@ -0,0 +1,172 @@
+import type { ThemeColors } from '@/modules/ui/theme.constants';
+import { useEffect, useState } from 'react';
+import {
+ Modal,
+ StyleSheet,
+ Text,
+ TextInput,
+ TouchableOpacity,
+ TouchableWithoutFeedback,
+ View,
+} from 'react-native';
+import { useAlert } from '@/modules/ui/providers/alert-provider';
+import { useThemeColor } from '@/modules/ui/providers/use-theme-color';
+
+type RenameDocumentDialogProps = {
+ visible: boolean;
+ defaultName: string;
+ onConfirm: (name: string) => void;
+ onCancel: () => void;
+};
+
+export function RenameDocumentDialog({
+ visible,
+ defaultName,
+ onConfirm,
+ onCancel,
+}: RenameDocumentDialogProps) {
+ const themeColors = useThemeColor();
+ const { showAlert } = useAlert();
+ const styles = createStyles({ themeColors });
+ const [documentName, setDocumentName] = useState('');
+
+ // Reset name when modal becomes visible
+ useEffect(() => {
+ if (visible) {
+ setDocumentName(defaultName);
+ }
+ }, [visible, defaultName]);
+
+ const handleConfirm = () => {
+ if (documentName.trim() === '') {
+ showAlert({
+ title: 'Invalid Name',
+ message: 'Please enter a document name',
+ });
+ return;
+ }
+
+ onConfirm(documentName.trim());
+ setDocumentName('');
+ };
+
+ const handleCancel = () => {
+ setDocumentName('');
+ onCancel();
+ };
+
+ return (
+ <Modal
+ visible={visible}
+ transparent
+ animationType="fade"
+ onRequestClose={handleCancel}
+ >
+ <TouchableWithoutFeedback onPress={handleCancel}>
+ <View style={styles.backdrop}>
+ <TouchableWithoutFeedback>
+ <View style={styles.content}>
+ <View style={styles.header}>
+ <Text style={styles.title}>Document Name</Text>
+ </View>
+
+ <View style={styles.inputContainer}>
+ <TextInput
+ style={styles.input}
+ value={documentName}
+ onChangeText={setDocumentName}
+ placeholder="Enter document name"
+ placeholderTextColor={themeColors.mutedForeground}
+ autoFocus
+ onSubmitEditing={handleConfirm}
+ />
+ </View>
+
+ <View style={styles.buttons}>
+ <TouchableOpacity
+ style={[styles.button, styles.cancelButton]}
+ onPress={handleCancel}
+ >
+ <Text style={styles.cancelButtonText}>Cancel</Text>
+ </TouchableOpacity>
+ <TouchableOpacity
+ style={[styles.button, styles.confirmButton]}
+ onPress={handleConfirm}
+ >
+ <Text style={styles.confirmButtonText}>Save</Text>
+ </TouchableOpacity>
+ </View>
+ </View>
+ </TouchableWithoutFeedback>
+ </View>
+ </TouchableWithoutFeedback>
+ </Modal>
+ );
+}
+
+function createStyles({ themeColors }: { themeColors: ThemeColors }) {
+ return StyleSheet.create({
+ backdrop: {
+ flex: 1,
+ backgroundColor: 'rgba(0, 0, 0, 0.5)',
+ justifyContent: 'center',
+ alignItems: 'center',
+ padding: 20,
+ },
+ content: {
+ backgroundColor: themeColors.background,
+ borderRadius: 16,
+ width: '100%',
+ maxWidth: 400,
+ padding: 20,
+ },
+ header: {
+ marginBottom: 20,
+ },
+ title: {
+ fontSize: 20,
+ fontWeight: 'bold',
+ color: themeColors.foreground,
+ },
+ inputContainer: {
+ marginBottom: 20,
+ },
+ input: {
+ borderWidth: 1,
+ borderColor: themeColors.border,
+ borderRadius: 8,
+ padding: 12,
+ fontSize: 16,
+ color: themeColors.foreground,
+ backgroundColor: themeColors.secondaryBackground,
+ },
+ buttons: {
+ flexDirection: 'row',
+ gap: 12,
+ },
+ button: {
+ flex: 1,
+ paddingVertical: 12,
+ borderRadius: 8,
+ alignItems: 'center',
+ },
+ cancelButton: {
+ backgroundColor: themeColors.secondaryBackground,
+ borderWidth: 1,
+ borderColor: themeColors.border,
+ },
+ cancelButtonText: {
+ fontSize: 16,
+ fontWeight: '600',
+ color: themeColors.foreground,
+ },
+ confirmButton: {
+ backgroundColor: themeColors.primary,
+ },
+ confirmButtonText: {
+ fontSize: 16,
+ fontWeight: '600',
+ color: themeColors.primaryForeground,
+ },
+ });
+}
diff --git a/apps/mobile/src/modules/documents/documents-scan.services.ts b/apps/mobile/src/modules/documents/documents-scan.services.ts
new file mode 100644
index 00000000..5061fd27
--- /dev/null
+++ b/apps/mobile/src/modules/documents/documents-scan.services.ts
@@ -0,0 +1,82 @@
+import * as FileSystem from 'expo-file-system/legacy';
+import * as Print from 'expo-print';
+
+export async function convertImagesToPdf(imageUris: string[]): Promise<string> {
+ const images = imageUris.map(async (imageUri) => {
+ try {
+ // Read the image file
+ const base64Image = await FileSystem.readAsStringAsync(imageUri, {
+ encoding: FileSystem.EncodingType.Base64,
+ });
+
+ // Detect image format from URI
+ let imageType = 'jpeg';
+ if (imageUri.toLowerCase().includes('.png')) {
+ imageType = 'png';
+ } else if (imageUri.toLowerCase().includes('.jpg') || imageUri.toLowerCase().includes('.jpeg')) {
+ imageType = 'jpeg';
+ }
+
+ return { imageType, base64Image };
+ } catch (error) {
+ console.error('Error converting image to PDF:', error);
+ throw error;
+ }
+ });
+
+ // Create HTML with the image embedded
+ const html = `
+ <!DOCTYPE html>
+ <html>
+ <head>
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
+ <style>
+ @page {
+ margin: 0;
+ size: A4;
+ }
+ body {
+ margin: 0;
+ padding: 0;
+ }
+ .page {
+ page-break-after: always;
+ display: flex;
+ justify-content: center;
+ align-items: center;
+ width: 100vw;
+ height: 100vh;
+ min-height: 100vh;
+ }
+ img {
+ max-width: 100%;
+ max-height: 100vh;
+ object-fit: contain;
+ display: block;
+ }
+ </style>
+ </head>
+ <body>
+ ${(
+ await Promise.all(images)
+ )
+ .map(
+ image => `
+ <div class="page">
+ <img src="data:image/${image.imageType};base64,${image.base64Image}" />
+ </div>
+ `,
+ )
+ .join('')}
+ </body>
+ </html>
+`;
+
+ // Generate PDF from HTML
+ const { uri: pdfUri } = await Print.printToFileAsync({
+ html,
+ base64: false,
+ });
+
+ return pdfUri;
+}
diff --git a/apps/mobile/src/modules/documents/documents.local-storage.ts b/apps/mobile/src/modules/documents/documents.local-storage.ts
new file mode 100644
index 00000000..2c075ce0
--- /dev/null
+++ b/apps/mobile/src/modules/documents/documents.local-storage.ts
@@ -0,0 +1,60 @@
+import type { Document } from './documents.types';
+import * as FileSystem from 'expo-file-system/legacy';
+import { coerceDate } from '../api/api.models';
+import { buildStorageKey } from '../lib/local-storage/local-storage.models';
+import { storage } from '../lib/local-storage/local-storage.services';
+
+const UNSYNCED_DOCUMENTS_KEY = buildStorageKey(['documents', 'unsynced']);
+
+async function getUnsyncedDocuments(): Promise<Document[]> {
+ const data = await storage.getItem(UNSYNCED_DOCUMENTS_KEY);
+ if (data == null) {
+ return [];
+ }
+ const parsed = JSON.parse(data) as Array<Omit<Document, 'createdAt'> & { createdAt: string }>;
+ return parsed.map(doc => ({
+ ...doc,
+ createdAt: coerceDate(doc.createdAt).toISOString(),
+ }));
+}
+
+async function saveUnsyncedDocuments(documents: Document[]): Promise<void> {
+ await storage.setItem(UNSYNCED_DOCUMENTS_KEY, JSON.stringify(documents));
+}
+
+export const documentsLocalStorage = {
+ async addUnsyncedDocument(document: Document): Promise<void> {
+ const documents = await getUnsyncedDocuments();
+ documents.push(document);
+ await saveUnsyncedDocuments(documents);
+ },
+
+ async getUnsyncedDocuments(): Promise<Document[]> {
+ return getUnsyncedDocuments();
+ },
+
+ async getUnsyncedDocumentsByOrganization(organizationId: string): Promise<Document[]> {
+ const documents = await getUnsyncedDocuments();
+ return documents.filter(doc => doc.organizationId === organizationId);
+ },
+
+ async removeUnsyncedDocument(documentId: string): Promise<void> {
+ const documents = await getUnsyncedDocuments();
+ const filtered = documents.filter(doc => doc.id !== documentId);
+ await saveUnsyncedDocuments(filtered);
+ },
+
+ async deleteUnsyncedDocumentFile(documentId: string): Promise<void> {
+ const documents = await getUnsyncedDocuments();
+ const document = documents.find(doc => doc.id === documentId);
+ if (document != null) {
+ try {
+ if (document.localUri != null) {
+ await FileSystem.deleteAsync(document.localUri, { idempotent: true });
+ }
+ } catch (error) {
+ console.error('Error deleting unsynced document file:', error);
+ }
+ }
+ },
+};
diff --git a/apps/mobile/src/modules/documents/documents.services.ts b/apps/mobile/src/modules/documents/documents.services.ts
index 3fb8df9f..80cdf1f8 100644
--- a/apps/mobile/src/modules/documents/documents.services.ts
+++ b/apps/mobile/src/modules/documents/documents.services.ts
@@ -4,6 +4,7 @@ import type { AuthClient } from '../auth/auth.client';
import type { Document } from './documents.types';
import * as FileSystem from 'expo-file-system/legacy';
import { coerceDates } from '../api/api.models';
+import { documentsLocalStorage } from './documents.local-storage';
export function getFormData(pojo: Record<string, string | FormDataValue | Blob>): FormData {
const formData = new FormData();
@@ -70,11 +71,12 @@ export async function fetchOrganizationDocuments({
});
try {
- const documents = apiDocuments.map(coerceDates);
-
+ const remote = apiDocuments.map(coerceDates);
+ const local = await documentsLocalStorage.getUnsyncedDocumentsByOrganization(organizationId);
+ const documents = [...local, ...remote];
return {
- documentsCount,
- documents,
+ documentsCount: documentsCount + local.length,
+ documents: documents.map(coerceDates),
};
} catch (error) {
console.error('Error fetching documents:', error);
diff --git a/apps/mobile/src/modules/documents/documents.sync.services.ts b/apps/mobile/src/modules/documents/documents.sync.services.ts
new file mode 100644
index 00000000..6b68bb32
--- /dev/null
+++ b/apps/mobile/src/modules/documents/documents.sync.services.ts
@@ -0,0 +1,41 @@
+import type { ApiClient } from '../api/api.client';
+import { queryClient } from '../api/providers/query.provider';
+import { documentsLocalStorage } from './documents.local-storage';
+import { uploadDocument } from './documents.services';
+
+export async function syncUnsyncedDocuments({
+ organizationId,
+ apiClient,
+ onProgress,
+}: {
+ organizationId: string;
+ apiClient: ApiClient;
+ onProgress?: (syncedCount: number, totalCount: number) => void;
+}): Promise<void> {
+ const unsyncedDocuments = await documentsLocalStorage.getUnsyncedDocumentsByOrganization(organizationId);
+
+ if (unsyncedDocuments.length === 0) {
+ return;
+ }
+
+ let syncedCount = 0;
+
+ for (const unsyncedDoc of unsyncedDocuments) {
+ try {
+ await uploadDocument({ file: { uri: unsyncedDoc.localUri ?? '', name: unsyncedDoc.name, type: unsyncedDoc.mimeType }, apiClient, organizationId });
+
+ // Delete the local file and remove from unsynced list
+ await documentsLocalStorage.deleteUnsyncedDocumentFile(unsyncedDoc.id);
+ await documentsLocalStorage.removeUnsyncedDocument(unsyncedDoc.id);
+
+ syncedCount++;
+ onProgress?.(syncedCount, unsyncedDocuments.length);
+
+ // Invalidate queries to refresh the list
+ await queryClient.invalidateQueries({ queryKey: ['organizations', organizationId, 'documents'] });
+ } catch (error) {
+ console.error(`Error syncing document ${unsyncedDoc.id}:`, error);
+ // Continue with next document even if one fails
+ }
+ }
+}
diff --git a/apps/mobile/src/modules/documents/documents.types.ts b/apps/mobile/src/modules/documents/documents.types.ts
index 24b94919..e6b603d6 100644
--- a/apps/mobile/src/modules/documents/documents.types.ts
+++ b/apps/mobile/src/modules/documents/documents.types.ts
@@ -6,6 +6,7 @@ export type Document = {
organizationId: string;
createdAt: string;
updatedAt: string;
+ localUri: string | undefined;
tags: {
id: string;
name: string;
diff --git a/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx b/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx
index 6b2182b1..c8010e61 100644
--- a/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx
+++ b/apps/mobile/src/modules/documents/screens/documents-list.screen.tsx
@@ -21,6 +21,7 @@ import { useOrganizations } from '@/modules/organizations/organizations.provider
import { Icon } from '@/modules/ui/components/icon';
import { useThemeColor } from '@/modules/ui/providers/use-theme-color';
import { fetchOrganizationDocuments } from '../documents.services';
+import { syncUnsyncedDocuments } from '../documents.sync.services';
export function DocumentsListScreen() {
const themeColors = useThemeColor();
@@ -68,6 +69,9 @@ export function DocumentsListScreen() {
const onRefresh = async () => {
await documentsQuery.refetch();
+ if (currentOrganizationId != null) {
+ void syncUnsyncedDocuments({ organizationId: currentOrganizationId, apiClient });
+ }
};
if (isLoadingOrganizations) {
@@ -116,6 +120,11 @@ export function DocumentsListScreen() {
<Text style={styles.metaText}>{formatFileSize(item.originalSize)}</Text>
<Text style={styles.metaSplitter}>-</Text>
<Text style={styles.metaText}>{formatDate(item.createdAt)}</Text>
+ {item.localUri !== undefined && (
+ <View style={[styles.unsyncedBadge, { backgroundColor: `${themeColors.primary}20` }]}>
+ <Icon name="upload" size={12} color={themeColors.primary} />
+ </View>
+ )}
{item.tags.length > 0 && (
<View style={styles.tagsContainer}>
{item.tags.map(tag => (
@@ -249,5 +258,13 @@ function createStyles({ themeColors }: { themeColors: ThemeColors }) {
fontWeight: '500',
lineHeight: 12,
},
+ unsyncedBadge: {
+ flexDirection: 'row',
+ alignItems: 'center',
+ gap: 4,
+ paddingHorizontal: 8,
+ paddingVertical: 4,
+ borderRadius: 12,
+ },
});
}
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 3a9f21b7..61e15024 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -189,6 +189,9 @@ importers:
expo-network:
specifier: ^8.0.8
+ expo-print:
+ specifier: ^15.0.7
expo-router:
specifier: ~6.0.14
version: 6.0.14(49a2902d0574a0052a669c80d9729e84)
@@ -225,6 +228,9 @@ importers:
react-native:
specifier: 0.81.5
version: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+ react-native-document-scanner-plugin:
+ specifier: ^2.0.2
react-native-gesture-handler:
specifier: ~2.28.0
@@ -7414,6 +7420,12 @@ packages:
expo: '*'
react: '*'
+ resolution: {integrity: sha512-4O0Qzm0On5AmJIl9d+BT+ieTipFp658nHI4aX7vKEFPfj3dfQxG6rDJJpca+rrc9c4Ha8ZFYGvxJG5+4lFq2Pw==}
+ peerDependencies:
+ expo: '*'
+ react-native: '*'
+
resolution: {integrity: sha512-vizLO4SgnMEL+PPs2dXr+etEOuksjue7yUQBCtfCEdqoDkQlB0r35zI7rS34Wt53sxKWSlM2p+038qQEpxtiFw==}
peerDependencies:
@@ -10089,6 +10101,12 @@ packages:
react: '*'
react-native: '*'
+ resolution: {integrity: sha512-8Q3P96evd2tjbxvmDCCeseOlSCnzOlfP38Xuc4kn1y+PPVxERinKLSHBrPviZYknNf4zGtSueP4H6CZcJ4RxGw==}
+ peerDependencies:
+ react: '*'
+ react-native: '*'
+
resolution: {integrity: sha512-0msfJ1vRxXKVgTgvL+1ZOoYw3/0z1R+Ked0+udoJhyplC2jbVKIJ8Z1bzWdpQRCV3QcQ87Op0zJVE5DhKK2A0A==}
peerDependencies:
@@ -20517,6 +20535,11 @@ snapshots:
react: 19.1.0
+ dependencies:
+ react-native: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+
[email protected](49a2902d0574a0052a669c80d9729e84):
dependencies:
@@ -23951,6 +23974,11 @@ snapshots:
react: 19.1.0
react-native: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+ dependencies:
+ react: 19.1.0
+ react-native: 0.81.5(@babel/[email protected])(@react-native-community/[email protected]([email protected]))(@types/[email protected])([email protected])
+
dependencies:
'@egjs/hammerjs': 2.0.17