@yogiswara/honcho-editor-ui 2.7.13 → 2.7.14
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 +1 -1
- package/dist/color.d.ts +0 -9
- package/dist/color.js +0 -9
- package/dist/components/editor/GalleryAlbum/AlbumImageGallery.d.ts +0 -8
- package/dist/components/editor/GalleryAlbum/AlbumImageGallery.js +0 -28
- package/dist/components/editor/GalleryAlbum/ImageItem.d.ts +0 -10
- package/dist/components/editor/GalleryAlbum/ImageItem.js +0 -81
- package/dist/components/editor/HAccordionAspectRatio.d.ts +0 -14
- package/dist/components/editor/HAccordionAspectRatio.js +0 -102
- package/dist/components/editor/HAccordionColor.d.ts +0 -16
- package/dist/components/editor/HAccordionColor.js +0 -282
- package/dist/components/editor/HAccordionColorAdjustment.d.ts +0 -35
- package/dist/components/editor/HAccordionColorAdjustment.js +0 -31
- package/dist/components/editor/HAccordionDetails.d.ts +0 -12
- package/dist/components/editor/HAccordionDetails.js +0 -157
- package/dist/components/editor/HAccordionLight.d.ts +0 -20
- package/dist/components/editor/HAccordionLight.js +0 -414
- package/dist/components/editor/HAccordionPreset.d.ts +0 -23
- package/dist/components/editor/HAccordionPreset.js +0 -50
- package/dist/components/editor/HAlertBox.d.ts +0 -8
- package/dist/components/editor/HAlertBox.js +0 -55
- package/dist/components/editor/HAspectRatioMobile.d.ts +0 -0
- package/dist/components/editor/HAspectRatioMobile.js +0 -1
- package/dist/components/editor/HBulkAccordionColorAdjustment.d.ts +0 -55
- package/dist/components/editor/HBulkAccordionColorAdjustment.js +0 -31
- package/dist/components/editor/HBulkAccordionColorAdjustmentColors.d.ts +0 -20
- package/dist/components/editor/HBulkAccordionColorAdjustmentColors.js +0 -121
- package/dist/components/editor/HBulkAccordionColorAdjustmentDetails.d.ts +0 -12
- package/dist/components/editor/HBulkAccordionColorAdjustmentDetails.js +0 -65
- package/dist/components/editor/HBulkAccordionColorAdjustmentLight.d.ts +0 -28
- package/dist/components/editor/HBulkAccordionColorAdjustmentLight.js +0 -177
- package/dist/components/editor/HBulkColorAdjustmentMobile.d.ts +0 -53
- package/dist/components/editor/HBulkColorAdjustmentMobile.js +0 -16
- package/dist/components/editor/HBulkColorMobile.d.ts +0 -20
- package/dist/components/editor/HBulkColorMobile.js +0 -121
- package/dist/components/editor/HBulkDetailsMobile.d.ts +0 -12
- package/dist/components/editor/HBulkDetailsMobile.js +0 -65
- package/dist/components/editor/HBulkLightMobile.d.ts +0 -28
- package/dist/components/editor/HBulkLightMobile.js +0 -192
- package/dist/components/editor/HBulkPreset.d.ts +0 -24
- package/dist/components/editor/HBulkPreset.js +0 -43
- package/dist/components/editor/HBulkPresetMobile.d.ts +0 -15
- package/dist/components/editor/HBulkPresetMobile.js +0 -26
- package/dist/components/editor/HDialogBox.d.ts +0 -18
- package/dist/components/editor/HDialogBox.js +0 -51
- package/dist/components/editor/HDialogCopy.d.ts +0 -40
- package/dist/components/editor/HDialogCopy.js +0 -80
- package/dist/components/editor/HFooter.d.ts +0 -12
- package/dist/components/editor/HFooter.js +0 -24
- package/dist/components/editor/HHeaderEditor.d.ts +0 -17
- package/dist/components/editor/HHeaderEditor.js +0 -36
- package/dist/components/editor/HImageEditorBulkDekstop.d.ts +0 -15
- package/dist/components/editor/HImageEditorBulkDekstop.js +0 -29
- package/dist/components/editor/HImageEditorBulkMobile.d.ts +0 -72
- package/dist/components/editor/HImageEditorBulkMobile.js +0 -81
- package/dist/components/editor/HImageEditorDekstop.d.ts +0 -15
- package/dist/components/editor/HImageEditorDekstop.js +0 -29
- package/dist/components/editor/HImageEditorMobile.d.ts +0 -51
- package/dist/components/editor/HImageEditorMobile.js +0 -92
- package/dist/components/editor/HImageEditorMobileLayout.d.ts +0 -14
- package/dist/components/editor/HImageEditorMobileLayout.js +0 -58
- package/dist/components/editor/HModalEditorDekstop.d.ts +0 -13
- package/dist/components/editor/HModalEditorDekstop.js +0 -22
- package/dist/components/editor/HModalMobile.d.ts +0 -13
- package/dist/components/editor/HModalMobile.js +0 -7
- package/dist/components/editor/HPresetDelete.d.ts +0 -7
- package/dist/components/editor/HPresetDelete.js +0 -7
- package/dist/components/editor/HPresetOptionMenu.d.ts +0 -9
- package/dist/components/editor/HPresetOptionMenu.js +0 -20
- package/dist/components/editor/HSliderColorMobile.d.ts +0 -16
- package/dist/components/editor/HSliderColorMobile.js +0 -270
- package/dist/components/editor/HSliderDetailsMobile.d.ts +0 -12
- package/dist/components/editor/HSliderDetailsMobile.js +0 -154
- package/dist/components/editor/HSliderLightMobile.d.ts +0 -20
- package/dist/components/editor/HSliderLightMobile.js +0 -420
- package/dist/components/editor/HTabAspectRatioMobile.d.ts +0 -0
- package/dist/components/editor/HTabAspectRatioMobile.js +0 -1
- package/dist/components/editor/HTabColorAdjustmentMobile.d.ts +0 -33
- package/dist/components/editor/HTabColorAdjustmentMobile.js +0 -16
- package/dist/components/editor/HTabPresetMobile.d.ts +0 -14
- package/dist/components/editor/HTabPresetMobile.js +0 -10
- package/dist/components/editor/HTextField.d.ts +0 -14
- package/dist/components/editor/HTextField.js +0 -51
- package/dist/components/editor/HWatermarkView.d.ts +0 -6
- package/dist/components/editor/HWatermarkView.js +0 -16
- package/dist/components/editor/svg/Tick.d.ts +0 -2
- package/dist/components/editor/svg/Tick.js +0 -6
- package/dist/components/modal/HModalDialog.d.ts +0 -12
- package/dist/components/modal/HModalDialog.js +0 -18
- package/dist/components/modal/HModalRename.d.ts +0 -14
- package/dist/components/modal/HModalRename.js +0 -35
- package/dist/hooks/demo/HonchoEditorBulkDemo.d.ts +0 -3
- package/dist/hooks/demo/HonchoEditorBulkDemo.js +0 -410
- package/dist/hooks/demo/HonchoEditorSingleCleanDemo.d.ts +0 -3
- package/dist/hooks/demo/HonchoEditorSingleCleanDemo.js +0 -354
- package/dist/hooks/demo/index.d.ts +0 -2
- package/dist/hooks/demo/index.js +0 -2
- package/dist/hooks/editor/type.d.ts +0 -174
- package/dist/hooks/editor/type.js +0 -1
- package/dist/hooks/editor/useHonchoEditorBulk.d.ts +0 -96
- package/dist/hooks/editor/useHonchoEditorBulk.js +0 -427
- package/dist/hooks/editor/useHonchoEditorSingle.d.ts +0 -44
- package/dist/hooks/editor/useHonchoEditorSingle.js +0 -162
- package/dist/hooks/useAdjustmentHistory.d.ts +0 -97
- package/dist/hooks/useAdjustmentHistory.js +0 -493
- package/dist/hooks/useAdjustmentHistoryBatch.d.ts +0 -177
- package/dist/hooks/useAdjustmentHistoryBatch.js +0 -1189
- package/dist/hooks/useGallerySwipe.d.ts +0 -36
- package/dist/hooks/useGallerySwipe.js +0 -344
- package/dist/hooks/usePaging.d.ts +0 -89
- package/dist/hooks/usePaging.js +0 -211
- package/dist/hooks/usePreset.d.ts +0 -82
- package/dist/hooks/usePreset.js +0 -344
- package/dist/index.d.ts +0 -41
- package/dist/index.js +0 -44
- package/dist/lib/context/EditorContext.d.ts +0 -28
- package/dist/lib/context/EditorContext.js +0 -60
- package/dist/lib/context/EditorProcessingService.d.ts +0 -36
- package/dist/lib/context/EditorProcessingService.js +0 -249
- package/dist/lib/editor/honcho-editor.d.ts +0 -324
- package/dist/lib/editor/honcho-editor.js +0 -825
- package/dist/lib/hooks/useEditor.d.ts +0 -22
- package/dist/lib/hooks/useEditor.js +0 -35
- package/dist/lib/hooks/useEditorHeadless.d.ts +0 -34
- package/dist/lib/hooks/useEditorHeadless.js +0 -207
- package/dist/lib/hooks/useImageProcessor.d.ts +0 -18
- package/dist/lib/hooks/useImageProcessor.js +0 -113
- package/dist/setupTests.d.ts +0 -1
- package/dist/setupTests.js +0 -1
- package/dist/themes/colors.d.ts +0 -12
- package/dist/themes/colors.js +0 -12
- package/dist/themes/honchoTheme.d.ts +0 -25
- package/dist/themes/honchoTheme.js +0 -94
- package/dist/utils/adjustment.d.ts +0 -6
- package/dist/utils/adjustment.js +0 -48
- package/dist/utils/imageLoader.d.ts +0 -11
- package/dist/utils/imageLoader.js +0 -48
- package/dist/utils/isMobile.d.ts +0 -1
- package/dist/utils/isMobile.js +0 -5
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { Controller } from "./editor/type";
|
|
2
|
-
import { Gallery } from "./editor/type";
|
|
3
|
-
/**
|
|
4
|
-
* Return type for the useGallerySwipe hook
|
|
5
|
-
* Provides image navigation functionality with pagination support
|
|
6
|
-
*/
|
|
7
|
-
interface UseGallerySwipeReturn {
|
|
8
|
-
/** Current image data object containing all image information */
|
|
9
|
-
currentImageData: Gallery | null;
|
|
10
|
-
/** Whether next image navigation is available (considers pagination) */
|
|
11
|
-
isNextAvailable: boolean;
|
|
12
|
-
/** Whether previous image navigation is available */
|
|
13
|
-
isPrevAvailable: boolean;
|
|
14
|
-
/** Function to navigate to the next image (async due to potential API calls) */
|
|
15
|
-
onSwipeNext: () => Promise<void>;
|
|
16
|
-
/** Function to navigate to the previous image (async due to potential API calls) */
|
|
17
|
-
onSwipePrev: () => Promise<void>;
|
|
18
|
-
/** Loading state during image transitions and API calls */
|
|
19
|
-
isLoading: boolean;
|
|
20
|
-
/** Error message if any operation fails */
|
|
21
|
-
error: string | null;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Custom hook for handling image gallery navigation with automatic pagination
|
|
25
|
-
*
|
|
26
|
-
* This hook manages image swipe/navigation functionality across a paginated gallery.
|
|
27
|
-
* It handles the complexity of finding images across multiple pages and loading
|
|
28
|
-
* additional pages as needed during navigation.
|
|
29
|
-
*
|
|
30
|
-
* @param firebaseUid - User's Firebase UID (can be null during initialization)
|
|
31
|
-
* @param initImageId - Initial image ID to start with (can be null during initialization)
|
|
32
|
-
* @param controller - Controller instance for API calls (can be null during initialization)
|
|
33
|
-
* @returns Object containing current image data and navigation functions
|
|
34
|
-
*/
|
|
35
|
-
export declare function useGallerySwipe(firebaseUid: string | null, initImageId: string | null, controller: Controller | null): UseGallerySwipeReturn;
|
|
36
|
-
export {};
|
|
@@ -1,344 +0,0 @@
|
|
|
1
|
-
import { useState, useEffect, useCallback, useRef } from "react";
|
|
2
|
-
/**
|
|
3
|
-
* Custom hook for handling image gallery navigation with automatic pagination
|
|
4
|
-
*
|
|
5
|
-
* This hook manages image swipe/navigation functionality across a paginated gallery.
|
|
6
|
-
* It handles the complexity of finding images across multiple pages and loading
|
|
7
|
-
* additional pages as needed during navigation.
|
|
8
|
-
*
|
|
9
|
-
* @param firebaseUid - User's Firebase UID (can be null during initialization)
|
|
10
|
-
* @param initImageId - Initial image ID to start with (can be null during initialization)
|
|
11
|
-
* @param controller - Controller instance for API calls (can be null during initialization)
|
|
12
|
-
* @returns Object containing current image data and navigation functions
|
|
13
|
-
*/
|
|
14
|
-
export function useGallerySwipe(firebaseUid, initImageId, controller) {
|
|
15
|
-
// Core state for current image and navigation
|
|
16
|
-
const [currentImageId, setCurrentImageId] = useState(initImageId);
|
|
17
|
-
const [currentImageData, setCurrentImageData] = useState(null);
|
|
18
|
-
const [currentEventId, setCurrentEventId] = useState(null);
|
|
19
|
-
// Pagination and image list state
|
|
20
|
-
const [currentImageList, setCurrentImageList] = useState([]);
|
|
21
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
22
|
-
const [hasNextPage, setHasNextPage] = useState(false);
|
|
23
|
-
// UI state management
|
|
24
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
25
|
-
const [error, setError] = useState(null);
|
|
26
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
27
|
-
// Refs to track parameter changes and avoid unnecessary re-initialization
|
|
28
|
-
// This prevents the hook from re-initializing when the same values are passed
|
|
29
|
-
const prevFirebaseUid = useRef(null);
|
|
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
|
-
/**
|
|
41
|
-
* Fetch image pages sequentially until the target image is found
|
|
42
|
-
* This is necessary because we don't know which page contains the initial image
|
|
43
|
-
*
|
|
44
|
-
* @param imageId - The target image ID to find
|
|
45
|
-
* @param eventId - The event ID to search within
|
|
46
|
-
* @returns Array of all gallery images up to and including the page containing the target image
|
|
47
|
-
*/
|
|
48
|
-
const getImageListUntilFound = useCallback(async (imageId, eventId) => {
|
|
49
|
-
let page = 1;
|
|
50
|
-
let allImages = [];
|
|
51
|
-
let isFound = false;
|
|
52
|
-
// Search through pages until we find the target image or reach safety limit
|
|
53
|
-
while (!isFound && page <= 100) { // Safety limit to prevent infinite loop
|
|
54
|
-
try {
|
|
55
|
-
const response = await controller.getImageList(firebaseUid, eventId, page);
|
|
56
|
-
if (response.gallery && response.gallery.length > 0) {
|
|
57
|
-
// Accumulate all images from previous pages
|
|
58
|
-
allImages = [...allImages, ...response.gallery];
|
|
59
|
-
// Check if target image is found in current page
|
|
60
|
-
isFound = response.gallery.some(img => img.id === imageId);
|
|
61
|
-
if (isFound) {
|
|
62
|
-
// Update pagination state when target is found
|
|
63
|
-
setCurrentPage(page);
|
|
64
|
-
setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
|
|
65
|
-
break;
|
|
66
|
-
}
|
|
67
|
-
// If no next page exists, stop searching
|
|
68
|
-
if (response.next_page === 0 || response.next_page <= response.current_page) {
|
|
69
|
-
break;
|
|
70
|
-
}
|
|
71
|
-
page++;
|
|
72
|
-
}
|
|
73
|
-
else {
|
|
74
|
-
// Empty response, stop searching
|
|
75
|
-
break;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
catch (err) {
|
|
79
|
-
console.error(`Error fetching page ${page}:`, err);
|
|
80
|
-
break;
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
return allImages;
|
|
84
|
-
}, [controller, firebaseUid]);
|
|
85
|
-
/**
|
|
86
|
-
* Load the next page of images when user reaches the end of current list
|
|
87
|
-
* This enables seamless navigation across page boundaries
|
|
88
|
-
*
|
|
89
|
-
* @returns Array of new images from the next page, or empty array if no more pages
|
|
90
|
-
*/
|
|
91
|
-
const loadNextPage = useCallback(async () => {
|
|
92
|
-
// Check prerequisites before attempting to load next page
|
|
93
|
-
if (!hasNextPage || !currentEventId || !controller || !firebaseUid) {
|
|
94
|
-
return [];
|
|
95
|
-
}
|
|
96
|
-
try {
|
|
97
|
-
const nextPageNum = currentPage + 1;
|
|
98
|
-
const response = await controller.getImageList(firebaseUid, currentEventId, nextPageNum);
|
|
99
|
-
if (response.gallery && response.gallery.length > 0) {
|
|
100
|
-
// Update pagination state with new page information
|
|
101
|
-
setCurrentPage(nextPageNum);
|
|
102
|
-
setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
|
|
103
|
-
return response.gallery;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
catch (err) {
|
|
107
|
-
console.error('Error loading next page:', err);
|
|
108
|
-
}
|
|
109
|
-
return [];
|
|
110
|
-
}, [hasNextPage, currentEventId, controller, firebaseUid, currentPage]);
|
|
111
|
-
/**
|
|
112
|
-
* Initialize or re-initialize the gallery when parameters change
|
|
113
|
-
* This function:
|
|
114
|
-
* 1. Fetches initial image data
|
|
115
|
-
* 2. Discovers the event ID from the image
|
|
116
|
-
* 3. Loads all image pages until the initial image is found
|
|
117
|
-
* 4. Sets up pagination state
|
|
118
|
-
*
|
|
119
|
-
* Only re-initializes when parameters actually change to avoid unnecessary API calls
|
|
120
|
-
*/
|
|
121
|
-
const initializeGallery = useCallback(async () => {
|
|
122
|
-
// Early return if required parameters are missing
|
|
123
|
-
if (!firebaseUid || !initImageId || !controller) {
|
|
124
|
-
setCurrentImageData(null);
|
|
125
|
-
setCurrentImageList([]);
|
|
126
|
-
setIsInitialized(false);
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
129
|
-
// Check if re-initialization is needed by comparing with previous values
|
|
130
|
-
const needsReinit = prevFirebaseUid.current !== firebaseUid ||
|
|
131
|
-
prevInitImageId.current !== initImageId ||
|
|
132
|
-
!isInitialized;
|
|
133
|
-
if (!needsReinit)
|
|
134
|
-
return;
|
|
135
|
-
setIsLoading(true);
|
|
136
|
-
setError(null);
|
|
137
|
-
try {
|
|
138
|
-
// Step 1: Get initial image data to discover event ID
|
|
139
|
-
const gallery = await controller.onGetImage(firebaseUid, initImageId);
|
|
140
|
-
if (!gallery) {
|
|
141
|
-
throw new Error('Failed to fetch initial image data');
|
|
142
|
-
}
|
|
143
|
-
// Step 2: Set up initial state with discovered data
|
|
144
|
-
setCurrentImageData(gallery);
|
|
145
|
-
setCurrentImageId(initImageId);
|
|
146
|
-
setCurrentEventId(gallery.event_id);
|
|
147
|
-
// Step 3: Get complete image list by searching through pages
|
|
148
|
-
// This ensures we have navigation context for the current image
|
|
149
|
-
const allImages = await getImageListUntilFound(initImageId, gallery.event_id);
|
|
150
|
-
console.log("Print all images Id: ", allImages.map(image => image.id).join(', '));
|
|
151
|
-
setCurrentImageList(allImages);
|
|
152
|
-
// Step 4: Update tracking refs to prevent unnecessary re-initialization
|
|
153
|
-
prevFirebaseUid.current = firebaseUid;
|
|
154
|
-
prevInitImageId.current = initImageId;
|
|
155
|
-
setIsInitialized(true);
|
|
156
|
-
}
|
|
157
|
-
catch (err) {
|
|
158
|
-
const errorMessage = err instanceof Error ? err.message : 'Unknown error occurred';
|
|
159
|
-
setError(errorMessage);
|
|
160
|
-
console.error('Error initializing gallery:', err);
|
|
161
|
-
}
|
|
162
|
-
finally {
|
|
163
|
-
setIsLoading(false);
|
|
164
|
-
}
|
|
165
|
-
}, [firebaseUid, initImageId, controller, getImageListUntilFound, isInitialized]);
|
|
166
|
-
/**
|
|
167
|
-
* Navigate to the next image in the gallery
|
|
168
|
-
* Handles two scenarios:
|
|
169
|
-
* 1. Next image exists in current loaded list - navigate directly
|
|
170
|
-
* 2. At end of current list - load next page and navigate to first image of new page
|
|
171
|
-
*
|
|
172
|
-
* @returns Promise that resolves when navigation is complete
|
|
173
|
-
*/
|
|
174
|
-
const onSwipeNext = useCallback(async () => {
|
|
175
|
-
// Prevent action if no current image or already loading
|
|
176
|
-
if (!currentImageId || isLoading)
|
|
177
|
-
return;
|
|
178
|
-
setIsLoading(true);
|
|
179
|
-
setError(null);
|
|
180
|
-
try {
|
|
181
|
-
// Debug logging
|
|
182
|
-
console.log("=== SWIPE NEXT DEBUG ===");
|
|
183
|
-
console.log("currentImageId:", currentImageId);
|
|
184
|
-
console.log("currentImageList length:", currentImageList.length);
|
|
185
|
-
console.log("currentImageList IDs:", currentImageList.map(img => img.id).join(", "));
|
|
186
|
-
// Calculate current index
|
|
187
|
-
const currentIndex = getCurrentImageIndex();
|
|
188
|
-
console.log("Current index: ", currentIndex);
|
|
189
|
-
if (currentIndex === -1) {
|
|
190
|
-
throw new Error('Current image not found in list');
|
|
191
|
-
}
|
|
192
|
-
// Scenario 1: At the last image of current list
|
|
193
|
-
if (currentIndex === currentImageList.length - 1) {
|
|
194
|
-
console.log("[SCENARIO 1] if last image: " + currentImageList.length);
|
|
195
|
-
// Try to load next page for more images
|
|
196
|
-
const newImages = await loadNextPage();
|
|
197
|
-
if (newImages.length > 0) {
|
|
198
|
-
// Extend current list with new images
|
|
199
|
-
const updatedList = [...currentImageList, ...newImages];
|
|
200
|
-
setCurrentImageList(updatedList);
|
|
201
|
-
// Navigate to first image of the new page
|
|
202
|
-
const nextImage = newImages[0];
|
|
203
|
-
console.log("Setting currentImageId to:", nextImage.id);
|
|
204
|
-
setCurrentImageId(nextImage.id);
|
|
205
|
-
// Fetch complete data for the new current image
|
|
206
|
-
const nextImageData = await controller.onGetImage(firebaseUid, nextImage.id);
|
|
207
|
-
if (nextImageData) {
|
|
208
|
-
setCurrentImageData(nextImageData);
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
else {
|
|
212
|
-
// No more pages available - end of gallery reached
|
|
213
|
-
setError('No more images available');
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
else {
|
|
217
|
-
// Scenario 2: Navigate to next image in current list
|
|
218
|
-
const nextImage = currentImageList[currentIndex + 1];
|
|
219
|
-
console.log("[SCENARIO 2] Navigating to next image:", nextImage.id);
|
|
220
|
-
console.log("Setting currentImageId from", currentImageId, "to", nextImage.id);
|
|
221
|
-
setCurrentImageId(nextImage.id);
|
|
222
|
-
// Fetch complete data for the next image
|
|
223
|
-
const nextImageData = await controller.onGetImage(firebaseUid, nextImage.id);
|
|
224
|
-
if (nextImageData) {
|
|
225
|
-
setCurrentImageData(nextImageData);
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
catch (err) {
|
|
230
|
-
const errorMessage = err instanceof Error ? err.message : 'Error moving to next image';
|
|
231
|
-
setError(errorMessage);
|
|
232
|
-
console.error('Error in onSwipeNext:', err);
|
|
233
|
-
}
|
|
234
|
-
finally {
|
|
235
|
-
setIsLoading(false);
|
|
236
|
-
}
|
|
237
|
-
}, [currentImageId, isLoading, getCurrentImageIndex, currentImageList, loadNextPage, controller, firebaseUid]);
|
|
238
|
-
/**
|
|
239
|
-
* Navigate to the previous image in the gallery
|
|
240
|
-
* Only works within the currently loaded image list
|
|
241
|
-
* (Previous pages are not loaded on-demand for backward navigation)
|
|
242
|
-
*
|
|
243
|
-
* @returns Promise that resolves when navigation is complete
|
|
244
|
-
*/
|
|
245
|
-
const onSwipePrev = useCallback(async () => {
|
|
246
|
-
// Prevent action if no current image or already loading
|
|
247
|
-
if (!currentImageId || isLoading)
|
|
248
|
-
return;
|
|
249
|
-
setIsLoading(true);
|
|
250
|
-
setError(null);
|
|
251
|
-
try {
|
|
252
|
-
// Calculate current index
|
|
253
|
-
const currentIndex = getCurrentImageIndex();
|
|
254
|
-
if (currentIndex === -1) {
|
|
255
|
-
throw new Error('Current image not found in list');
|
|
256
|
-
}
|
|
257
|
-
if (currentIndex > 0) {
|
|
258
|
-
// Navigate to previous image in the current list
|
|
259
|
-
const prevImage = currentImageList[currentIndex - 1];
|
|
260
|
-
setCurrentImageId(prevImage.id);
|
|
261
|
-
// Fetch complete data for the previous image
|
|
262
|
-
const prevImageData = await controller.onGetImage(firebaseUid, prevImage.id);
|
|
263
|
-
if (prevImageData) {
|
|
264
|
-
setCurrentImageData(prevImageData);
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
else {
|
|
268
|
-
// Already at the first image of loaded list
|
|
269
|
-
setError('Already at the first image');
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
catch (err) {
|
|
273
|
-
const errorMessage = err instanceof Error ? err.message : 'Error moving to previous image';
|
|
274
|
-
setError(errorMessage);
|
|
275
|
-
console.error('Error in onSwipePrev:', err);
|
|
276
|
-
}
|
|
277
|
-
finally {
|
|
278
|
-
setIsLoading(false);
|
|
279
|
-
}
|
|
280
|
-
}, [currentImageId, isLoading, getCurrentImageIndex, currentImageList, controller, firebaseUid]);
|
|
281
|
-
/**
|
|
282
|
-
* Calculate if next image navigation is available
|
|
283
|
-
* Returns true if:
|
|
284
|
-
* 1. There's a next image in the current loaded list, OR
|
|
285
|
-
* 2. We're at the end of current list but more pages are available
|
|
286
|
-
*
|
|
287
|
-
* @returns Boolean indicating if next navigation is possible
|
|
288
|
-
*/
|
|
289
|
-
const isNextAvailable = useCallback(() => {
|
|
290
|
-
if (isLoading || !currentImageId)
|
|
291
|
-
return false;
|
|
292
|
-
// Calculate current index
|
|
293
|
-
const currentIndex = getCurrentImageIndex();
|
|
294
|
-
if (currentIndex === -1)
|
|
295
|
-
return false;
|
|
296
|
-
// If we're not at the last image, next is definitely available
|
|
297
|
-
if (currentIndex < currentImageList.length - 1)
|
|
298
|
-
return true;
|
|
299
|
-
// If we're at the last image but there are more pages, next is still available
|
|
300
|
-
return hasNextPage;
|
|
301
|
-
}, [isLoading, getCurrentImageIndex, currentImageList.length, hasNextPage]);
|
|
302
|
-
/**
|
|
303
|
-
* Calculate if previous image navigation is available
|
|
304
|
-
* Returns true if there's a previous image in the currently loaded list
|
|
305
|
-
*
|
|
306
|
-
* @returns Boolean indicating if previous navigation is possible
|
|
307
|
-
*/
|
|
308
|
-
const isPrevAvailable = useCallback(() => {
|
|
309
|
-
if (isLoading || !currentImageId)
|
|
310
|
-
return false;
|
|
311
|
-
// Calculate current index
|
|
312
|
-
const currentIndex = getCurrentImageIndex();
|
|
313
|
-
return currentIndex > 0;
|
|
314
|
-
}, [isLoading, getCurrentImageIndex]);
|
|
315
|
-
// Initialize when dependencies change
|
|
316
|
-
useEffect(() => {
|
|
317
|
-
initializeGallery();
|
|
318
|
-
}, [initializeGallery]);
|
|
319
|
-
// Update currentImageId when initImageId changes from external source
|
|
320
|
-
// This allows the hook to respond to external changes to the initial image ID
|
|
321
|
-
// but should not interfere with internal navigation
|
|
322
|
-
useEffect(() => {
|
|
323
|
-
// Only update if initImageId actually changed and we're not currently loading
|
|
324
|
-
// (loading indicates we're in the middle of navigation)
|
|
325
|
-
if (initImageId && initImageId !== currentImageId && !isLoading) {
|
|
326
|
-
// Additional check: only update if this is truly an external change
|
|
327
|
-
// If prevInitImageId is different from initImageId, it's an external change
|
|
328
|
-
if (prevInitImageId.current !== initImageId) {
|
|
329
|
-
console.log("External initImageId change detected, updating currentImageId");
|
|
330
|
-
setCurrentImageId(initImageId);
|
|
331
|
-
}
|
|
332
|
-
}
|
|
333
|
-
}, [initImageId]);
|
|
334
|
-
// Return all the functionality and state that components need
|
|
335
|
-
return {
|
|
336
|
-
currentImageData,
|
|
337
|
-
isNextAvailable: isNextAvailable(),
|
|
338
|
-
isPrevAvailable: isPrevAvailable(),
|
|
339
|
-
onSwipeNext,
|
|
340
|
-
onSwipePrev,
|
|
341
|
-
isLoading,
|
|
342
|
-
error
|
|
343
|
-
};
|
|
344
|
-
}
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import { Gallery } from './editor/type';
|
|
2
|
-
import { Controller } from "./editor/type";
|
|
3
|
-
/**
|
|
4
|
-
* Configuration options for the paging hook
|
|
5
|
-
*/
|
|
6
|
-
export interface PagingOptions {
|
|
7
|
-
/** Enable development warnings for debugging */
|
|
8
|
-
devWarnings?: boolean;
|
|
9
|
-
/** Auto-load first page on hook initialization */
|
|
10
|
-
autoLoad?: boolean;
|
|
11
|
-
/** Reset pagination when dependencies change */
|
|
12
|
-
autoReset?: boolean;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Information about the current paging state
|
|
16
|
-
*/
|
|
17
|
-
export interface PagingInfo {
|
|
18
|
-
/** Whether images are currently being loaded */
|
|
19
|
-
isLoading: boolean;
|
|
20
|
-
/** Whether more pages are being loaded */
|
|
21
|
-
isLoadingMore: boolean;
|
|
22
|
-
/** Error message if any operation failed */
|
|
23
|
-
error: string | null;
|
|
24
|
-
/** Current page number */
|
|
25
|
-
currentPage: number;
|
|
26
|
-
/** Whether there are more pages to load */
|
|
27
|
-
hasMore: boolean;
|
|
28
|
-
/** Total number of images loaded */
|
|
29
|
-
totalImages: number;
|
|
30
|
-
/** Whether the hook has been initialized */
|
|
31
|
-
isInitialized: boolean;
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Actions available for paging management
|
|
35
|
-
*/
|
|
36
|
-
export interface PagingActions {
|
|
37
|
-
/** Load more images (next page) - only one instance can run at a time */
|
|
38
|
-
loadMore: () => Promise<void>;
|
|
39
|
-
/** Refresh/reload from first page */
|
|
40
|
-
refresh: () => Promise<void>;
|
|
41
|
-
/** Reset pagination state */
|
|
42
|
-
reset: () => void;
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Return type for the usePaging hook
|
|
46
|
-
*/
|
|
47
|
-
export interface UsePagingReturn {
|
|
48
|
-
/** Current list of images */
|
|
49
|
-
images: Gallery[];
|
|
50
|
-
/** Information about paging state */
|
|
51
|
-
info: PagingInfo;
|
|
52
|
-
/** Available paging actions */
|
|
53
|
-
actions: PagingActions;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Hook for managing paginated image loading with ControllerBulk.
|
|
57
|
-
*
|
|
58
|
-
* **Key Features:**
|
|
59
|
-
* - **Paginated Loading**: Handles page-by-page image loading
|
|
60
|
-
* - **State Management**: Maintains image list and pagination state
|
|
61
|
-
* - **Load More**: Seamlessly loads and appends next pages
|
|
62
|
-
* - **Mutation**: Update specific images without full reload
|
|
63
|
-
* - **Error Handling**: Provides error states for failed operations
|
|
64
|
-
* - **Auto-loading**: Optional automatic first page loading
|
|
65
|
-
*
|
|
66
|
-
* **Typical Usage:**
|
|
67
|
-
* ```typescript
|
|
68
|
-
* const { images, info, actions } = usePaging(controller, firebaseUid, eventId, {
|
|
69
|
-
* autoLoad: true,
|
|
70
|
-
* autoReset: true
|
|
71
|
-
* });
|
|
72
|
-
*
|
|
73
|
-
* // Load more images
|
|
74
|
-
* await actions.loadMore();
|
|
75
|
-
*
|
|
76
|
-
* // Refresh from beginning
|
|
77
|
-
* await actions.refresh();
|
|
78
|
-
*
|
|
79
|
-
* // Update specific image
|
|
80
|
-
* actions.mutateImage(imageId, (img) => ({ ...img, isSelected: true }));
|
|
81
|
-
* ```
|
|
82
|
-
*
|
|
83
|
-
* @param controller - Backend controller for API communication
|
|
84
|
-
* @param firebaseUid - User identifier for backend operations
|
|
85
|
-
* @param eventId - Event identifier for image list
|
|
86
|
-
* @param options - Configuration options
|
|
87
|
-
* @returns Object with images, info, and actions
|
|
88
|
-
*/
|
|
89
|
-
export declare function usePaging(controller: Controller | null, firebaseUid: string, eventId: string, options?: PagingOptions): UsePagingReturn;
|
package/dist/hooks/usePaging.js
DELETED
|
@@ -1,211 +0,0 @@
|
|
|
1
|
-
import { useState, useCallback, useEffect, useRef, useMemo } from 'react';
|
|
2
|
-
/**
|
|
3
|
-
* Hook for managing paginated image loading with ControllerBulk.
|
|
4
|
-
*
|
|
5
|
-
* **Key Features:**
|
|
6
|
-
* - **Paginated Loading**: Handles page-by-page image loading
|
|
7
|
-
* - **State Management**: Maintains image list and pagination state
|
|
8
|
-
* - **Load More**: Seamlessly loads and appends next pages
|
|
9
|
-
* - **Mutation**: Update specific images without full reload
|
|
10
|
-
* - **Error Handling**: Provides error states for failed operations
|
|
11
|
-
* - **Auto-loading**: Optional automatic first page loading
|
|
12
|
-
*
|
|
13
|
-
* **Typical Usage:**
|
|
14
|
-
* ```typescript
|
|
15
|
-
* const { images, info, actions } = usePaging(controller, firebaseUid, eventId, {
|
|
16
|
-
* autoLoad: true,
|
|
17
|
-
* autoReset: true
|
|
18
|
-
* });
|
|
19
|
-
*
|
|
20
|
-
* // Load more images
|
|
21
|
-
* await actions.loadMore();
|
|
22
|
-
*
|
|
23
|
-
* // Refresh from beginning
|
|
24
|
-
* await actions.refresh();
|
|
25
|
-
*
|
|
26
|
-
* // Update specific image
|
|
27
|
-
* actions.mutateImage(imageId, (img) => ({ ...img, isSelected: true }));
|
|
28
|
-
* ```
|
|
29
|
-
*
|
|
30
|
-
* @param controller - Backend controller for API communication
|
|
31
|
-
* @param firebaseUid - User identifier for backend operations
|
|
32
|
-
* @param eventId - Event identifier for image list
|
|
33
|
-
* @param options - Configuration options
|
|
34
|
-
* @returns Object with images, info, and actions
|
|
35
|
-
*/
|
|
36
|
-
export function usePaging(controller, firebaseUid, eventId, options = {}) {
|
|
37
|
-
// Memoize options to prevent re-renders when object is recreated with same values
|
|
38
|
-
const memoizedOptions = useMemo(() => ({
|
|
39
|
-
devWarnings: options.devWarnings ?? false,
|
|
40
|
-
autoLoad: options.autoLoad ?? false,
|
|
41
|
-
autoReset: options.autoReset ?? true
|
|
42
|
-
}), [options.devWarnings, options.autoLoad, options.autoReset]);
|
|
43
|
-
// Core state
|
|
44
|
-
const [images, setImages] = useState([]);
|
|
45
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
46
|
-
const [isLoadingMore, setIsLoadingMore] = useState(false);
|
|
47
|
-
const [error, setError] = useState(null);
|
|
48
|
-
const [currentPage, setCurrentPage] = useState(1);
|
|
49
|
-
const [hasMore, setHasMore] = useState(true);
|
|
50
|
-
const [isInitialized, setIsInitialized] = useState(false);
|
|
51
|
-
// Track if loadMore is currently running to prevent spam
|
|
52
|
-
const isLoadMoreRunningRef = useRef(false);
|
|
53
|
-
// Track dependencies with stable refs
|
|
54
|
-
const controllerRef = useRef(controller);
|
|
55
|
-
const firebaseUidRef = useRef(firebaseUid);
|
|
56
|
-
const eventIdRef = useRef(eventId);
|
|
57
|
-
// Only update refs when values actually change
|
|
58
|
-
if (controllerRef.current !== controller) {
|
|
59
|
-
controllerRef.current = controller;
|
|
60
|
-
}
|
|
61
|
-
if (firebaseUidRef.current !== firebaseUid) {
|
|
62
|
-
firebaseUidRef.current = firebaseUid;
|
|
63
|
-
}
|
|
64
|
-
if (eventIdRef.current !== eventId) {
|
|
65
|
-
eventIdRef.current = eventId;
|
|
66
|
-
}
|
|
67
|
-
// Helper function to log debug messages
|
|
68
|
-
const debugLog = useCallback((message, data) => {
|
|
69
|
-
if (memoizedOptions.devWarnings) {
|
|
70
|
-
console.log(`[usePaging] ${message}`, data || '');
|
|
71
|
-
}
|
|
72
|
-
}, [memoizedOptions.devWarnings]);
|
|
73
|
-
// Helper function to handle errors
|
|
74
|
-
const handleError = useCallback((operation, error) => {
|
|
75
|
-
const errorMessage = `Failed to ${operation}: ${error instanceof Error ? error.message : String(error)}`;
|
|
76
|
-
setError(errorMessage);
|
|
77
|
-
debugLog(`Error in ${operation}`, error);
|
|
78
|
-
}, [debugLog]);
|
|
79
|
-
// Load images for a specific page
|
|
80
|
-
const loadPage = useCallback(async (pageNum, isLoadMore = false) => {
|
|
81
|
-
if (!controllerRef.current || !firebaseUidRef.current || !eventIdRef.current) {
|
|
82
|
-
debugLog('Load skipped: missing controller, firebaseUid, or eventId');
|
|
83
|
-
return;
|
|
84
|
-
}
|
|
85
|
-
// Set appropriate loading state
|
|
86
|
-
if (isLoadMore) {
|
|
87
|
-
setIsLoadingMore(true);
|
|
88
|
-
}
|
|
89
|
-
else {
|
|
90
|
-
setIsLoading(true);
|
|
91
|
-
}
|
|
92
|
-
setError(null);
|
|
93
|
-
try {
|
|
94
|
-
debugLog(`Loading page ${pageNum}...`, { isLoadMore });
|
|
95
|
-
const response = await controllerRef.current.getImageList(firebaseUidRef.current, eventIdRef.current, pageNum);
|
|
96
|
-
debugLog('Page loaded successfully', {
|
|
97
|
-
page: response.current_page,
|
|
98
|
-
imageCount: response.gallery.length,
|
|
99
|
-
hasNext: response.next_page > 0
|
|
100
|
-
});
|
|
101
|
-
// Update images list
|
|
102
|
-
setImages(prev => {
|
|
103
|
-
if (isLoadMore) {
|
|
104
|
-
// Append new images for load more
|
|
105
|
-
return [...prev, ...response.gallery];
|
|
106
|
-
}
|
|
107
|
-
else {
|
|
108
|
-
// Replace all images for initial load or refresh
|
|
109
|
-
return response.gallery;
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
// Update pagination state
|
|
113
|
-
setCurrentPage(response.current_page);
|
|
114
|
-
setHasMore(response.next_page > 0 && response.gallery.length > 0);
|
|
115
|
-
if (!isInitialized) {
|
|
116
|
-
setIsInitialized(true);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
catch (err) {
|
|
120
|
-
handleError(`load page ${pageNum}`, err);
|
|
121
|
-
// On error, don't change images if it's load more
|
|
122
|
-
if (!isLoadMore) {
|
|
123
|
-
setImages([]);
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
finally {
|
|
127
|
-
if (isLoadMore) {
|
|
128
|
-
setIsLoadingMore(false);
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
setIsLoading(false);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
}, [debugLog, handleError, isInitialized]);
|
|
135
|
-
// Load more images (next page) - spam-protected
|
|
136
|
-
const loadMore = useCallback(async () => {
|
|
137
|
-
// Prevent multiple concurrent loadMore calls
|
|
138
|
-
if (isLoadMoreRunningRef.current || isLoadingMore || !hasMore) {
|
|
139
|
-
debugLog('Load more skipped', {
|
|
140
|
-
isLoadMoreRunning: isLoadMoreRunningRef.current,
|
|
141
|
-
isLoadingMore,
|
|
142
|
-
hasMore
|
|
143
|
-
});
|
|
144
|
-
return;
|
|
145
|
-
}
|
|
146
|
-
// Mark as running to prevent spam
|
|
147
|
-
isLoadMoreRunningRef.current = true;
|
|
148
|
-
try {
|
|
149
|
-
debugLog('Loading more images...', { nextPage: currentPage + 1 });
|
|
150
|
-
await loadPage(currentPage + 1, true);
|
|
151
|
-
}
|
|
152
|
-
finally {
|
|
153
|
-
// Always reset the running flag
|
|
154
|
-
isLoadMoreRunningRef.current = false;
|
|
155
|
-
}
|
|
156
|
-
}, [isLoadingMore, hasMore, currentPage, loadPage, debugLog]);
|
|
157
|
-
// Refresh from first page
|
|
158
|
-
const refresh = useCallback(async () => {
|
|
159
|
-
debugLog('Refreshing from first page...');
|
|
160
|
-
setCurrentPage(1);
|
|
161
|
-
setHasMore(true);
|
|
162
|
-
await loadPage(1, false);
|
|
163
|
-
}, [loadPage, debugLog]);
|
|
164
|
-
// Reset pagination state
|
|
165
|
-
const reset = useCallback(() => {
|
|
166
|
-
debugLog('Resetting pagination state');
|
|
167
|
-
setImages([]);
|
|
168
|
-
setCurrentPage(1);
|
|
169
|
-
setHasMore(true);
|
|
170
|
-
setError(null);
|
|
171
|
-
setIsInitialized(false);
|
|
172
|
-
// Reset loadMore running flag when page changes
|
|
173
|
-
isLoadMoreRunningRef.current = false;
|
|
174
|
-
}, [debugLog]);
|
|
175
|
-
// Auto-load first page on initialization
|
|
176
|
-
useEffect(() => {
|
|
177
|
-
if (memoizedOptions.autoLoad && controller && firebaseUid && eventId && !isInitialized) {
|
|
178
|
-
debugLog('Auto-loading first page...');
|
|
179
|
-
loadPage(1, false);
|
|
180
|
-
}
|
|
181
|
-
}, [memoizedOptions.autoLoad, controller, firebaseUid, eventId, isInitialized, loadPage, debugLog]);
|
|
182
|
-
// Reset when dependencies change (if autoReset is enabled)
|
|
183
|
-
useEffect(() => {
|
|
184
|
-
if (memoizedOptions.autoReset && isInitialized) {
|
|
185
|
-
debugLog('Dependencies changed, resetting state');
|
|
186
|
-
reset();
|
|
187
|
-
}
|
|
188
|
-
}, [controller, firebaseUid, eventId, memoizedOptions.autoReset, isInitialized, reset, debugLog]);
|
|
189
|
-
// Paging info object - memoized to prevent re-renders
|
|
190
|
-
const info = useMemo(() => ({
|
|
191
|
-
isLoading,
|
|
192
|
-
isLoadingMore,
|
|
193
|
-
error,
|
|
194
|
-
currentPage,
|
|
195
|
-
hasMore,
|
|
196
|
-
totalImages: images.length,
|
|
197
|
-
isInitialized
|
|
198
|
-
}), [isLoading, isLoadingMore, error, currentPage, hasMore, images.length, isInitialized]);
|
|
199
|
-
// Actions object - memoized to prevent re-renders
|
|
200
|
-
const actions = useMemo(() => ({
|
|
201
|
-
loadMore,
|
|
202
|
-
refresh,
|
|
203
|
-
reset
|
|
204
|
-
}), [loadMore, refresh, reset]);
|
|
205
|
-
// Return object - memoized to prevent re-renders
|
|
206
|
-
return useMemo(() => ({
|
|
207
|
-
images,
|
|
208
|
-
info,
|
|
209
|
-
actions
|
|
210
|
-
}), [images, info, actions]);
|
|
211
|
-
}
|