@yogiswara/honcho-editor-ui 3.8.1 → 3.8.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.
@@ -12,14 +12,6 @@ export interface PhotoData {
12
12
  isSelected: boolean;
13
13
  adjustments?: Partial<AdjustmentValues>;
14
14
  }
15
- export interface GalleryDataProps {
16
- photos: any[];
17
- isLoading: boolean;
18
- isLoadingMore: boolean;
19
- hasMore: boolean;
20
- loadMore: () => void;
21
- reloadGallery: () => void;
22
- }
23
15
  export interface CopyCheckboxes {
24
16
  color: {
25
17
  temperature: boolean;
@@ -163,4 +155,4 @@ export interface UseHonchoEditorBulkReturn {
163
155
  * - Automatic backend synchronization for all state changes
164
156
  * - Comprehensive logging of multi-image operations
165
157
  */
166
- export declare function useHonchoEditorBulk(controller: Controller, eventID: string, firebaseUid: string, galleryHookData: GalleryDataProps): UseHonchoEditorBulkReturn;
158
+ export declare function useHonchoEditorBulk(controller: Controller, eventID: string, firebaseUid: string): UseHonchoEditorBulkReturn;
@@ -1,6 +1,7 @@
1
1
  'use client';
2
2
  import { useState, useCallback, useEffect, useMemo, useRef } from 'react';
3
3
  import { useAdjustmentHistoryBatch } from '../useAdjustmentHistoryBatch';
4
+ import { usePaging } from "../usePaging";
4
5
  import { usePreset } from "../usePreset";
5
6
  import { mapAdjustmentStateToAdjustmentEditor } from "../../utils/adjustment";
6
7
  import { log } from '../../utils/logger';
@@ -141,16 +142,13 @@ const getCurrentAdjustmentsForCopy = (selectedIds, currentBatch) => {
141
142
  * - Automatic backend synchronization for all state changes
142
143
  * - Comprehensive logging of multi-image operations
143
144
  */
144
- export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHookData) {
145
+ export function useHonchoEditorBulk(controller, eventID, firebaseUid) {
145
146
  const { state, actions: batchActions } = useAdjustmentHistoryBatch(controller, firebaseUid, eventID);
146
147
  const { currentBatch, selectedIds } = state;
147
- // const { images, info, actions } = usePaging(controller, firebaseUid, eventID, {
148
- // autoLoad: true,
149
- // autoReset: false, // Prevent auto-reset to avoid loops
150
- // });
151
- const images = useMemo(() => {
152
- return galleryHookData.photos.map(p => p.value || p);
153
- }, [galleryHookData.photos]);
148
+ const { images, info, actions } = usePaging(controller, firebaseUid, eventID, {
149
+ autoLoad: true,
150
+ autoReset: false, // Prevent auto-reset to avoid loops
151
+ });
154
152
  // Preset management
155
153
  const { presets, info: presetInfo, actions: presetActions } = usePreset(controller, firebaseUid, {
156
154
  autoLoad: true,
@@ -180,12 +178,12 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHoo
180
178
  };
181
179
  const readyState = useMemo(() => {
182
180
  const paging = {
183
- isReady: !galleryHookData.isLoading, // Simplified ready check
184
- isLoading: galleryHookData.isLoading,
181
+ isReady: info.isReady ?? (info.isInitialized && !info.isLoading && info.error === null),
182
+ isLoading: info.isLoading,
185
183
  };
186
184
  log.debug("[useHonchoEditorBulk] 📊 Paging state");
187
185
  const history = {
188
- isReady: state.isReady ?? true,
186
+ isReady: state.isReady ?? true, // History sync happens on-demand, not blocking
189
187
  isLoading: state.isLoading ?? false
190
188
  };
191
189
  log.debug("[useHonchoEditorBulk] 📊 History state");
@@ -193,15 +191,26 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHoo
193
191
  isReady: presetInfo.isReady ?? (presetInfo.isInitialized && !presetInfo.isLoading),
194
192
  isLoading: presetInfo.isLoading
195
193
  };
194
+ log.debug("[useHonchoEditorBulk] 📊 Preset state");
196
195
  const allReady = paging.isReady && history.isReady && presets.isReady;
197
196
  const anyLoading = paging.isLoading || history.isLoading || presets.isLoading;
197
+ log.debug({
198
+ paging: { isReady: paging.isReady, isLoading: paging.isLoading },
199
+ history: { isReady: history.isReady, isLoading: history.isLoading },
200
+ presets: { isReady: presets.isReady, isLoading: presets.isLoading },
201
+ allReady,
202
+ anyLoading
203
+ }, '[useHonchoEditorBulk] 📊 Ready state computed');
198
204
  return {
199
205
  isReady: allReady,
200
206
  isLoading: anyLoading,
201
207
  operations: { paging, history, presets }
202
208
  };
203
209
  }, [
204
- galleryHookData.isLoading, // Updated dependency
210
+ info.isReady,
211
+ info.isInitialized,
212
+ info.isLoading,
213
+ info.error,
205
214
  state.isReady,
206
215
  state.isLoading,
207
216
  presetInfo.isReady,
@@ -287,9 +296,9 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHoo
287
296
  }, '[useHonchoEditorBulk] 🎨 Preset selection updated');
288
297
  }, [activePreset]);
289
298
  // Use loading states from usePaging instead of local state
290
- const isLoading = galleryHookData.isLoading;
291
- const error = null;
292
- const hasMore = galleryHookData.hasMore;
299
+ const isLoading = info.isLoading;
300
+ const error = info.error;
301
+ const hasMore = info.hasMore;
293
302
  const imageData = useMemo(() => {
294
303
  const res = images.map(item => {
295
304
  const basePhoto = mapGalleryToPhotoData(item, selectedIds);
@@ -527,7 +536,7 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHoo
527
536
  return {
528
537
  imageData,
529
538
  isLoading,
530
- isLoadingMore: galleryHookData.isLoadingMore,
539
+ isLoadingMore: info.isLoadingMore,
531
540
  error,
532
541
  selectedIds,
533
542
  hasMore,
@@ -545,8 +554,8 @@ export function useHonchoEditorBulk(controller, eventID, firebaseUid, galleryHoo
545
554
  // Preset creation handlers
546
555
  presetActions, // Expose preset actions for create/rename/delete
547
556
  handleToggleImageSelection: batchActions.toggleSelection,
548
- handleLoadMore: async () => { galleryHookData.loadMore(); },
549
- handleRefresh: async () => { galleryHookData.reloadGallery(); },
557
+ handleLoadMore: actions.loadMore,
558
+ handleRefresh: actions.refresh,
550
559
  // Adjustment
551
560
  handleBulkTempDecreaseMax,
552
561
  handleBulkTempDecrease,
@@ -47,7 +47,7 @@ export interface UseHonchoEditorSingleActions {
47
47
  setBatchMode: (enabled: boolean) => void;
48
48
  startBatchMode: () => void;
49
49
  endBatchMode: () => void;
50
- updateFromSocket: (imageId: string, adjustmentTaskId: string, adjustment: ColorAdjustment) => void;
50
+ updateFromSocket: (imageId: string, adjustmentTaskId: string, adjustment: ColorAdjustment, preset_id?: string) => void;
51
51
  pushState: (state: AdjustmentState) => void;
52
52
  undo: () => void;
53
53
  redo: () => void;
@@ -166,8 +166,8 @@ export function useHonchoEditorSingle({ controller, initImageId, firebaseUid })
166
166
  sharpness: adjustments.sharpnessScore,
167
167
  };
168
168
  }, [adjustmentHistory.currentState]);
169
- const updateFromSocket = useCallback((imageId, adjustmentTaskId, adjustment) => {
170
- adjustmentHistory.actions.updateFromBackend(imageId, adjustmentTaskId, adjustment);
169
+ const updateFromSocket = useCallback((imageId, adjustmentTaskId, adjustment, preset_id) => {
170
+ adjustmentHistory.actions.updateFromBackend(imageId, adjustmentTaskId, adjustment, preset_id);
171
171
  }, [adjustmentHistory.actions.updateFromBackend]);
172
172
  const actions = {
173
173
  // Navigation
@@ -53,7 +53,7 @@ export interface HistoryActions {
53
53
  /** Sync history from backend using getEditorHistory */
54
54
  syncFromBackend: () => Promise<void>;
55
55
  /** Update specific history entry from backend without changing current index */
56
- updateFromBackend: (imageId: string, adjustmentTaskId: string, adjustment: ColorAdjustment) => void;
56
+ updateFromBackend: (imageId: string, adjustmentTaskId: string, adjustment: ColorAdjustment, preset_id?: string) => void;
57
57
  }
58
58
  /**
59
59
  * Configuration actions for runtime adjustment
@@ -22,7 +22,7 @@ const convertAdjustmentStateToColorAdjustment = (adjustmentState) => {
22
22
  /**
23
23
  * Convert ColorAdjustment from backend to AdjustmentState format
24
24
  */
25
- const convertColorAdjustmentToAdjustmentState = (colorAdjustment) => {
25
+ const convertColorAdjustmentToAdjustmentState = (colorAdjustment, preset_id) => {
26
26
  return {
27
27
  tempScore: colorAdjustment.temperature,
28
28
  tintScore: colorAdjustment.tint,
@@ -36,6 +36,7 @@ const convertColorAdjustmentToAdjustmentState = (colorAdjustment) => {
36
36
  blacksScore: colorAdjustment.blacks,
37
37
  clarityScore: colorAdjustment.clarity,
38
38
  sharpnessScore: Math.max(0, Math.min(100, colorAdjustment.sharpness)),
39
+ preset_id: preset_id,
39
40
  };
40
41
  };
41
42
  /**
@@ -579,32 +580,32 @@ export function useAdjustmentHistory(initialState, controller, firebaseUid, curr
579
580
  }
580
581
  }, [internalOptions]);
581
582
  // Update specific history entry from backend without changing current index
582
- const updateFromBackend = useCallback((imageId, adjustmentTaskId, adjustment) => {
583
+ const updateFromBackend = useCallback((imageId, adjustmentTaskId, adjustment, preset_id) => {
583
584
  // Ignore updates if imageID doesn't match current image
584
585
  if (imageId !== internalOptions.currentImageId) {
585
- console.log(`🚫 updateFromBackend: Ignoring update for different image (${imageId} vs ${internalOptions.currentImageId})`);
586
+ log.debug({ receivedImageId: imageId, currentImageId: internalOptions.currentImageId }, '🚫 updateFromBackend: Ignoring update for different image');
586
587
  return;
587
588
  }
588
589
  // Ignore updates during batch mode
589
590
  if (batchModeRef.current) {
590
- console.log(`🚫 updateFromBackend: Ignoring update during batch mode for taskId: ${adjustmentTaskId}`);
591
+ log.debug({ adjustmentTaskId }, '🚫 updateFromBackend: Ignoring update during batch mode for taskId');
591
592
  return;
592
593
  }
593
- console.log(`🔄 updateFromBackend: Received update for taskId: ${adjustmentTaskId}, imageId: ${imageId}`);
594
+ log.info({ adjustmentTaskId, imageId, preset_id }, '🔄 updateFromBackend: Received update');
594
595
  // Convert ColorAdjustment to AdjustmentState
595
- const updatedState = convertColorAdjustmentToAdjustmentState(adjustment);
596
+ const updatedState = convertColorAdjustmentToAdjustmentState(adjustment, preset_id);
596
597
  setHistory(prevHistory => {
597
598
  // Find the index of the task to update
598
599
  const taskIndex = prevHistory.findIndex(entry => entry.taskId === adjustmentTaskId);
599
600
  if (taskIndex === -1) {
600
601
  // Task doesn't exist in current history, we need to sync from backend
601
602
  // to get the complete history with proper chronological order
602
- console.log(`📝 updateFromBackend: TaskId ${adjustmentTaskId} not found in current history, triggering sync from backend`);
603
+ log.info({ adjustmentTaskId }, '📝 updateFromBackend: TaskId not found in current history, triggering sync from backend');
603
604
  // Don't modify history here, instead trigger a sync
604
605
  // Use setTimeout to avoid calling async function inside setState
605
606
  setTimeout(() => {
606
607
  syncFromBackend().catch(error => {
607
- console.error('❌ Failed to sync history after unknown taskId:', error);
608
+ log.error({ error, adjustmentTaskId }, '❌ Failed to sync history after unknown taskId');
608
609
  });
609
610
  }, 0);
610
611
  // Return unchanged history for now
@@ -613,10 +614,10 @@ export function useAdjustmentHistory(initialState, controller, firebaseUid, curr
613
614
  // Task exists, check if it's the current index
614
615
  const isCurrentIndex = taskIndex === currentIndexRef.current;
615
616
  if (isCurrentIndex) {
616
- console.log(`🔄 updateFromBackend: Updating current index (${taskIndex}) but not changing current state`);
617
+ log.debug({ taskIndex }, '🔄 updateFromBackend: Updating current index but not changing current state');
617
618
  }
618
619
  else {
619
- console.log(`🔄 updateFromBackend: Updating history entry at index ${taskIndex} (far behind current ${currentIndexRef.current})`);
620
+ log.debug({ taskIndex, currentIndex: currentIndexRef.current }, '🔄 updateFromBackend: Updating history entry far behind current');
620
621
  }
621
622
  // Update the specific history entry
622
623
  const updatedHistory = [...prevHistory];
@@ -626,7 +627,7 @@ export function useAdjustmentHistory(initialState, controller, firebaseUid, curr
626
627
  };
627
628
  return updatedHistory;
628
629
  });
629
- console.log(`✅ updateFromBackend: Successfully updated taskId ${adjustmentTaskId}`);
630
+ log.info({ adjustmentTaskId }, '✅ updateFromBackend: Successfully updated taskId');
630
631
  }, [internalOptions]);
631
632
  // History info object
632
633
  const historyInfo = useMemo(() => ({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yogiswara/honcho-editor-ui",
3
- "version": "3.8.1",
3
+ "version": "3.8.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",