@yogiswara/honcho-editor-ui 1.2.2 → 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;
|
|
@@ -35,7 +43,6 @@ export type Preset = {
|
|
|
35
43
|
export type ImageItem = {
|
|
36
44
|
id: string;
|
|
37
45
|
url: string;
|
|
38
|
-
name: string;
|
|
39
46
|
file: File;
|
|
40
47
|
};
|
|
41
48
|
export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string, eventId: string): {
|
|
@@ -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,15 +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
|
-
name: g.uid,
|
|
186
188
|
file: new File([], g.id),
|
|
187
189
|
}));
|
|
188
190
|
setImageList(items);
|
|
189
|
-
|
|
191
|
+
// ✅ SET INITIAL PAGINATION STATE
|
|
192
|
+
setCurrentPage(1);
|
|
193
|
+
setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
|
|
190
194
|
}
|
|
191
195
|
catch (error) {
|
|
192
196
|
console.error("Hook failed to fetch image list:", error);
|
|
@@ -194,7 +198,7 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
|
194
198
|
}
|
|
195
199
|
};
|
|
196
200
|
fetchAndSetImageList();
|
|
197
|
-
}, [controller, firebaseUid, eventId
|
|
201
|
+
}, [controller, firebaseUid, eventId]);
|
|
198
202
|
// Effect for keyboard shortcuts
|
|
199
203
|
useEffect(() => {
|
|
200
204
|
window.addEventListener('keydown', handleKeyDown);
|
|
@@ -323,16 +327,55 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
|
|
|
323
327
|
}
|
|
324
328
|
}, [imageList, currentImageId]);
|
|
325
329
|
const handleNext = useCallback(async (firebaseUid) => {
|
|
326
|
-
// Find the current image index
|
|
327
330
|
const currentIndex = imageList.findIndex(img => img.id === currentImageId);
|
|
328
|
-
//
|
|
329
|
-
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) {
|
|
330
370
|
const nextImageId = imageList[currentIndex + 1]?.id;
|
|
331
371
|
if (nextImageId) {
|
|
332
372
|
setCurrentImageId(nextImageId);
|
|
333
373
|
}
|
|
334
374
|
}
|
|
335
|
-
}, [
|
|
375
|
+
}, [
|
|
376
|
+
imageList, currentImageId, hasNextPage,
|
|
377
|
+
isFetchingNextPage, currentPage, controller, firebaseUid, eventId
|
|
378
|
+
]);
|
|
336
379
|
useEffect(() => {
|
|
337
380
|
// This is now the single point of control for loading an image based on the initial props.
|
|
338
381
|
// 1. First, check if all conditions are met to even attempt loading.
|