@yogiswara/honcho-editor-ui 1.4.15 → 1.4.16
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 +14 -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,8 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
178
169
|
setIsLoading(true);
|
|
179
170
|
setError(null);
|
|
180
171
|
try {
|
|
181
|
-
|
|
172
|
+
// Calculate current index directly to avoid stale closure issues
|
|
173
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
182
174
|
console.log("Current index: ", currentIndex);
|
|
183
175
|
if (currentIndex === -1) {
|
|
184
176
|
throw new Error('Current image not found in list');
|
|
@@ -226,7 +218,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
226
218
|
finally {
|
|
227
219
|
setIsLoading(false);
|
|
228
220
|
}
|
|
229
|
-
}, [currentImageId, isLoading,
|
|
221
|
+
}, [currentImageId, isLoading, currentImageList, loadNextPage, controller, firebaseUid]);
|
|
230
222
|
/**
|
|
231
223
|
* Navigate to the previous image in the gallery
|
|
232
224
|
* Only works within the currently loaded image list
|
|
@@ -241,7 +233,8 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
241
233
|
setIsLoading(true);
|
|
242
234
|
setError(null);
|
|
243
235
|
try {
|
|
244
|
-
|
|
236
|
+
// Calculate current index directly to avoid stale closure issues
|
|
237
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
245
238
|
if (currentIndex === -1) {
|
|
246
239
|
throw new Error('Current image not found in list');
|
|
247
240
|
}
|
|
@@ -268,7 +261,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
268
261
|
finally {
|
|
269
262
|
setIsLoading(false);
|
|
270
263
|
}
|
|
271
|
-
}, [currentImageId, isLoading,
|
|
264
|
+
}, [currentImageId, isLoading, currentImageList, controller, firebaseUid]);
|
|
272
265
|
/**
|
|
273
266
|
* Calculate if next image navigation is available
|
|
274
267
|
* Returns true if:
|
|
@@ -278,9 +271,10 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
278
271
|
* @returns Boolean indicating if next navigation is possible
|
|
279
272
|
*/
|
|
280
273
|
const isNextAvailable = useCallback(() => {
|
|
281
|
-
if (isLoading)
|
|
274
|
+
if (isLoading || !currentImageId)
|
|
282
275
|
return false;
|
|
283
|
-
|
|
276
|
+
// Calculate current index directly to avoid stale closure issues
|
|
277
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
284
278
|
if (currentIndex === -1)
|
|
285
279
|
return false;
|
|
286
280
|
// If we're not at the last image, next is definitely available
|
|
@@ -288,7 +282,7 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
288
282
|
return true;
|
|
289
283
|
// If we're at the last image but there are more pages, next is still available
|
|
290
284
|
return hasNextPage;
|
|
291
|
-
}, [isLoading,
|
|
285
|
+
}, [isLoading, currentImageId, currentImageList, hasNextPage]);
|
|
292
286
|
/**
|
|
293
287
|
* Calculate if previous image navigation is available
|
|
294
288
|
* Returns true if there's a previous image in the currently loaded list
|
|
@@ -296,11 +290,12 @@ export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
|
296
290
|
* @returns Boolean indicating if previous navigation is possible
|
|
297
291
|
*/
|
|
298
292
|
const isPrevAvailable = useCallback(() => {
|
|
299
|
-
if (isLoading)
|
|
293
|
+
if (isLoading || !currentImageId)
|
|
300
294
|
return false;
|
|
301
|
-
|
|
295
|
+
// Calculate current index directly to avoid stale closure issues
|
|
296
|
+
const currentIndex = currentImageList.findIndex(img => img.id === currentImageId);
|
|
302
297
|
return currentIndex > 0;
|
|
303
|
-
}, [isLoading,
|
|
298
|
+
}, [isLoading, currentImageId, currentImageList]);
|
|
304
299
|
// Initialize when dependencies change
|
|
305
300
|
useEffect(() => {
|
|
306
301
|
initializeGallery();
|