@yogiswara/honcho-editor-ui 1.3.1 → 1.3.3

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.
@@ -73,4 +73,12 @@ export interface Gallery {
73
73
  editor_config?: EditorConfig;
74
74
  log: Log;
75
75
  }
76
+ export interface ResponseGalleryPaging {
77
+ gallery: Gallery[];
78
+ limit: number;
79
+ current_page: number;
80
+ prev_page: number;
81
+ next_page: number;
82
+ sum_of_image?: number;
83
+ }
76
84
  export {};
@@ -1,5 +1,5 @@
1
1
  import { SelectChangeEvent } from "@mui/material";
2
- import { Gallery } from '../../hooks/editor/type';
2
+ import { Gallery, ResponseGalleryPaging } from '../../hooks/editor/type';
3
3
  declare global {
4
4
  interface Window {
5
5
  Module: any;
@@ -7,21 +7,13 @@ declare global {
7
7
  }
8
8
  export interface Controller {
9
9
  onGetImage(firebaseUid: string, imageID: string): Promise<Gallery>;
10
- getImageList(firebaseUid: string, eventId: string, page: number): Promise<ResponseGallery>;
10
+ getImageList(firebaseUid: string, eventId: string, page: number): Promise<ResponseGalleryPaging>;
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
- }
25
17
  export type AdjustmentState = {
26
18
  tempScore: number;
27
19
  tintScore: number;
@@ -45,7 +37,7 @@ export type ImageItem = {
45
37
  url: string;
46
38
  file: File;
47
39
  };
48
- export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string, eventId: string): {
40
+ export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string): {
49
41
  canvasRef: import("react").MutableRefObject<HTMLCanvasElement | null>;
50
42
  canvasContainerRef: import("react").MutableRefObject<HTMLDivElement | null>;
51
43
  fileInputRef: import("react").MutableRefObject<HTMLInputElement | null>;
@@ -103,7 +95,7 @@ export declare function useHonchoEditor(controller: Controller, initImageId: str
103
95
  handleScriptReady: () => Promise<void>;
104
96
  handleFileChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
105
97
  handleAlertClose: () => void;
106
- loadImageFromId: (firebaseUid: string, imageId: string) => Promise<void>;
98
+ loadImageFromId: (firebaseUid: string, imageId: string) => Promise<Gallery | undefined>;
107
99
  loadImageFromUrl: (url: string) => Promise<void>;
108
100
  handleRevert: () => void;
109
101
  handleUndo: () => void;
@@ -6,11 +6,12 @@ const initialAdjustments = {
6
6
  whitesScore: 0, blacksScore: 0, saturationScore: 0, contrastScore: 0, clarityScore: 0, sharpnessScore: 0,
7
7
  };
8
8
  const clamp = (value) => Math.max(-100, Math.min(100, value));
9
- export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
9
+ export function useHonchoEditor(controller, initImageId, firebaseUid) {
10
10
  const [currentImageId, setCurrentImageId] = useState(initImageId);
11
11
  const [currentPage, setCurrentPage] = useState(1);
12
12
  const [hasNextPage, setHasNextPage] = useState(true);
13
13
  const [isFetchingNextPage, setIsFetchingNextPage] = useState(false);
14
+ const [eventId, setEventId] = useState(null);
14
15
  // MARK: - Core Editor State & Refs
15
16
  const editorRef = useRef(null);
16
17
  const canvasRef = useRef(null);
@@ -175,33 +176,6 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
175
176
  }, 50);
176
177
  return () => clearTimeout(timeoutId);
177
178
  }, [activeSubPanel, isBulkEditing]);
178
- useEffect(() => {
179
- const fetchAndSetImageList = async () => {
180
- if (controller && firebaseUid && eventId && imageList.length === 0) {
181
- try {
182
- console.log("Hook is fetching image list for event:", eventId);
183
- // The controller now requires eventId, adjust the interface if needed
184
- const response = await controller.getImageList(firebaseUid, eventId, 1);
185
- const items = response.gallery.map(g => ({
186
- id: g.id,
187
- url: g.raw_edited?.path || g.download?.path || '',
188
- name: g.id,
189
- file: new File([], g.id),
190
- }));
191
- setImageList(items);
192
- // ✅ ADD THIS CONSOLE LOG
193
- console.log("✅ Image list fetched and set in state:", items);
194
- // ✅ SET INITIAL PAGINATION STATE
195
- setCurrentPage(1);
196
- setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
197
- }
198
- catch (error) {
199
- console.error("Hook failed to fetch image list:", error);
200
- }
201
- }
202
- };
203
- fetchAndSetImageList();
204
- }, [controller, firebaseUid, eventId]);
205
179
  // Effect for keyboard shortcuts
206
180
  useEffect(() => {
207
181
  window.addEventListener('keydown', handleKeyDown);
@@ -305,9 +279,8 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
305
279
  ? gallery.raw_edited.path
306
280
  : gallery?.download?.path;
307
281
  if (imagePath) {
308
- console.log("Test Image Path", imagePath);
309
- console.log("Test gallery Path", { ...gallery });
310
282
  await loadImageFromUrl(imagePath);
283
+ return gallery; // ✅ RETURN the gallery object on success
311
284
  }
312
285
  else {
313
286
  throw new Error("Controller did not return a valid image object with path.");
@@ -333,30 +306,30 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
333
306
  const currentIndex = imageList.findIndex(img => img.id === currentImageId);
334
307
  // Condition 1: We are at the last image of the currently loaded list.
335
308
  if (currentIndex === imageList.length - 1) {
309
+ // ✅ ADD THIS CHECK: Ensure we have the eventId before trying to fetch.
310
+ if (!eventId) {
311
+ console.error("Cannot fetch next page, eventId has not been discovered yet.");
312
+ return;
313
+ }
336
314
  // Condition 2: Check if there's a next page and we aren't already fetching it.
337
315
  if (hasNextPage && !isFetchingNextPage) {
338
316
  console.log(`At end of list. Fetching next page: ${currentPage + 1}`);
339
- setIsFetchingNextPage(true); // Prevent multiple fetches
317
+ setIsFetchingNextPage(true);
340
318
  try {
341
- // Fetch the next page of images
342
319
  const response = await controller.getImageList(firebaseUid, eventId, currentPage + 1);
343
- // If the API returns new images...
344
320
  if (response.gallery && response.gallery.length > 0) {
345
321
  const newItems = response.gallery.map(g => ({
346
322
  id: g.id,
347
323
  url: g.raw_edited?.path || g.download?.path || '',
324
+ name: g.id, // ✅ ADDED: Fulfill the ImageItem 'name' property
348
325
  file: new File([], g.id),
349
326
  }));
350
- // Append the new images to our existing list
351
327
  setImageList(prevList => [...prevList, ...newItems]);
352
- // Update the pagination state
353
328
  setCurrentPage(response.current_page);
354
329
  setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
355
- // IMPORTANT: Set the current image to the first of the NEW images
356
330
  setCurrentImageId(newItems[0].id);
357
331
  }
358
332
  else {
359
- // No more images left to fetch
360
333
  setHasNextPage(false);
361
334
  }
362
335
  }
@@ -364,7 +337,7 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
364
337
  console.error("Failed to fetch next page:", error);
365
338
  }
366
339
  finally {
367
- setIsFetchingNextPage(false); // Allow fetching again
340
+ setIsFetchingNextPage(false);
368
341
  }
369
342
  }
370
343
  // Condition 3: We are NOT at the end of the list, so just navigate normally.
@@ -399,6 +372,38 @@ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
399
372
  // Dependencies: The external props and readiness flags that trigger this logic.
400
373
  // Whenever any of these change, this effect will re-evaluate.
401
374
  }, [initImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
375
+ useEffect(() => {
376
+ const initialize = async () => {
377
+ // 1. Check if we have the initial data and the editor is ready
378
+ if (initImageId && firebaseUid && controller && isEditorReady) {
379
+ console.log(`[INIT] Starting sequence for image: ${initImageId}`);
380
+ // 2. Load the initial image data and get the gallery object back
381
+ const initialGallery = await loadImageFromId(firebaseUid, initImageId);
382
+ // 3. If we got the gallery data and it contains an event_id...
383
+ if (initialGallery && initialGallery.event_id) {
384
+ const fetchedEventId = initialGallery.event_id;
385
+ console.log(`[INIT] Discovered eventID: ${fetchedEventId}`);
386
+ setEventId(fetchedEventId); // Store the discovered eventId in our state
387
+ // 4. Now, use the discovered eventId to fetch the full image list for navigation
388
+ const response = await controller.getImageList(firebaseUid, fetchedEventId, 1);
389
+ const items = response.gallery.map(g => ({
390
+ id: g.id,
391
+ url: g.raw_edited?.path || g.download?.path || '',
392
+ name: g.id,
393
+ file: new File([], g.id),
394
+ }));
395
+ setImageList(items);
396
+ setCurrentPage(1);
397
+ setHasNextPage(response.next_page !== 0 && response.next_page > response.current_page);
398
+ console.log("[INIT] Image list fetched and set.");
399
+ }
400
+ else {
401
+ console.error("[INIT] Failed to get initial gallery data or event_id was missing.");
402
+ }
403
+ }
404
+ };
405
+ initialize();
406
+ }, [initImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
402
407
  useEffect(() => {
403
408
  // Ensure we have everything needed before trying to load.
404
409
  if (currentImageId && firebaseUid && controller && isEditorReady) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "1.3.1",
3
+ "version": "1.3.3",
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",