@umituz/react-native-ai-generation-content 1.83.11 → 1.83.13

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.83.11",
3
+ "version": "1.83.13",
4
4
  "description": "Provider-agnostic AI generation orchestration for React Native with result preview components",
5
5
  "main": "src/index.ts",
6
6
  "types": "src/index.ts",
@@ -4,7 +4,7 @@
4
4
  * Single Responsibility: Firestore query operations
5
5
  */
6
6
 
7
- import { getDocs, getDoc, query, orderBy, where } from "firebase/firestore";
7
+ import { getDocs, getDoc, query, orderBy } from "firebase/firestore";
8
8
  import type { IPathResolver } from "@umituz/react-native-firebase";
9
9
  import type { DocumentMapper } from "../../domain/value-objects/CreationsConfig";
10
10
  import type { Creation, CreationDocument } from "../../domain/entities/Creation";
@@ -28,20 +28,20 @@ export class CreationsQuery {
28
28
  try {
29
29
  const q = query(
30
30
  userCollection,
31
- where(CREATION_FIELDS.DELETED_AT, "==", null),
32
31
  orderBy(CREATION_FIELDS.CREATED_AT, "desc")
33
32
  );
34
33
  const snapshot = await getDocs(q);
35
34
 
36
- const creations = snapshot.docs.map((docSnap) => {
37
- const data = docSnap.data() as CreationDocument;
38
- return this.documentMapper(docSnap.id, data);
39
- });
35
+ const creations = snapshot.docs
36
+ .map((docSnap) => {
37
+ const data = docSnap.data() as CreationDocument;
38
+ return this.documentMapper(docSnap.id, data);
39
+ })
40
+ .filter((c) => c.deletedAt == null);
40
41
 
41
42
  if (__DEV__) {
42
43
  console.log("[CreationsQuery] Fetched creations:", {
43
44
  count: creations.length,
44
- hasDeletedFilter: true,
45
45
  });
46
46
  }
47
47
 
@@ -4,7 +4,7 @@
4
4
  * Single Responsibility: Firestore realtime listeners
5
5
  */
6
6
 
7
- import { query, orderBy, onSnapshot, where } from "firebase/firestore";
7
+ import { query, orderBy, onSnapshot } from "firebase/firestore";
8
8
  import type { IPathResolver } from "@umituz/react-native-firebase";
9
9
  import type { DocumentMapper } from "../../domain/value-objects/CreationsConfig";
10
10
  import type { CreationDocument } from "../../domain/entities/Creation";
@@ -35,7 +35,6 @@ export class CreationsSubscription {
35
35
 
36
36
  const q = query(
37
37
  userCollection,
38
- where(CREATION_FIELDS.DELETED_AT, "==", null),
39
38
  orderBy(CREATION_FIELDS.CREATED_AT, "desc")
40
39
  );
41
40
 
@@ -43,10 +42,12 @@ export class CreationsSubscription {
43
42
  q,
44
43
  { includeMetadataChanges: false },
45
44
  (snapshot) => {
46
- const creations = snapshot.docs.map((docSnap) => {
47
- const data = docSnap.data() as CreationDocument;
48
- return this.documentMapper(docSnap.id, data);
49
- });
45
+ const creations = snapshot.docs
46
+ .map((docSnap) => {
47
+ const data = docSnap.data() as CreationDocument;
48
+ return this.documentMapper(docSnap.id, data);
49
+ })
50
+ .filter((c) => c.deletedAt == null);
50
51
 
51
52
  if (__DEV__) {
52
53
  console.log("[CreationsSubscription] Sync:", creations.length, "items");
@@ -76,7 +76,7 @@ export function useCreations({
76
76
  }
77
77
  unsubscribe();
78
78
  };
79
- }, [userId, repository, enabled, onDataCallback, onErrorCallback]);
79
+ }, [userId, repository, enabled]); // onDataCallback/onErrorCallback intentionally omitted - stable memoized refs
80
80
 
81
81
  return { data, isLoading, error, refetch };
82
82
  }
@@ -75,20 +75,19 @@ export function useGalleryCallbacks(props: UseGalleryCallbacksProps) {
75
75
  const handleFavorite = useCallback(
76
76
  (c: Creation) => {
77
77
  void (async () => {
78
- if (__DEV__) {
79
- console.log("[handleFavorite] Called", { id: c.id, currentFavorite: c.isFavorite, userId });
78
+ try {
79
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
80
+ console.log("[handleFavorite] Called", { id: c.id, currentFavorite: c.isFavorite, userId });
81
+ }
82
+ if (!userId) return;
83
+ const newFavoriteStatus = !c.isFavorite;
84
+ const success = await repository.updateFavorite(userId, c.id, newFavoriteStatus);
85
+ if (success) void refetch();
86
+ } catch (e) {
87
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
88
+ console.error("[handleFavorite] Error:", e);
89
+ }
80
90
  }
81
- if (!userId) return;
82
- // Toggle the favorite status
83
- const newFavoriteStatus = !c.isFavorite;
84
- if (__DEV__) {
85
- console.log("[handleFavorite] Toggling", { newFavoriteStatus });
86
- }
87
- const success = await repository.updateFavorite(userId, c.id, newFavoriteStatus);
88
- if (__DEV__) {
89
- console.log("[handleFavorite] Update result", { success });
90
- }
91
- if (success) void refetch();
92
91
  })();
93
92
  },
94
93
  [userId, repository, refetch],
@@ -118,11 +117,17 @@ export function useGalleryCallbacks(props: UseGalleryCallbacksProps) {
118
117
  (rating: number, description: string) => {
119
118
  if (!userId || !selectedCreation) return;
120
119
  void (async () => {
121
- const success = await repository.rate(userId, selectedCreation.id, rating, description);
122
- if (success) {
123
- setSelectedCreation({ ...selectedCreation, rating, ratedAt: new Date() });
124
- alert.show(AlertType.SUCCESS, AlertMode.TOAST, t("result.rateSuccessTitle"), t("result.rateSuccessMessage"));
125
- void refetch();
120
+ try {
121
+ const success = await repository.rate(userId, selectedCreation.id, rating, description);
122
+ if (success) {
123
+ setSelectedCreation({ ...selectedCreation, rating, ratedAt: new Date() });
124
+ alert.show(AlertType.SUCCESS, AlertMode.TOAST, t("result.rateSuccessTitle"), t("result.rateSuccessMessage"));
125
+ void refetch();
126
+ }
127
+ } catch (e) {
128
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
129
+ console.error("[handleSubmitRating] Error:", e);
130
+ }
126
131
  }
127
132
  })();
128
133
  },
@@ -178,23 +178,32 @@ export function useProcessingJobsPoller(
178
178
  useEffect(() => {
179
179
  if (!enabled || !userId || orphanJobs.length === 0) return;
180
180
 
181
- orphanJobs.forEach(async (creation) => {
182
- const ageMs = Date.now() - creation.createdAt.getTime();
183
- if (ageMs < DEFAULT_MAX_POLL_TIME_MS) return;
181
+ const cleanupOrphans = async () => {
182
+ const staleOrphans = orphanJobs.filter((creation) => {
183
+ const ageMs = Date.now() - creation.createdAt.getTime();
184
+ return ageMs >= DEFAULT_MAX_POLL_TIME_MS;
185
+ });
184
186
 
187
+ if (staleOrphans.length === 0) return;
188
+
189
+ await Promise.allSettled(
190
+ staleOrphans.map(async (creation) => {
191
+ if (!isMountedRef.current) return;
192
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
193
+ console.log("[ProcessingJobsPoller] Orphan job timed out, marking as failed:", creation.id);
194
+ }
195
+ await repository.update(userId, creation.id, {
196
+ status: CREATION_STATUS.FAILED,
197
+ metadata: { ...creation.metadata, error: "Generation timed out" },
198
+ completedAt: new Date(),
199
+ });
200
+ }),
201
+ );
202
+ };
203
+
204
+ void cleanupOrphans().catch((e) => {
185
205
  if (typeof __DEV__ !== "undefined" && __DEV__) {
186
- console.log("[ProcessingJobsPoller] Orphan job timed out, marking as failed:", creation.id, { ageMs });
187
- }
188
- try {
189
- await repository.update(userId, creation.id, {
190
- status: CREATION_STATUS.FAILED,
191
- metadata: { ...creation.metadata, error: "Generation timed out" },
192
- completedAt: new Date(),
193
- });
194
- } catch (e) {
195
- if (typeof __DEV__ !== "undefined" && __DEV__) {
196
- console.error("[ProcessingJobsPoller] Failed to mark orphan job:", e);
197
- }
206
+ console.error("[ProcessingJobsPoller] Failed to clean up orphan jobs:", e);
198
207
  }
199
208
  });
200
209
  }, [enabled, userId, orphanJobs, repository]);