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

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/domain/entities/{MultimediaFlashcardTypes.ts → MediaAttachments.ts} +13 -32
  4. package/src/media/index.ts +24 -23
  5. package/src/media/infrastructure/services/MediaGenerationService.ts +1 -1
  6. package/src/media/infrastructure/services/MediaOptimizerService.ts +1 -1
  7. package/src/media/infrastructure/services/MediaUploadService.ts +1 -1
  8. package/src/media/infrastructure/services/MediaValidationService.ts +1 -1
  9. package/src/media/infrastructure/services/MultimediaFlashcardService.ts +1 -1
  10. package/src/media/infrastructure/utils/PermissionManager.ts +1 -1
  11. package/src/media/infrastructure/utils/media-collection-utils.ts +4 -2
  12. package/src/media/infrastructure/utils/mediaPickerMappers.ts +1 -1
  13. package/src/media/presentation/hooks/multimedia.types.ts +1 -1
  14. package/src/media/presentation/hooks/useCardMultimediaFlashcard.ts +4 -4
  15. package/src/media/presentation/hooks/useMedia.ts +2 -2
  16. package/src/media/presentation/hooks/useMediaGeneration.ts +1 -1
  17. package/src/media/presentation/hooks/useMediaUpload.ts +1 -1
  18. package/src/media/presentation/hooks/useMediaValidation.ts +1 -1
  19. package/src/media/presentation/hooks/useMultimediaFlashcard.ts +1 -1
  20. package/src/molecules/navigation/utils/AppNavigation.ts +3 -3
  21. package/src/storage/infrastructure/adapters/StorageService.ts +3 -3
  22. package/src/storage/infrastructure/repositories/BaseStorageOperations.ts +5 -5
  23. package/src/storage/presentation/hooks/CacheStorageOperations.ts +3 -3
  24. package/src/storage/presentation/hooks/useStore.ts +0 -1
  25. package/src/media/domain/entities/CardMultimedia.types.README.md +0 -129
  26. package/src/media/domain/entities/Media.README.md +0 -80
  27. package/src/media/domain/entities/MultimediaFlashcardTypes.README.md +0 -144
  28. package/src/media/domain/utils/MediaUtils.README.md +0 -178
  29. package/src/media/index.ts.README.md +0 -191
  30. package/src/media/infrastructure/services/CardMultimediaService.README.md +0 -176
  31. package/src/media/infrastructure/services/CardMultimediaService.ts +0 -98
  32. package/src/media/infrastructure/services/MediaGenerationService.README.md +0 -142
  33. package/src/media/infrastructure/services/MediaOptimizerService.README.md +0 -145
  34. package/src/media/infrastructure/services/MediaPickerService.README.md +0 -106
  35. package/src/media/infrastructure/services/MediaSaveService.README.md +0 -120
  36. package/src/media/infrastructure/services/MediaUploadService.README.md +0 -135
  37. package/src/media/infrastructure/services/MediaValidationService.README.md +0 -135
  38. package/src/media/infrastructure/services/MultimediaFlashcardService.README.md +0 -142
  39. package/src/media/infrastructure/utils/mediaHelpers.README.md +0 -96
  40. package/src/media/infrastructure/utils/mediaPickerMappers.README.md +0 -129
  41. package/src/media/presentation/hooks/card-multimedia.types.README.md +0 -177
  42. package/src/media/presentation/hooks/card-multimedia.types.ts +0 -53
  43. package/src/media/presentation/hooks/multimedia.types.README.md +0 -201
  44. package/src/media/presentation/hooks/useCardMediaGeneration.ts +0 -20
  45. package/src/media/presentation/hooks/useCardMediaUpload.ts +0 -84
  46. package/src/media/presentation/hooks/useCardMediaValidation.ts +0 -104
  47. package/src/media/presentation/hooks/useCardMultimediaFlashcard.README.md +0 -158
  48. package/src/media/presentation/hooks/useMedia.README.md +0 -94
  49. package/src/media/presentation/hooks/useMediaGeneration.README.md +0 -118
  50. package/src/media/presentation/hooks/useMediaUpload.README.md +0 -108
  51. package/src/media/presentation/hooks/useMediaValidation.README.md +0 -134
  52. package/src/media/presentation/hooks/useMultimediaFlashcard.README.md +0 -141
@@ -1,129 +0,0 @@
1
- # Media Picker Mappers
2
-
3
- ## Purpose
4
- Mapper functions to convert between expo-image-picker types and domain types, maintaining abstraction layer.
5
-
6
- ## File Location
7
- `src/infrastructure/utils/mediaPickerMappers.ts`
8
-
9
- ## Strategy
10
- - Isolate expo-image-picker dependency to infrastructure layer
11
- - Provide clean mapping between external and domain types
12
- - Handle permission status conversion
13
- - Convert media type enums to library-specific formats
14
- - Transform picker results to domain entities
15
- - Maintain compatibility with expo-image-picker API changes
16
-
17
- ## Forbidden
18
- - **DO NOT** import expo-image-picker outside infrastructure layer
19
- - **DO NOT** add business logic to mapping functions
20
- - **DO NOT** modify input parameters during mapping
21
- - **DO NOT** throw exceptions for invalid inputs (use defaults)
22
- - **DO NOT** add side effects to mapping functions
23
- - **DO NOT** directly use mapped types in domain or presentation layers
24
- - **DO NOT** create circular dependencies with picker implementation
25
-
26
- ## Rules
27
- 1. All mapping functions must be pure transformations
28
- 2. Permission status must map UNDETERMINED to DENIED
29
- 3. MediaType must convert to array format for expo-image-picker
30
- 4. Asset properties must use fallback values for undefined fields
31
- 5. All mappers must handle null/undefined inputs gracefully
32
- 6. Mapped types must match domain type contracts exactly
33
- 7. Must preserve all original data during transformation
34
- 8. Type conversion must be reversible where possible
35
- 9. Must handle all enum values explicitly
36
- 10. Default values must be documented
37
-
38
- ## AI Agent Guidelines
39
-
40
- When working with media picker mappers:
41
-
42
- 1. **Layer Isolation**: Only use mappers in infrastructure layer, never in domain/presentation
43
- 2. **Type Conversion**: Always use provided mappers, never manually convert types
44
- 3. **Permission Handling**: Check mapped permission status, not raw expo-image-picker values
45
- 4. **Media Types**: Use domain MediaType enum, then map to expo format when calling picker
46
- 5. **Result Processing**: Always map picker results before passing to other layers
47
- 6. **Fallback Values**: Be aware that asset properties may have default values
48
- 7. **Null Safety**: Handle undefined optional properties in mapped results
49
- 8. **Version Compatibility**: Update mappers when upgrading expo-image-picker
50
-
51
- ### Permission Status Mapping
52
-
53
- - **GRANTED** → GRANTED (full access)
54
- - **DENIED** → DENIED (no access)
55
- - **UNDETERMINED** → DENIED (treat as denied, request again)
56
-
57
- **Strategy**: Convert undetermined to denied to force explicit permission request
58
-
59
- ### MediaType Mapping
60
-
61
- | Domain MediaType | expo-image-picker Format |
62
- |-----------------|------------------------|
63
- | IMAGE | ["images"] |
64
- | VIDEO | ["videos"] |
65
- | ALL | ["images", "videos"] |
66
- | undefined | ["images"] (default) |
67
-
68
- **Strategy**: Convert domain enum to array format required by library
69
-
70
- ### Asset Transformation
71
-
72
- All asset fields are mapped with fallback values:
73
- - **uri**: Required, no fallback
74
- - **width**: Number, fallback 0
75
- - **height**: Number, fallback 0
76
- - **type**: MediaType enum (IMAGE or VIDEO)
77
- - **fileSize**: Number, fallback 0
78
- - **fileName**: String or undefined
79
- - **duration**: Number or undefined (video only)
80
- - **base64**: String or undefined (only when requested)
81
- - **mimeType**: String or undefined
82
-
83
- ### Picker Result Structure
84
-
85
- **Input Structure (expo-image-picker)**:
86
- - A boolean `canceled` field indicating whether the user cancelled the operation
87
- - An optional `assets` array containing Asset objects from expo-image-picker
88
-
89
- **Output Structure (MediaPickerResult)**:
90
- - A boolean `canceled` field (same as input)
91
- - An optional `assets` array containing MediaAsset domain objects
92
- - All Asset fields are transformed to MediaAsset fields with appropriate fallback values
93
-
94
- ### Integration Patterns
95
-
96
- 1. **Before Picker**: Convert domain types to picker types
97
- 2. **After Picker**: Convert picker results to domain types
98
- 3. **Permission Check**: Map permission status before domain layer access
99
- 4. **Error Handling**: Check canceled flag before processing assets
100
- 5. **Type Safety**: Use domain types throughout application logic
101
-
102
- ### Common Workflows
103
-
104
- 1. **Permission Request**: Check status → Map → Request → Map result
105
- 2. **Media Selection**: Map MediaType → Launch picker → Map result
106
- 3. **Multiple Selection**: Handle array of assets in mapper
107
- 4. **Camera vs Library**: Use same mappers for both picker types
108
-
109
- ### Validation Rules
110
-
111
- 1. Always check `canceled` flag before accessing assets
112
- 2. Validate assets array exists and has length > 0
113
- 3. Handle undefined optional properties gracefully
114
- 4. Check permission status before launching picker
115
- 5. Handle null asset properties with fallback values
116
-
117
- ### Error Handling
118
-
119
- 1. Cancelled operations return `{ canceled: true }`
120
- 2. Missing assets return empty array or undefined
121
- 3. Invalid types use default fallback values
122
- 4. Permission denied operations should be handled at application level
123
- 5. Never throw exceptions from mapping functions
124
-
125
- ## Dependencies
126
-
127
- - expo-image-picker (external library)
128
- - Domain layer types (MediaAsset, MediaPickerResult, MediaType, MediaLibraryPermission)
129
- - Infrastructure layer only
@@ -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,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
- };