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