@umituz/react-native-design-system 4.23.100 → 4.23.102

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 (52) hide show
  1. package/package.json +1 -1
  2. package/src/atoms/AtomicInput.tsx +0 -2
  3. package/src/media/index.ts +26 -22
  4. package/src/media/infrastructure/utils/media-collection-utils.ts +4 -2
  5. package/src/molecules/navigation/utils/AppNavigation.ts +3 -3
  6. package/src/storage/infrastructure/adapters/StorageService.ts +3 -3
  7. package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +9 -9
  8. package/src/storage/presentation/hooks/CacheStorageOperations.ts +3 -3
  9. package/src/storage/presentation/hooks/useStore.ts +0 -1
  10. package/src/media/domain/entities/CardMultimedia.types.README.md +0 -129
  11. package/src/media/domain/entities/Media.README.md +0 -80
  12. package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +0 -144
  13. package/src/media/domain/entities/MultimediaFlashcardTypes.ts +0 -120
  14. package/src/media/domain/utils/MediaUtils.README.md +0 -178
  15. package/src/media/index.ts.README.md +0 -191
  16. package/src/media/infrastructure/services/CardMultimediaService.README.md +0 -176
  17. package/src/media/infrastructure/services/CardMultimediaService.ts +0 -98
  18. package/src/media/infrastructure/services/MediaGenerationService.README.md +0 -142
  19. package/src/media/infrastructure/services/MediaGenerationService.ts +0 -80
  20. package/src/media/infrastructure/services/MediaOptimizerService.README.md +0 -145
  21. package/src/media/infrastructure/services/MediaOptimizerService.ts +0 -32
  22. package/src/media/infrastructure/services/MediaPickerService.README.md +0 -106
  23. package/src/media/infrastructure/services/MediaPickerService.ts +0 -157
  24. package/src/media/infrastructure/services/MediaSaveService.README.md +0 -120
  25. package/src/media/infrastructure/services/MediaSaveService.ts +0 -97
  26. package/src/media/infrastructure/services/MediaUploadService.README.md +0 -135
  27. package/src/media/infrastructure/services/MediaUploadService.ts +0 -60
  28. package/src/media/infrastructure/services/MediaValidationService.README.md +0 -135
  29. package/src/media/infrastructure/services/MediaValidationService.ts +0 -61
  30. package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +0 -142
  31. package/src/media/infrastructure/services/MultimediaFlashcardService.ts +0 -96
  32. package/src/media/infrastructure/utils/mediaHelpers.README.md +0 -96
  33. package/src/media/infrastructure/utils/mediaPickerMappers.README.md +0 -129
  34. package/src/media/presentation/hooks/card-multimedia.types.README.md +0 -177
  35. package/src/media/presentation/hooks/card-multimedia.types.ts +0 -53
  36. package/src/media/presentation/hooks/multimedia.types.README.md +0 -201
  37. package/src/media/presentation/hooks/multimedia.types.ts +0 -53
  38. package/src/media/presentation/hooks/useCardMediaGeneration.ts +0 -20
  39. package/src/media/presentation/hooks/useCardMediaUpload.ts +0 -84
  40. package/src/media/presentation/hooks/useCardMediaValidation.ts +0 -104
  41. package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +0 -158
  42. package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +0 -102
  43. package/src/media/presentation/hooks/useMedia.README.md +0 -94
  44. package/src/media/presentation/hooks/useMedia.ts +0 -190
  45. package/src/media/presentation/hooks/useMediaGeneration.README.md +0 -118
  46. package/src/media/presentation/hooks/useMediaGeneration.ts +0 -18
  47. package/src/media/presentation/hooks/useMediaUpload.README.md +0 -108
  48. package/src/media/presentation/hooks/useMediaUpload.ts +0 -84
  49. package/src/media/presentation/hooks/useMediaValidation.README.md +0 -134
  50. package/src/media/presentation/hooks/useMediaValidation.ts +0 -93
  51. package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +0 -141
  52. package/src/media/presentation/hooks/useMultimediaFlashcard.ts +0 -101
@@ -1,177 +0,0 @@
1
- # Card Multimedia Hook Types
2
-
3
- ## Purpose
4
- TypeScript return type interfaces for card-specific multimedia hooks in the presentation layer.
5
-
6
- ## File Location
7
- `src/presentation/hooks/card-multimedia.types.ts`
8
-
9
- ## Strategy
10
- - Define contracts for card multimedia hook implementations
11
- - Ensure type safety across card media operations
12
- - Provide consistent return types for upload, generation, and validation
13
- - Support card-specific media operations (including image search)
14
- - Enable proper error handling and loading states
15
- - Maintain separation between card and general multimedia types
16
-
17
- ## Forbidden
18
- - **DO NOT** import implementation details or hooks in type files
19
- - **DO NOT** mix CardMediaAttachment and MediaAttachment types
20
- - **DO NOT** add business logic to type definitions
21
- - **DO NOT** use `any` type for function parameters or returns
22
- - **DO NOT** create circular dependencies with domain types
23
- - **DO NOT** export implementation-specific types
24
- - **DO NOT** modify these types without updating all hook implementations
25
-
26
- ## Rules
27
- 1. All hook returns must include loading state, error state, and operation function
28
- 2. Async operations must return Promise with appropriate type
29
- 3. Error states must be string | null (not Error objects)
30
- 4. Progress/results must be null when not active
31
- 5. Boolean states must clearly indicate operation in progress
32
- 6. All interfaces must be exported and public
33
- 7. Type names must follow Use*Result pattern
34
- 8. Functions must accept domain types, not external types
35
- 9. Optional parameters must be clearly marked
36
- 10. Return types must match hook implementations exactly
37
-
38
- ## AI Agent Guidelines
39
-
40
- When working with card multimedia hook types:
41
-
42
- 1. **Type Imports**: Always import types from this file for card multimedia hooks
43
- 2. **Hook Implementation**: Implement hooks that return these exact interfaces
44
- 3. **Card vs General**: Use Card* types for card-specific operations, Media* for general
45
- 4. **Error Handling**: Always check error state before using results
46
- 5. **Loading States**: Respect loading states to prevent race conditions
47
- 6. **Progress Tracking**: Use progress objects for upload operations
48
- 7. **Type Safety**: Use these types for all card multimedia hook return values
49
- 8. **Testing**: Mock these interfaces when testing card media operations
50
-
51
- ### Hook Return Type Structure
52
-
53
- All card multimedia hook returns follow this consistent pattern:
54
-
55
- **Core Components**:
56
- - **operationFunction**: An async function that accepts parameters and returns a Promise with the result type
57
- - **isOperationInProgress**: A boolean flag indicating whether the operation is currently running
58
- - **operationResult**: The result object or null when no operation is active
59
- - **error**: A string containing error messages or null when no error exists
60
-
61
- ### UseCardMediaUploadResult
62
-
63
- **Purpose**: Card media upload operations with compression options
64
-
65
- **Key Features**:
66
- - Upload function accepts file and compression options
67
- - Tracks upload progress
68
- - Returns CardMediaAttachment
69
- - Handles upload errors
70
-
71
- **Usage Pattern**:
72
- 1. Check `isUploading` before calling
73
- 2. Call `uploadMedia()` with file and optional compression
74
- 3. Monitor `uploadProgress` during upload
75
- 4. Check `error` state on completion
76
- 5. Use returned CardMediaAttachment on success
77
-
78
- ### UseCardMediaGenerationResult
79
-
80
- **Purpose**: Card media generation (AI-based generation, image search)
81
-
82
- **Key Features**:
83
- - Generation function accepts request parameters
84
- - Tracks generation status
85
- - Returns CardMediaGenerationResult
86
- - Supports multiple generation methods
87
-
88
- **Usage Pattern**:
89
- 1. Prepare CardMediaGenerationRequest
90
- 2. Check `isGenerating` before calling
91
- 3. Call `generateMedia()` with request
92
- 4. Access `generationResult` when complete
93
- 5. Handle `error` if generation fails
94
-
95
- ### UseCardMediaValidationResult
96
-
97
- **Purpose**: Card media validation before upload or processing
98
-
99
- **Key Features**:
100
- - Validation function accepts file
101
- - Tracks validation status
102
- - Returns CardMediaValidation result
103
- - Provides detailed validation errors
104
-
105
- **Usage Pattern**:
106
- 1. Check `isValidating` before calling
107
- 2. Call `validateMedia()` with file
108
- 3. Access `validation` result for validity check
109
- 4. Use `validation.errors` array for error details
110
- 5. Check `error` state for validation failures
111
-
112
- ### UseCardMultimediaFlashcardResult
113
-
114
- **Purpose**: Card flashcard CRUD operations
115
-
116
- **Key Features**:
117
- - Create card with multimedia
118
- - Update card media
119
- - Delete specific media attachment
120
- - Tracks processing state
121
- - Returns CardMultimediaFlashcard
122
-
123
- **Usage Pattern**:
124
- 1. Create: Call `createCardMultimedia()` with card data
125
- 2. Update: Call `updateCardMedia()` with cardId and media array
126
- 3. Delete: Call `deleteCardMedia()` with attachmentId
127
- 4. Check `isProcessing` before operations
128
- 5. Handle `error` state for failures
129
-
130
- ### Card vs General Multimedia Types
131
-
132
- | Operation | Card Types | General Types | Key Difference |
133
- |-----------|-----------|---------------|----------------|
134
- | Upload | CardMediaAttachment | MediaAttachment | Card-specific metadata |
135
- | Generation | CardMediaGenerationRequest | MediaGenerationRequest | Cards include image search |
136
- | Validation | CardMediaValidation | MediaValidation | Card-specific rules |
137
- | Flashcard | CardMultimediaFlashcard | MultimediaFlashcard | Different entity types |
138
-
139
- ### Type Guards and Validation
140
-
141
- 1. **Upload Hook**: Check for `uploadMedia` function and `isUploading` boolean
142
- 2. **Generation Hook**: Check for `generateMedia` function and `isGenerating` boolean
143
- 3. **Validation Hook**: Check for `validateMedia` function and `isValidating` boolean
144
- 4. **Flashcard Hook**: Check for all three CRUD functions and `isProcessing` boolean
145
-
146
- ### Error Handling Patterns
147
-
148
- 1. Always check if `error !== null` before using results
149
- 2. Errors are strings, not Error objects
150
- 3. Clear error before starting new operation
151
- 4. Show user-friendly error messages
152
- 5. Handle null states for progress/results
153
-
154
- ### Async Operation Patterns
155
-
156
- 1. **Before Call**: Check loading state to prevent concurrent calls
157
- 2. **During Call**: Show loading indicator based on boolean state
158
- 3. **After Call**: Check error state, then use result
159
- 4. **Error Case**: Display error, reset loading state
160
- 5. **Success Case**: Use result, clear error
161
-
162
- ### Related Domain Types
163
-
164
- These interfaces use domain types:
165
- - CardMediaAttachment
166
- - CardMediaGenerationRequest
167
- - CardMediaGenerationResult
168
- - CardMediaCompressionOptions
169
- - CardMediaValidation
170
- - CardMediaUploadProgress
171
- - CardMultimediaFlashcard
172
-
173
- ## Dependencies
174
-
175
- - Domain layer types (Card* entities)
176
- - Presentation layer hooks
177
- - No external dependencies
@@ -1,53 +0,0 @@
1
- /**
2
- * Card Multimedia Flashcard Hook Types
3
- * Type definitions for card multimedia hooks
4
- */
5
-
6
- import type {
7
- CardMediaAttachment,
8
- CardMediaFile,
9
- CardMediaGenerationRequest,
10
- CardMediaGenerationResult,
11
- CardMediaCompressionOptions,
12
- CardMediaValidation,
13
- CardMediaUploadProgress,
14
- CardMultimediaFlashcard,
15
- CreateCardMultimediaData,
16
- } from "../../domain/entities/CardMultimedia.types";
17
-
18
- export interface UseCardMediaUploadResult {
19
- uploadMedia: (
20
- file: CardMediaFile,
21
- options?: CardMediaCompressionOptions,
22
- ) => Promise<CardMediaAttachment>;
23
- isUploading: boolean;
24
- uploadProgress: CardMediaUploadProgress | null;
25
- error: string | null;
26
- }
27
-
28
- export interface UseCardMediaGenerationResult {
29
- generateMedia: (
30
- request: CardMediaGenerationRequest,
31
- ) => Promise<CardMediaGenerationResult>;
32
- isGenerating: boolean;
33
- generationResult: CardMediaGenerationResult | null;
34
- error: string | null;
35
- }
36
-
37
- export interface UseCardMediaValidationResult {
38
- validateMedia: (file: CardMediaFile) => Promise<CardMediaValidation>;
39
- isValidating: boolean;
40
- validation: CardMediaValidation | null;
41
- error: string | null;
42
- }
43
-
44
- export interface UseCardMultimediaFlashcardResult {
45
- createCardMultimedia: (cardData: CreateCardMultimediaData) => Promise<CardMultimediaFlashcard>;
46
- updateCardMedia: (
47
- cardId: string,
48
- media: CardMediaAttachment[],
49
- ) => Promise<CardMultimediaFlashcard>;
50
- deleteCardMedia: (attachmentId: string) => Promise<void>;
51
- isProcessing: boolean;
52
- error: string | null;
53
- }
@@ -1,201 +0,0 @@
1
- # Multimedia Hook Types
2
-
3
- ## Purpose
4
- TypeScript return type interfaces for general multimedia hooks in the presentation layer.
5
-
6
- ## File Location
7
- `src/presentation/hooks/multimedia.types.ts`
8
-
9
- ## Strategy
10
- - Define contracts for general multimedia hook implementations
11
- - Ensure type safety across media operations
12
- - Provide consistent return types for upload, generation, and validation
13
- - Support general-purpose media operations
14
- - Enable proper error handling and loading states
15
- - Maintain separation from card-specific multimedia types
16
-
17
- ## Forbidden
18
- - **DO NOT** import implementation details or hooks in type files
19
- - **DO NOT** mix MediaAttachment and CardMediaAttachment types
20
- - **DO NOT** add business logic to type definitions
21
- - **DO NOT** use `any` type for function parameters or returns
22
- - **DO NOT** create circular dependencies with domain types
23
- - **DO NOT** export implementation-specific types
24
- - **DO NOT** modify these types without updating all hook implementations
25
-
26
- ## Rules
27
- 1. All hook returns must include loading state, error state, and operation function
28
- 2. Async operations must return Promise with appropriate type
29
- 3. Error states must be string | null (not Error objects)
30
- 4. Progress/results must be null when not active
31
- 5. Boolean states must clearly indicate operation in progress
32
- 6. All interfaces must be exported and public
33
- 7. Type names must follow Use*Result pattern
34
- 8. Functions must accept domain types, not external types
35
- 9. Optional parameters must be clearly marked
36
- 10. Return types must match hook implementations exactly
37
-
38
- ## AI Agent Guidelines
39
-
40
- When working with multimedia hook types:
41
-
42
- 1. **Type Imports**: Always import types from this file for general multimedia hooks
43
- 2. **Hook Implementation**: Implement hooks that return these exact interfaces
44
- 3. **General vs Card**: Use Media* types for general operations, Card* for card-specific
45
- 4. **Error Handling**: Always check error state before using results
46
- 5. **Loading States**: Respect loading states to prevent race conditions
47
- 6. **Progress Tracking**: Use progress objects for upload operations
48
- 7. **Type Safety**: Use these types for all general multimedia hook return values
49
- 8. **Testing**: Mock these interfaces when testing media operations
50
-
51
- ### Hook Return Type Structure
52
-
53
- All multimedia hook returns follow this consistent pattern:
54
-
55
- **Core Components**:
56
- - **operationFunction**: An async function that accepts parameters and returns a Promise with the result type
57
- - **isOperationInProgress**: A boolean flag indicating whether the operation is currently running
58
- - **operationResult**: The result object or null when no operation is active
59
- - **error**: A string containing error messages or null when no error exists
60
-
61
- ### UseMediaUploadResult
62
-
63
- **Purpose**: General media upload operations with compression options
64
-
65
- **Key Features**:
66
- - Upload function accepts file and compression options
67
- - Tracks upload progress
68
- - Returns MediaAttachment
69
- - Handles upload errors
70
-
71
- **Usage Pattern**:
72
- 1. Check `isUploading` before calling
73
- 2. Call `uploadMedia()` with file and optional compression
74
- 3. Monitor `uploadProgress` during upload
75
- 4. Check `error` state on completion
76
- 5. Use returned MediaAttachment on success
77
-
78
- ### UseMediaGenerationResult
79
-
80
- **Purpose**: General media generation (AI-based generation without image search)
81
-
82
- **Key Features**:
83
- - Generation function accepts request parameters
84
- - Tracks generation status
85
- - Returns MediaGenerationResult
86
- - Supports core generation methods
87
-
88
- **Usage Pattern**:
89
- 1. Prepare MediaGenerationRequest
90
- 2. Check `isGenerating` before calling
91
- 3. Call `generateMedia()` with request
92
- 4. Access `generationResult` when complete
93
- 5. Handle `error` if generation fails
94
-
95
- ### UseMediaValidationResult
96
-
97
- **Purpose**: General media validation before upload or processing
98
-
99
- **Key Features**:
100
- - Validation function accepts file
101
- - Tracks validation status
102
- - Returns MediaValidation result
103
- - Provides detailed validation errors
104
-
105
- **Usage Pattern**:
106
- 1. Check `isValidating` before calling
107
- 2. Call `validateMedia()` with file
108
- 3. Access `validation` result for validity check
109
- 4. Use `validation.errors` array for error details
110
- 5. Check `error` state for validation failures
111
-
112
- ### UseMultimediaFlashcardResult
113
-
114
- **Purpose**: General flashcard CRUD operations
115
-
116
- **Key Features**:
117
- - Create flashcard with multimedia
118
- - Update flashcard media
119
- - Delete specific media attachment
120
- - Tracks processing state
121
- - Returns MultimediaFlashcard
122
-
123
- **Usage Pattern**:
124
- 1. Create: Call `createMultimediaCard()` with card data
125
- 2. Update: Call `updateMedia()` with cardId and media array
126
- 3. Delete: Call `deleteMedia()` with attachmentId
127
- 4. Check `isProcessing` before operations
128
- 5. Handle `error` state for failures
129
-
130
- ### General vs Card Multimedia Types
131
-
132
- | Operation | General Types | Card Types | Key Difference |
133
- |-----------|--------------|------------|----------------|
134
- | Upload | MediaAttachment | CardMediaAttachment | Different entity structures |
135
- | Generation | MediaGenerationRequest | CardMediaGenerationRequest | Cards include image search |
136
- | Validation | MediaValidation | CardMediaValidation | Different validation rules |
137
- | Flashcard | MultimediaFlashcard | CardMultimediaFlashcard | Different entity types |
138
- | Features | Core operations | Core + image search | Card has extended features |
139
-
140
- ### When to Use Which Types
141
-
142
- **Use Media* Types (General)**:
143
- - Generic media handling
144
- - Non-card-specific operations
145
- - Reusable media components
146
- - General-purpose flashcards
147
-
148
- **Use Card* Types (Card-Specific)**:
149
- - Card-specific operations
150
- - Image search functionality
151
- - Card entity management
152
- - Card-specific validation rules
153
-
154
- ### Type Guards and Validation
155
-
156
- 1. **Upload Hook**: Check for `uploadMedia` function and `isUploading` boolean
157
- 2. **Generation Hook**: Check for `generateMedia` function and `isGenerating` boolean
158
- 3. **Validation Hook**: Check for `validateMedia` function and `isValidating` boolean
159
- 4. **Flashcard Hook**: Check for all three CRUD functions and `isProcessing` boolean
160
-
161
- ### Error Handling Patterns
162
-
163
- 1. Always check if `error !== null` before using results
164
- 2. Errors are strings, not Error objects
165
- 3. Clear error before starting new operation
166
- 4. Show user-friendly error messages
167
- 5. Handle null states for progress/results
168
-
169
- ### Async Operation Patterns
170
-
171
- 1. **Before Call**: Check loading state to prevent concurrent calls
172
- 2. **During Call**: Show loading indicator based on boolean state
173
- 3. **After Call**: Check error state, then use result
174
- 4. **Error Case**: Display error, reset loading state
175
- 5. **Success Case**: Use result, clear error
176
-
177
- ### Composable Hooks Pattern
178
-
179
- Combine multiple hook types for complex workflows:
180
-
181
- 1. **Validate Then Upload**: Use validation result before calling upload
182
- 2. **Generate Then Upload**: Chain generation and upload operations
183
- 3. **Upload Then Create Card**: Use upload result to create flashcard
184
- 4. **Parallel Operations**: Use multiple hooks independently
185
-
186
- ### Related Domain Types
187
-
188
- These interfaces use domain types:
189
- - MediaAttachment
190
- - MediaGenerationRequest
191
- - MediaGenerationResult
192
- - MediaCompressionOptions
193
- - MediaValidation
194
- - MediaUploadProgress
195
- - MultimediaFlashcard
196
-
197
- ## Dependencies
198
-
199
- - Domain layer types (Media* entities)
200
- - Presentation layer hooks
201
- - No external dependencies
@@ -1,53 +0,0 @@
1
- /**
2
- * Multimedia Flashcard Hook Types
3
- * Type definitions for multimedia hooks
4
- */
5
-
6
- import type {
7
- MediaAttachment,
8
- MediaFile,
9
- MediaGenerationRequest,
10
- MediaGenerationResult,
11
- MediaCompressionOptions,
12
- MediaValidation,
13
- MediaUploadProgress,
14
- MultimediaFlashcard,
15
- CreateMultimediaCardData,
16
- } from "../../domain/entities/MultimediaFlashcardTypes";
17
-
18
- export interface UseMediaUploadResult {
19
- uploadMedia: (
20
- file: MediaFile,
21
- options?: MediaCompressionOptions,
22
- ) => Promise<MediaAttachment>;
23
- isUploading: boolean;
24
- uploadProgress: MediaUploadProgress | null;
25
- error: string | null;
26
- }
27
-
28
- export interface UseMediaGenerationResult {
29
- generateMedia: (
30
- request: MediaGenerationRequest,
31
- ) => Promise<MediaGenerationResult>;
32
- isGenerating: boolean;
33
- generationResult: MediaGenerationResult | null;
34
- error: string | null;
35
- }
36
-
37
- export interface UseMediaValidationResult {
38
- validateMedia: (file: MediaFile) => Promise<MediaValidation>;
39
- isValidating: boolean;
40
- validation: MediaValidation | null;
41
- error: string | null;
42
- }
43
-
44
- export interface UseMultimediaFlashcardResult {
45
- createMultimediaCard: (cardData: CreateMultimediaCardData) => Promise<MultimediaFlashcard>;
46
- updateMedia: (
47
- cardId: string,
48
- media: MediaAttachment[],
49
- ) => Promise<MultimediaFlashcard>;
50
- deleteMedia: (attachmentId: string) => Promise<void>;
51
- isProcessing: boolean;
52
- error: string | null;
53
- }
@@ -1,20 +0,0 @@
1
- /**
2
- * Card Media Generation Hook
3
- * Hook for generating card media with AI
4
- * Now a thin wrapper around useGenericMediaGeneration
5
- *
6
- * Note: CardMedia types are aliases of Media types for backward compatibility
7
- */
8
-
9
- import { useGenericMediaGeneration } from "../../infrastructure/hooks/useGenericMediaGeneration";
10
- import type { UseCardMediaGenerationResult } from "./card-multimedia.types";
11
- import type {
12
- MediaAttachment as CardMediaAttachment,
13
- MediaGenerationRequest as CardMediaGenerationRequest,
14
- } from "../../domain/entities/MultimediaFlashcardTypes";
15
-
16
- export const useCardMediaGeneration = (): UseCardMediaGenerationResult => {
17
- return useGenericMediaGeneration<CardMediaAttachment, CardMediaGenerationRequest>(
18
- (baseAttachment) => baseAttachment as CardMediaAttachment
19
- );
20
- };
@@ -1,84 +0,0 @@
1
- /**
2
- * Card Media Upload Hook
3
- * Hook for uploading card media files
4
- */
5
-
6
- import { useState, useCallback } from "react";
7
- import { generateThumbnail, getMediaDuration } from "../../infrastructure/utils/file-media-utils";
8
- import { getMediaTypeFromMime } from "../../infrastructure/utils/mime-type-detector";
9
- import type { UseCardMediaUploadResult } from "./card-multimedia.types";
10
- import type {
11
- MediaAttachment as CardMediaAttachment,
12
- MediaCompressionOptions as CardMediaCompressionOptions,
13
- MediaFile as CardMediaFile,
14
- MediaUploadProgress as CardMediaUploadProgress,
15
- } from "../../domain/entities/MultimediaFlashcardTypes";
16
-
17
- export const useCardMediaUpload = (): UseCardMediaUploadResult => {
18
- const [isUploading, setIsUploading] = useState(false);
19
- const [uploadProgress, setUploadProgress] =
20
- useState<CardMediaUploadProgress | null>(null);
21
- const [error, setError] = useState<string | null>(null);
22
-
23
- const uploadMedia = useCallback(
24
- async (file: CardMediaFile, _options?: CardMediaCompressionOptions) => {
25
- try {
26
- setIsUploading(true);
27
- setError(null);
28
-
29
- // Simulate upload progress
30
- setUploadProgress({
31
- fileId: `upload_${Date.now()}`,
32
- progress: 0,
33
- status: "uploading",
34
- });
35
-
36
- // Simulate progress updates
37
- for (let i = 1; i <= 100; i += 10) {
38
- await new Promise((resolve) => setTimeout(resolve, 50));
39
- setUploadProgress((prev) => (prev ? { ...prev, progress: i } : null));
40
- }
41
-
42
- const attachment: CardMediaAttachment = {
43
- id: `card_media_${Date.now()}`,
44
- type: getMediaTypeFromMime(file.type),
45
- position: "both",
46
- url: `https://storage.example.com/media/${Date.now()}_${file.name}`,
47
- filename: file.name,
48
- fileSize: file.size || 100000,
49
- mimeType: file.type,
50
- duration: await getMediaDuration(file),
51
- thumbnailUrl: generateThumbnail(file),
52
- caption: "",
53
- isDownloaded: true,
54
- createdAt: new Date().toISOString(),
55
- };
56
-
57
- setUploadProgress({
58
- fileId: `upload_${Date.now()}`,
59
- progress: 100,
60
- status: "completed",
61
- url: attachment.url,
62
- });
63
-
64
- return attachment;
65
- } catch (err) {
66
- const errorMessage =
67
- err instanceof Error ? err.message : "Upload failed";
68
- setError(errorMessage);
69
- setIsUploading(false);
70
- throw err;
71
- } finally {
72
- setIsUploading(false);
73
- }
74
- },
75
- [],
76
- );
77
-
78
- return {
79
- uploadMedia,
80
- isUploading,
81
- uploadProgress,
82
- error,
83
- };
84
- };
@@ -1,104 +0,0 @@
1
- /**
2
- * Card Media Validation Hook
3
- * Hook for validating card media files
4
- */
5
-
6
- import { useState, useCallback } from "react";
7
- import { formatFileSize } from "../../infrastructure/utils/media-collection-utils";
8
- import type { UseCardMediaValidationResult } from "./card-multimedia.types";
9
- import type {
10
- MediaValidation as CardMediaValidation,
11
- MediaFile as CardMediaFile,
12
- } from "../../domain/entities/MultimediaFlashcardTypes";
13
-
14
- export const useCardMediaValidation = (): UseCardMediaValidationResult => {
15
- const [isValidating, setIsValidating] = useState(false);
16
- const [validation, setValidation] =
17
- useState<CardMediaValidation | null>(null);
18
- const [error, setError] = useState<string | null>(null);
19
-
20
- const validateMedia = useCallback(
21
- async (file: CardMediaFile): Promise<CardMediaValidation> => {
22
- try {
23
- setIsValidating(true);
24
- setError(null);
25
-
26
- // Simulate validation
27
- await new Promise((resolve) => setTimeout(resolve, 500));
28
-
29
- const errors: string[] = [];
30
- const warnings: string[] = [];
31
- const recommendations: string[] = [];
32
-
33
- // File size validation
34
- const maxSize = 50 * 1024 * 1024; // 50MB
35
- if (file.size > maxSize) {
36
- errors.push(
37
- `File size (${formatFileSize(file.size)}) exceeds maximum allowed size (${formatFileSize(maxSize)})`,
38
- );
39
- } else if (file.size > 10 * 1024 * 1024) {
40
- // 10MB
41
- warnings.push(`Large file size may impact performance`);
42
- recommendations.push("Consider compressing file");
43
- }
44
-
45
- // File type validation
46
- const supportedTypes = [
47
- "image/jpeg",
48
- "image/png",
49
- "image/webp",
50
- "audio/mp3",
51
- "audio/wav",
52
- "audio/m4a",
53
- "video/mp4",
54
- "video/mov",
55
- ];
56
-
57
- if (!supportedTypes.includes(file.type)) {
58
- errors.push(`Unsupported file type: ${file.type}`);
59
- }
60
-
61
- // Media-specific validations
62
- if (file.type.startsWith("image/")) {
63
- if (file.size > 5 * 1024 * 1024) {
64
- // 5MB for images
65
- warnings.push("Very large image may cause performance issues");
66
- recommendations.push("Consider resizing image to under 5MB");
67
- }
68
- }
69
-
70
- const result: CardMediaValidation = {
71
- isValid: errors.length === 0,
72
- errors,
73
- warnings,
74
- recommendations,
75
- };
76
-
77
- setValidation(result);
78
- return result;
79
- } catch (err) {
80
- const errorMessage =
81
- err instanceof Error ? err.message : "Validation failed";
82
- setError(errorMessage);
83
- setIsValidating(false);
84
-
85
- return {
86
- isValid: false,
87
- errors: [errorMessage],
88
- warnings: [],
89
- recommendations: [],
90
- };
91
- } finally {
92
- setIsValidating(false);
93
- }
94
- },
95
- [],
96
- );
97
-
98
- return {
99
- validateMedia,
100
- isValidating,
101
- validation,
102
- error,
103
- };
104
- };