@yogiswara/honcho-editor-ui 1.1.0 → 1.2.2

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,7 +7,7 @@ declare global {
7
7
  }
8
8
  export interface Controller {
9
9
  onGetImage(firebaseUid: string, imageID: string): Promise<Gallery>;
10
- getImageList(firebaseUid: string): Promise<Gallery[]>;
10
+ getImageList(firebaseUid: string, eventId: string): Promise<Gallery[]>;
11
11
  syncConfig(firebaseUid: string): Promise<void>;
12
12
  handleBack(firebaseUid: string, imageID: string): void;
13
13
  getPresets(firebaseUid: string): Promise<Preset[]>;
@@ -38,7 +38,7 @@ export type ImageItem = {
38
38
  name: string;
39
39
  file: File;
40
40
  };
41
- export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string): {
41
+ export declare function useHonchoEditor(controller: Controller, initImageId: string, firebaseUid: string, eventId: string): {
42
42
  canvasRef: import("react").MutableRefObject<HTMLCanvasElement | null>;
43
43
  canvasContainerRef: import("react").MutableRefObject<HTMLDivElement | null>;
44
44
  fileInputRef: import("react").MutableRefObject<HTMLInputElement | null>;
@@ -6,7 +6,7 @@ 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) {
9
+ export function useHonchoEditor(controller, initImageId, firebaseUid, eventId) {
10
10
  const [currentImageId, setCurrentImageId] = useState(initImageId);
11
11
  // MARK: - Core Editor State & Refs
12
12
  const editorRef = useRef(null);
@@ -172,6 +172,29 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
172
172
  }, 50);
173
173
  return () => clearTimeout(timeoutId);
174
174
  }, [activeSubPanel, isBulkEditing]);
175
+ useEffect(() => {
176
+ const fetchAndSetImageList = async () => {
177
+ if (controller && firebaseUid && eventId && imageList.length === 0) {
178
+ try {
179
+ console.log("Hook is fetching image list for event:", eventId);
180
+ // The controller now requires eventId, adjust the interface if needed
181
+ const galleryList = await controller.getImageList(firebaseUid, eventId);
182
+ const items = galleryList.map(g => ({
183
+ id: g.id,
184
+ url: g.raw_edited?.path || g.download?.path || '',
185
+ name: g.uid,
186
+ file: new File([], g.id),
187
+ }));
188
+ setImageList(items);
189
+ console.log("Image list state updated in hook:", items);
190
+ }
191
+ catch (error) {
192
+ console.error("Hook failed to fetch image list:", error);
193
+ }
194
+ }
195
+ };
196
+ fetchAndSetImageList();
197
+ }, [controller, firebaseUid, eventId, imageList.length]);
175
198
  // Effect for keyboard shortcuts
176
199
  useEffect(() => {
177
200
  window.addEventListener('keydown', handleKeyDown);
@@ -311,15 +334,25 @@ export function useHonchoEditor(controller, initImageId, firebaseUid) {
311
334
  }
312
335
  }, [imageList, currentImageId]);
313
336
  useEffect(() => {
314
- if (initImageId) {
315
- setCurrentImageId(initImageId);
316
- }
317
- }, [initImageId]);
318
- useEffect(() => {
319
- if (currentImageId && firebaseUid) {
320
- loadImageFromId(firebaseUid, currentImageId);
337
+ // This is now the single point of control for loading an image based on the initial props.
338
+ // 1. First, check if all conditions are met to even attempt loading.
339
+ // We ensure the editor itself is ready before doing anything.
340
+ const canLoad = initImageId && firebaseUid && controller && isEditorReady;
341
+ if (!canLoad) {
342
+ return;
321
343
  }
322
- }, [currentImageId, firebaseUid, loadImageFromId]);
344
+ // 2. Define the loading sequence as an async function inside the effect.
345
+ const loadInitialImage = async () => {
346
+ console.log(`[EFFECT] Starting to load initial image ID: ${initImageId}`);
347
+ // This directly calls the loading function. We don't need to set
348
+ // an intermediate 'currentImageId' state, which avoids an extra re-render and potential loop.
349
+ await loadImageFromId(firebaseUid, initImageId);
350
+ };
351
+ // 3. Execute the loading sequence.
352
+ loadInitialImage();
353
+ // Dependencies: The external props and readiness flags that trigger this logic.
354
+ // Whenever any of these change, this effect will re-evaluate.
355
+ }, [initImageId, firebaseUid, controller, isEditorReady, loadImageFromId]);
323
356
  const handleFileChange = (event) => {
324
357
  const files = event.target?.files;
325
358
  if (!files || files.length === 0)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "1.1.0",
3
+ "version": "1.2.2",
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",