@yogiswara/honcho-editor-ui 1.2.3 → 1.2.4
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.
|
@@ -7,13 +7,21 @@ declare global {
|
|
|
7
7
|
}
|
|
8
8
|
export interface Controller {
|
|
9
9
|
onGetImage(firebaseUid: string, imageID: string): Promise<Gallery>;
|
|
10
|
-
getImageList(firebaseUid: string, eventId: string): Promise<
|
|
10
|
+
getImageList(firebaseUid: string, eventId: string, page: number): Promise<ResponseGallery>;
|
|
11
11
|
syncConfig(firebaseUid: string): Promise<void>;
|
|
12
12
|
handleBack(firebaseUid: string, imageID: string): void;
|
|
13
13
|
getPresets(firebaseUid: string): Promise<Preset[]>;
|
|
14
14
|
createPreset(firebaseUid: string, name: string, settings: AdjustmentState): Promise<Preset>;
|
|
15
15
|
deletePreset(firebaseUid: string, presetId: string): Promise<void>;
|
|
16
16
|
}
|
|
17
|
+
export interface ResponseGallery {
|
|
18
|
+
gallery: Gallery[];
|
|
19
|
+
limit: number;
|
|
20
|
+
current_page: number;
|
|
21
|
+
prev_page: number;
|
|
22
|
+
next_page: number;
|
|
23
|
+
sum_of_image?: number;
|
|
24
|
+
}
|
|
17
25
|
export type AdjustmentState = {
|
|
18
26
|
tempScore: number;
|
|
19
27
|
tintScore: number;
|
|
@@ -8,6 +8,9 @@ const initialAdjustments = {
|
|
|
8
8
|
const clamp = (value) => Math.max(-100, Math.min(100, value));
|
|
9
9
|
export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
10
10
|
const [currentImageId, setCurrentImageId] = useState(initImageId);
|
|
11
|
+
const [currentPage, setCurrentPage] = useState(1);
|
|
12
|
+
const [hasNextPage, setHasNextPage] = useState(true);
|
|
13
|
+
const [isFetchingNextPage, setIsFetchingNextPage] = useState(false);
|
|
11
14
|
// MARK: - Core Editor State & Refs
|
|
12
15
|
const editorRef = useRef(null);
|
|
13
16
|
const canvasRef = useRef(null);
|
|
@@ -178,14 +181,16 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
|
178
181
|
try {
|
|
179
182
|
console.log("Hook is fetching image list for event:", eventId);
|
|
180
183
|
// The controller now requires eventId, adjust the interface if needed
|
|
181
|
-
const
|
|
182
|
-
const items =
|
|
184
|
+
const response = await controller.getImageList(firebaseUid, eventId, 1);
|
|
185
|
+
const items = response.gallery.map(g => ({
|
|
183
186
|
id: g.id,
|
|
184
187
|
url: g.raw_edited?.path || g.download?.path || '',
|
|
185
188
|
file: new File([], g.id),
|
|
186
189
|
}));
|
|
187
190
|
setImageList(items);
|
|
188
|
-
|
|
191
|
+
// ✅ SET INITIAL PAGINATION STATE
|
|
192
|
+
setCurrentPage(1);
|
|
193
|
+
setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
|
|
189
194
|
}
|
|
190
195
|
catch (error) {
|
|
191
196
|
console.error("Hook failed to fetch image list:", error);
|
|
@@ -193,7 +198,7 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
|
193
198
|
}
|
|
194
199
|
};
|
|
195
200
|
fetchAndSetImageList();
|
|
196
|
-
}, [controller, firebaseUid, eventId
|
|
201
|
+
}, [controller, firebaseUid, eventId]);
|
|
197
202
|
// Effect for keyboard shortcuts
|
|
198
203
|
useEffect(() => {
|
|
199
204
|
window.addEventListener('keydown', handleKeyDown);
|
|
@@ -322,16 +327,55 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
|
322
327
|
}
|
|
323
328
|
}, [imageList, currentImageId]);
|
|
324
329
|
const handleNext = useCallback(async (firebaseUid) => {
|
|
325
|
-
// Find the current image index
|
|
326
330
|
const currentIndex = imageList.findIndex(img => img.id === currentImageId);
|
|
327
|
-
//
|
|
328
|
-
if (currentIndex
|
|
331
|
+
// Condition 1: We are at the last image of the currently loaded list.
|
|
332
|
+
if (currentIndex === imageList.length - 1) {
|
|
333
|
+
// Condition 2: Check if there's a next page and we aren't already fetching it.
|
|
334
|
+
if (hasNextPage && !isFetchingNextPage) {
|
|
335
|
+
console.log(`At end of list. Fetching next page: ${currentPage + 1}`);
|
|
336
|
+
setIsFetchingNextPage(true); // Prevent multiple fetches
|
|
337
|
+
try {
|
|
338
|
+
// Fetch the next page of images
|
|
339
|
+
const response = await controller.getImageList(firebaseUid, eventId, currentPage + 1);
|
|
340
|
+
// If the API returns new images...
|
|
341
|
+
if (response.gallery && response.gallery.length > 0) {
|
|
342
|
+
const newItems = response.gallery.map(g => ({
|
|
343
|
+
id: g.id,
|
|
344
|
+
url: g.raw_edited?.path || g.download?.path || '',
|
|
345
|
+
file: new File([], g.id),
|
|
346
|
+
}));
|
|
347
|
+
// Append the new images to our existing list
|
|
348
|
+
setImageList(prevList => [...prevList, ...newItems]);
|
|
349
|
+
// Update the pagination state
|
|
350
|
+
setCurrentPage(response.current_page);
|
|
351
|
+
setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
|
|
352
|
+
// IMPORTANT: Set the current image to the first of the NEW images
|
|
353
|
+
setCurrentImageId(newItems[0].id);
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
// No more images left to fetch
|
|
357
|
+
setHasNextPage(false);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
catch (error) {
|
|
361
|
+
console.error("Failed to fetch next page:", error);
|
|
362
|
+
}
|
|
363
|
+
finally {
|
|
364
|
+
setIsFetchingNextPage(false); // Allow fetching again
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
// Condition 3: We are NOT at the end of the list, so just navigate normally.
|
|
368
|
+
}
|
|
369
|
+
else if (currentIndex !== -1) {
|
|
329
370
|
const nextImageId = imageList[currentIndex + 1]?.id;
|
|
330
371
|
if (nextImageId) {
|
|
331
372
|
setCurrentImageId(nextImageId);
|
|
332
373
|
}
|
|
333
374
|
}
|
|
334
|
-
}, [
|
|
375
|
+
}, [
|
|
376
|
+
imageList, currentImageId, hasNextPage,
|
|
377
|
+
isFetchingNextPage, currentPage, controller, firebaseUid, eventId
|
|
378
|
+
]);
|
|
335
379
|
useEffect(() => {
|
|
336
380
|
// This is now the single point of control for loading an image based on the initial props.
|
|
337
381
|
// 1. First, check if all conditions are met to even attempt loading.
|