@yogiswara/honcho-editor-ui 1.4.15 → 1.4.17
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/dist/hooks/useGallerySwipe.js +21 -19
- package/package.json +1 -1
|
@@ -28,15 +28,6 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
28
28
|
// This prevents the hook from re-initializing when the same values are passed
|
|
29
29
|
const prevFirebaseUid = useRef(null);
|
|
30
30
|
const prevInitImageId = useRef(null);
|
|
31
|
-
/**
|
|
32
|
-
* Get the index of the current image in the loaded image list
|
|
33
|
-
* Returns -1 if the current image is not found in the list
|
|
34
|
-
*/
|
|
35
|
-
const getCurrentImageIndex = useCallback(() => {
|
|
36
|
-
if (!currentImageId || currentImageList.length === 0)
|
|
37
|
-
return -1;
|
|
38
|
-
return currentImageList.findIndex(img => img.id === currentImageId);
|
|
39
|
-
}, [currentImageId, currentImageList]);
|
|
40
31
|
/**
|
|
41
32
|
* Fetch image pages sequentially until the target image is found
|
|
42
33
|
* This is necessary because we don't know which page contains the initial image
|
|
@@ -178,7 +169,13 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
178
169
|
setIsLoading(true);
|
|
179
170
|
setError(null);
|
|
180
171
|
try {
|
|
181
|
-
|
|
172
|
+
// Debug logging
|
|
173
|
+
console.log("=== SWIPE NEXT DEBUG ===");
|
|
174
|
+
console.log("currentImageId:", currentImageId);
|
|
175
|
+
console.log("currentImageList length:", currentImageList.length);
|
|
176
|
+
console.log("currentImageList IDs:", currentImageList.map(img => img.id).join(", "));
|
|
177
|
+
// Calculate current index directly to avoid stale closure issues
|
|
178
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
182
179
|
console.log("Current index: ", currentIndex);
|
|
183
180
|
if (currentIndex === -1) {
|
|
184
181
|
throw new Error('Current image not found in list');
|
|
@@ -194,6 +191,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
194
191
|
setCurrentImageList(updatedList);
|
|
195
192
|
// Navigate to first image of the new page
|
|
196
193
|
const nextImage = newImages[0];
|
|
194
|
+
console.log("Setting currentImageId to:", nextImage.id);
|
|
197
195
|
setCurrentImageId(nextImage.id);
|
|
198
196
|
// Fetch complete data for the new current image
|
|
199
197
|
const nextImageData = await controller.onGetImage(firebaseUid, nextImage.id);
|
|
@@ -210,6 +208,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
210
208
|
// Scenario 2: Navigate to next image in current list
|
|
211
209
|
const nextImage = currentImageList[currentIndex + 1];
|
|
212
210
|
console.log("[SCENARIO 2] Navigating to next image:", nextImage.id);
|
|
211
|
+
console.log("Setting currentImageId from", currentImageId, "to", nextImage.id);
|
|
213
212
|
setCurrentImageId(nextImage.id);
|
|
214
213
|
// Fetch complete data for the next image
|
|
215
214
|
const nextImageData = await controller.onGetImage(firebaseUid, nextImage.id);
|
|
@@ -226,7 +225,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
226
225
|
finally {
|
|
227
226
|
setIsLoading(false);
|
|
228
227
|
}
|
|
229
|
-
}, [currentImageId, isLoading,
|
|
228
|
+
}, [currentImageId, isLoading, currentImageList, loadNextPage, controller, firebaseUid]);
|
|
230
229
|
/**
|
|
231
230
|
* Navigate to the previous image in the gallery
|
|
232
231
|
* Only works within the currently loaded image list
|
|
@@ -241,7 +240,8 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
241
240
|
setIsLoading(true);
|
|
242
241
|
setError(null);
|
|
243
242
|
try {
|
|
244
|
-
|
|
243
|
+
// Calculate current index directly to avoid stale closure issues
|
|
244
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
245
245
|
if (currentIndex === -1) {
|
|
246
246
|
throw new Error('Current image not found in list');
|
|
247
247
|
}
|
|
@@ -268,7 +268,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
268
268
|
finally {
|
|
269
269
|
setIsLoading(false);
|
|
270
270
|
}
|
|
271
|
-
}, [currentImageId, isLoading,
|
|
271
|
+
}, [currentImageId, isLoading, currentImageList, controller, firebaseUid]);
|
|
272
272
|
/**
|
|
273
273
|
* Calculate if next image navigation is available
|
|
274
274
|
* Returns true if:
|
|
@@ -278,9 +278,10 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
278
278
|
* @returns Boolean indicating if next navigation is possible
|
|
279
279
|
*/
|
|
280
280
|
const isNextAvailable = useCallback(() => {
|
|
281
|
-
if (isLoading)
|
|
281
|
+
if (isLoading || !currentImageId)
|
|
282
282
|
return false;
|
|
283
|
-
|
|
283
|
+
// Calculate current index directly to avoid stale closure issues
|
|
284
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
284
285
|
if (currentIndex === -1)
|
|
285
286
|
return false;
|
|
286
287
|
// If we're not at the last image, next is definitely available
|
|
@@ -288,7 +289,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
288
289
|
return true;
|
|
289
290
|
// If we're at the last image but there are more pages, next is still available
|
|
290
291
|
return hasNextPage;
|
|
291
|
-
}, [isLoading,
|
|
292
|
+
}, [isLoading, currentImageId, currentImageList, hasNextPage]);
|
|
292
293
|
/**
|
|
293
294
|
* Calculate if previous image navigation is available
|
|
294
295
|
* Returns true if there's a previous image in the currently loaded list
|
|
@@ -296,11 +297,12 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
296
297
|
* @returns Boolean indicating if previous navigation is possible
|
|
297
298
|
*/
|
|
298
299
|
const isPrevAvailable = useCallback(() => {
|
|
299
|
-
if (isLoading)
|
|
300
|
+
if (isLoading || !currentImageId)
|
|
300
301
|
return false;
|
|
301
|
-
|
|
302
|
+
// Calculate current index directly to avoid stale closure issues
|
|
303
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
302
304
|
return currentIndex > 0;
|
|
303
|
-
}, [isLoading,
|
|
305
|
+
}, [isLoading, currentImageId, currentImageList]);
|
|
304
306
|
// Initialize when dependencies change
|
|
305
307
|
useEffect(() => {
|
|
306
308
|
initializeGallery();
|