@umituz/react-native-ai-generation-content 1.17.161 → 1.17.162

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-generation-content",
3
- "version": "1.17.161",
3
+ "version": "1.17.162",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -116,6 +116,13 @@ export { useCreations } from "./presentation/hooks/useCreations";
116
116
  export { useDeleteCreation } from "./presentation/hooks/useDeleteCreation";
117
117
  export { useCreationsFilter } from "./presentation/hooks/useCreationsFilter";
118
118
  export { useAdvancedFilter } from "./presentation/hooks/useAdvancedFilter";
119
+ export { useCreationPersistence } from "./presentation/hooks/useCreationPersistence";
120
+ export type {
121
+ UseCreationPersistenceConfig,
122
+ UseCreationPersistenceReturn,
123
+ ProcessingStartData,
124
+ ProcessingResult,
125
+ } from "./presentation/hooks/useCreationPersistence";
119
126
 
120
127
  // =============================================================================
121
128
  // PRESENTATION LAYER - Components
@@ -14,3 +14,10 @@ export type {
14
14
  export { useFilter, useStatusFilter, useMediaFilter } from "./useFilter";
15
15
  export type { UseFilterProps, UseFilterReturn } from "./useFilter";
16
16
  export { useGalleryFilters } from "./useGalleryFilters";
17
+ export { useCreationPersistence } from "./useCreationPersistence";
18
+ export type {
19
+ UseCreationPersistenceConfig,
20
+ UseCreationPersistenceReturn,
21
+ ProcessingStartData,
22
+ ProcessingResult,
23
+ } from "./useCreationPersistence";
@@ -0,0 +1,133 @@
1
+ /**
2
+ * useCreationPersistence Hook
3
+ * Encapsulates Firestore persistence logic for AI generation features
4
+ * Eliminates boilerplate code in feature screens
5
+ */
6
+
7
+ import { useCallback, useMemo } from "react";
8
+ import { useQueryClient } from "@tanstack/react-query";
9
+ import { useAuth } from "@umituz/react-native-auth";
10
+ import { createCreationsRepository } from "../../infrastructure/adapters";
11
+ import type { Creation } from "../../domain/entities/Creation";
12
+
13
+ /**
14
+ * Configuration for creation persistence
15
+ */
16
+ export interface UseCreationPersistenceConfig {
17
+ /** Creation type identifier (e.g., "anime-selfie", "ai-kiss") */
18
+ readonly type: string;
19
+ /** Collection name in Firestore (defaults to "creations") */
20
+ readonly collectionName?: string;
21
+ }
22
+
23
+ /**
24
+ * Generic processing start data - all features must have creationId
25
+ */
26
+ export interface ProcessingStartData {
27
+ readonly creationId: string;
28
+ readonly [key: string]: unknown;
29
+ }
30
+
31
+ /**
32
+ * Generic processing result - all features should have creationId
33
+ */
34
+ export interface ProcessingResult {
35
+ readonly creationId?: string;
36
+ readonly imageUrl?: string;
37
+ readonly videoUrl?: string;
38
+ readonly [key: string]: unknown;
39
+ }
40
+
41
+ /**
42
+ * Return type for useCreationPersistence
43
+ */
44
+ export interface UseCreationPersistenceReturn {
45
+ readonly onProcessingStart: (data: ProcessingStartData) => void;
46
+ readonly onProcessingComplete: (result: ProcessingResult) => void;
47
+ readonly onError: (error: string, creationId?: string) => void;
48
+ }
49
+
50
+ /**
51
+ * Hook that provides Firestore persistence callbacks for AI features
52
+ *
53
+ * @example
54
+ * // In AnimeSelfieScreen:
55
+ * const persistence = useCreationPersistence({ type: "anime-selfie" });
56
+ * const config = useMemo(() => ({
57
+ * prepareImage,
58
+ * ...persistence,
59
+ * }), [persistence]);
60
+ */
61
+ export function useCreationPersistence(
62
+ config: UseCreationPersistenceConfig,
63
+ ): UseCreationPersistenceReturn {
64
+ const { type, collectionName = "creations" } = config;
65
+ const { userId } = useAuth();
66
+ const queryClient = useQueryClient();
67
+
68
+ const repository = useMemo(
69
+ () => createCreationsRepository(collectionName),
70
+ [collectionName],
71
+ );
72
+
73
+ const onProcessingStart = useCallback(
74
+ (data: ProcessingStartData) => {
75
+ if (!userId) return;
76
+
77
+ const { creationId, ...rest } = data;
78
+ const creation: Creation = {
79
+ id: creationId,
80
+ uri: "",
81
+ type,
82
+ status: "processing",
83
+ createdAt: new Date(),
84
+ isShared: false,
85
+ isFavorite: false,
86
+ metadata: rest,
87
+ };
88
+
89
+ repository.create(userId, creation);
90
+ queryClient.invalidateQueries({ queryKey: ["creations"] });
91
+ },
92
+ [userId, repository, queryClient, type],
93
+ );
94
+
95
+ const onProcessingComplete = useCallback(
96
+ (result: ProcessingResult) => {
97
+ if (!userId || !result.creationId) return;
98
+
99
+ const uri = result.imageUrl || result.videoUrl || "";
100
+ const output = result.imageUrl
101
+ ? { imageUrl: result.imageUrl }
102
+ : result.videoUrl
103
+ ? { videoUrl: result.videoUrl }
104
+ : undefined;
105
+
106
+ repository.update(userId, result.creationId, {
107
+ uri,
108
+ status: "completed",
109
+ output,
110
+ });
111
+ queryClient.invalidateQueries({ queryKey: ["creations"] });
112
+ },
113
+ [userId, repository, queryClient],
114
+ );
115
+
116
+ const onError = useCallback(
117
+ (error: string, creationId?: string) => {
118
+ if (!userId || !creationId) return;
119
+
120
+ repository.update(userId, creationId, {
121
+ status: "failed",
122
+ metadata: { error },
123
+ });
124
+ queryClient.invalidateQueries({ queryKey: ["creations"] });
125
+ },
126
+ [userId, repository, queryClient],
127
+ );
128
+
129
+ return useMemo(
130
+ () => ({ onProcessingStart, onProcessingComplete, onError }),
131
+ [onProcessingStart, onProcessingComplete, onError],
132
+ );
133
+ }