@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.
Files changed (54) hide show
  1. package/lib/commonjs/ui/hooks/useSurfaceHeader.js +44 -7
  2. package/lib/commonjs/ui/hooks/useSurfaceHeader.js.map +1 -1
  3. package/lib/commonjs/ui/navigation/surfaces.js +8 -3
  4. package/lib/commonjs/ui/navigation/surfaces.js.map +1 -1
  5. package/lib/commonjs/ui/screens/CreateAccountScreen.js +6 -1
  6. package/lib/commonjs/ui/screens/CreateAccountScreen.js.map +1 -1
  7. package/lib/commonjs/ui/screens/FileManagementScreen.js +1 -0
  8. package/lib/commonjs/ui/screens/FileManagementScreen.js.map +1 -1
  9. package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js +10 -7
  10. package/lib/commonjs/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
  11. package/lib/commonjs/ui/screens/fileManagement/UploadBar.js +19 -11
  12. package/lib/commonjs/ui/screens/fileManagement/UploadBar.js.map +1 -1
  13. package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js +28 -3
  14. package/lib/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
  15. package/lib/module/ui/hooks/useSurfaceHeader.js +45 -8
  16. package/lib/module/ui/hooks/useSurfaceHeader.js.map +1 -1
  17. package/lib/module/ui/navigation/surfaces.js +7 -1
  18. package/lib/module/ui/navigation/surfaces.js.map +1 -1
  19. package/lib/module/ui/screens/CreateAccountScreen.js +7 -2
  20. package/lib/module/ui/screens/CreateAccountScreen.js.map +1 -1
  21. package/lib/module/ui/screens/FileManagementScreen.js +1 -0
  22. package/lib/module/ui/screens/FileManagementScreen.js.map +1 -1
  23. package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js +10 -7
  24. package/lib/module/ui/screens/fileManagement/PhotoPickerSection.js.map +1 -1
  25. package/lib/module/ui/screens/fileManagement/UploadBar.js +20 -12
  26. package/lib/module/ui/screens/fileManagement/UploadBar.js.map +1 -1
  27. package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js +29 -4
  28. package/lib/module/ui/screens/fileManagement/hooks/useFileUploadState.js.map +1 -1
  29. package/lib/typescript/commonjs/ui/hooks/useSurfaceHeader.d.ts +7 -0
  30. package/lib/typescript/commonjs/ui/hooks/useSurfaceHeader.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/ui/navigation/surfaces.d.ts.map +1 -1
  32. package/lib/typescript/commonjs/ui/screens/CreateAccountScreen.d.ts.map +1 -1
  33. package/lib/typescript/commonjs/ui/screens/FileManagementScreen.d.ts.map +1 -1
  34. package/lib/typescript/commonjs/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/ui/screens/fileManagement/UploadBar.d.ts.map +1 -1
  36. package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts +3 -1
  37. package/lib/typescript/commonjs/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
  38. package/lib/typescript/module/ui/hooks/useSurfaceHeader.d.ts +7 -0
  39. package/lib/typescript/module/ui/hooks/useSurfaceHeader.d.ts.map +1 -1
  40. package/lib/typescript/module/ui/navigation/surfaces.d.ts.map +1 -1
  41. package/lib/typescript/module/ui/screens/CreateAccountScreen.d.ts.map +1 -1
  42. package/lib/typescript/module/ui/screens/FileManagementScreen.d.ts.map +1 -1
  43. package/lib/typescript/module/ui/screens/fileManagement/PhotoPickerSection.d.ts.map +1 -1
  44. package/lib/typescript/module/ui/screens/fileManagement/UploadBar.d.ts.map +1 -1
  45. package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts +3 -1
  46. package/lib/typescript/module/ui/screens/fileManagement/hooks/useFileUploadState.d.ts.map +1 -1
  47. package/package.json +1 -1
  48. package/src/ui/hooks/useSurfaceHeader.ts +65 -8
  49. package/src/ui/navigation/surfaces.ts +9 -1
  50. package/src/ui/screens/CreateAccountScreen.tsx +8 -2
  51. package/src/ui/screens/FileManagementScreen.tsx +1 -0
  52. package/src/ui/screens/fileManagement/PhotoPickerSection.tsx +4 -5
  53. package/src/ui/screens/fileManagement/UploadBar.tsx +17 -10
  54. 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
- setTimeout(() => {
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
  });