@oxyhq/services 22.12.2 → 22.12.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/ui/hooks/useSurfaceHeader.js +44 -7
- package/lib/commonjs/ui/hooks/useSurfaceHeader.js.map +1 -1
- package/lib/commonjs/ui/navigation/surfaces.js +8 -3
- package/lib/commonjs/ui/navigation/surfaces.js.map +1 -1
- package/lib/commonjs/ui/screens/CreateAccountScreen.js +6 -1
- package/lib/commonjs/ui/screens/CreateAccountScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/FileManagementScreen.js +1 -0
- package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js +10 -7
- package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/UploadBar.js +19 -11
- package/lib/commonjs/ui/screens/fileManagement/UploadBar.js.map +1 -1
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js +28 -3
- package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/module/ui/hooks/useSurfaceHeader.js +45 -8
- package/lib/module/ui/hooks/useSurfaceHeader.js.map +1 -1
- package/lib/module/ui/navigation/surfaces.js +7 -1
- package/lib/module/ui/navigation/surfaces.js.map +1 -1
- package/lib/module/ui/screens/CreateAccountScreen.js +7 -2
- package/lib/module/ui/screens/CreateAccountScreen.js.map +1 -1
- package/lib/module/ui/screens/FileManagementScreen.js +1 -0
- package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js +10 -7
- package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/UploadBar.js +20 -12
- package/lib/module/ui/screens/fileManagement/UploadBar.js.map +1 -1
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js +29 -4
- package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
- package/lib/typescript/commonjs/ui/hooks/useSurfaceHeader.d.ts +7 -0
- package/lib/typescript/commonjs/ui/hooks/useSurfaceHeader.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/navigation/surfaces.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/CreateAccountScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/UploadBar.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts +3 -1
- package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/lib/typescript/module/ui/hooks/useSurfaceHeader.d.ts +7 -0
- package/lib/typescript/module/ui/hooks/useSurfaceHeader.d.ts.map +1 -1
- package/lib/typescript/module/ui/navigation/surfaces.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/CreateAccountScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/FileManagementScreen.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/UploadBar.d.ts.map +1 -1
- package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts +3 -1
- package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/ui/hooks/useSurfaceHeader.ts +65 -8
- package/src/ui/navigation/surfaces.ts +9 -1
- package/src/ui/screens/CreateAccountScreen.tsx +8 -2
- package/src/ui/screens/FileManagementScreen.tsx +1 -0
- package/src/ui/screens/fileManagement/PhotoPickerSection.tsx +4 -5
- package/src/ui/screens/fileManagement/UploadBar.tsx +17 -10
- package/src/ui/screens/fileManagement/hooks/useFileUploadState.ts +35 -4
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type React from 'react';
|
|
2
|
-
import { useCallback, useRef, useState } from 'react';
|
|
2
|
+
import { useCallback, useEffect, useRef, useState } from 'react';
|
|
3
3
|
import { useQueryClient } from '@tanstack/react-query';
|
|
4
4
|
import { toast } from '@oxyhq/bloom';
|
|
5
5
|
import type { AssetUploadInput, FileMetadata } from '@oxyhq/core';
|
|
@@ -62,6 +62,8 @@ export interface UseFileUploadStateParams {
|
|
|
62
62
|
onPicked?: (file: FileMetadata) => void;
|
|
63
63
|
goBack?: () => void;
|
|
64
64
|
onClose?: () => void;
|
|
65
|
+
/** When true, the document picker and pre-upload validation accept images only. */
|
|
66
|
+
imagesOnly?: boolean;
|
|
65
67
|
selectedIds: Set<string>;
|
|
66
68
|
setSelectedIds: React.Dispatch<React.SetStateAction<Set<string>>>;
|
|
67
69
|
t: (key: string, vars?: Record<string, string | number>) => string;
|
|
@@ -99,6 +101,7 @@ export const useFileUploadState = ({
|
|
|
99
101
|
onPicked,
|
|
100
102
|
goBack,
|
|
101
103
|
onClose,
|
|
104
|
+
imagesOnly = false,
|
|
102
105
|
selectedIds,
|
|
103
106
|
setSelectedIds,
|
|
104
107
|
t,
|
|
@@ -111,6 +114,23 @@ export const useFileUploadState = ({
|
|
|
111
114
|
|
|
112
115
|
const queryClient = useQueryClient();
|
|
113
116
|
const uploadStartRef = useRef<number | null>(null);
|
|
117
|
+
const postSelectTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
118
|
+
const isActiveRef = useRef(true);
|
|
119
|
+
|
|
120
|
+
const clearPostSelectTimer = useCallback(() => {
|
|
121
|
+
if (postSelectTimerRef.current) {
|
|
122
|
+
clearTimeout(postSelectTimerRef.current);
|
|
123
|
+
postSelectTimerRef.current = null;
|
|
124
|
+
}
|
|
125
|
+
}, []);
|
|
126
|
+
|
|
127
|
+
useEffect(() => {
|
|
128
|
+
isActiveRef.current = true;
|
|
129
|
+
return () => {
|
|
130
|
+
isActiveRef.current = false;
|
|
131
|
+
clearPostSelectTimer();
|
|
132
|
+
};
|
|
133
|
+
}, [clearPostSelectTimer]);
|
|
114
134
|
|
|
115
135
|
const endUpload = useCallback(() => {
|
|
116
136
|
const started = uploadStartRef.current;
|
|
@@ -277,6 +297,11 @@ export const useFileUploadState = ({
|
|
|
277
297
|
|
|
278
298
|
const fileType = candidateType(file);
|
|
279
299
|
|
|
300
|
+
if (imagesOnly && !fileType.startsWith('image/')) {
|
|
301
|
+
toast.error(t('fileManagement.toasts.imagesOnlyRequired'));
|
|
302
|
+
continue;
|
|
303
|
+
}
|
|
304
|
+
|
|
280
305
|
// Generate preview for images - unified approach
|
|
281
306
|
let preview: string | undefined;
|
|
282
307
|
if (fileType.startsWith('image/')) {
|
|
@@ -311,7 +336,7 @@ export const useFileUploadState = ({
|
|
|
311
336
|
// Show preview modal for user to review files before upload
|
|
312
337
|
setPendingFiles(processedFiles);
|
|
313
338
|
setShowUploadPreview(true);
|
|
314
|
-
}, [t]);
|
|
339
|
+
}, [imagesOnly, t]);
|
|
315
340
|
|
|
316
341
|
const handleConfirmUpload = async () => {
|
|
317
342
|
if (pendingFiles.length === 0) return;
|
|
@@ -335,7 +360,11 @@ export const useFileUploadState = ({
|
|
|
335
360
|
// If in selectMode, automatically select the uploaded file(s)
|
|
336
361
|
if (selectMode && uploadedFiles.length > 0) {
|
|
337
362
|
// Defer one tick so the query cache has settled before selecting.
|
|
338
|
-
|
|
363
|
+
clearPostSelectTimer();
|
|
364
|
+
postSelectTimerRef.current = setTimeout(() => {
|
|
365
|
+
postSelectTimerRef.current = null;
|
|
366
|
+
if (!isActiveRef.current) return;
|
|
367
|
+
|
|
339
368
|
const fileToSelect = uploadedFiles[0];
|
|
340
369
|
if (!multiSelect && fileToSelect) {
|
|
341
370
|
if (onPicked) {
|
|
@@ -371,6 +400,8 @@ export const useFileUploadState = ({
|
|
|
371
400
|
};
|
|
372
401
|
|
|
373
402
|
const handleCancelUpload = () => {
|
|
403
|
+
clearPostSelectTimer();
|
|
404
|
+
|
|
374
405
|
// Cleanup preview URLs
|
|
375
406
|
for (const pf of pendingFiles) {
|
|
376
407
|
revokePreviewUrl(pf.preview);
|
|
@@ -412,7 +443,7 @@ export const useFileUploadState = ({
|
|
|
412
443
|
// Use expo-document-picker (works on all platforms including web)
|
|
413
444
|
// On web, it uses the native file input and provides File objects directly
|
|
414
445
|
const result = await picker.getDocumentAsync({
|
|
415
|
-
type: '*/*',
|
|
446
|
+
type: imagesOnly ? 'image/*' : '*/*',
|
|
416
447
|
multiple: true,
|
|
417
448
|
copyToCacheDirectory: true,
|
|
418
449
|
});
|