@emberai-engg/task-board 0.3.3 → 0.3.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.
package/dist/index.d.mts CHANGED
@@ -354,7 +354,7 @@ declare function TaskBoardProvider({ children, ...config }: TaskBoardConfig & {
354
354
  children: React__default.ReactNode;
355
355
  }): react_jsx_runtime.JSX.Element;
356
356
 
357
- declare function useTaskBoard(): {
357
+ declare function useTaskBoard(isDragging?: React.RefObject<boolean>): {
358
358
  projects: Project[];
359
359
  selectedProject: string;
360
360
  setSelectedProject: React$1.Dispatch<React$1.SetStateAction<string>>;
@@ -373,7 +373,7 @@ declare function useTaskBoard(): {
373
373
  loadMoreTasks: (statusKey: string) => Promise<void>;
374
374
  };
375
375
 
376
- declare function useTaskActions(tasks: TasksByStatus, setTasks: React.Dispatch<React.SetStateAction<TasksByStatus>>, fetchTasks: () => Promise<void>): {
376
+ declare function useTaskActions(tasks: TasksByStatus, setTasks: React.Dispatch<React.SetStateAction<TasksByStatus>>, fetchTasks: () => Promise<void>, isDragging?: React.RefObject<boolean>): {
377
377
  createTask: (data: CreateTaskPayload) => Promise<Task>;
378
378
  updateTask: (taskId: string, data: UpdateTaskPayload) => Promise<Task>;
379
379
  deleteTask: (taskId: string) => Promise<void>;
package/dist/index.d.ts CHANGED
@@ -354,7 +354,7 @@ declare function TaskBoardProvider({ children, ...config }: TaskBoardConfig & {
354
354
  children: React__default.ReactNode;
355
355
  }): react_jsx_runtime.JSX.Element;
356
356
 
357
- declare function useTaskBoard(): {
357
+ declare function useTaskBoard(isDragging?: React.RefObject<boolean>): {
358
358
  projects: Project[];
359
359
  selectedProject: string;
360
360
  setSelectedProject: React$1.Dispatch<React$1.SetStateAction<string>>;
@@ -373,7 +373,7 @@ declare function useTaskBoard(): {
373
373
  loadMoreTasks: (statusKey: string) => Promise<void>;
374
374
  };
375
375
 
376
- declare function useTaskActions(tasks: TasksByStatus, setTasks: React.Dispatch<React.SetStateAction<TasksByStatus>>, fetchTasks: () => Promise<void>): {
376
+ declare function useTaskActions(tasks: TasksByStatus, setTasks: React.Dispatch<React.SetStateAction<TasksByStatus>>, fetchTasks: () => Promise<void>, isDragging?: React.RefObject<boolean>): {
377
377
  createTask: (data: CreateTaskPayload) => Promise<Task>;
378
378
  updateTask: (taskId: string, data: UpdateTaskPayload) => Promise<Task>;
379
379
  deleteTask: (taskId: string) => Promise<void>;
package/dist/index.js CHANGED
@@ -262,7 +262,7 @@ function TaskBoardProvider({
262
262
 
263
263
  // src/hooks/useTaskBoard.ts
264
264
  var import_react2 = require("react");
265
- function useTaskBoard() {
265
+ function useTaskBoard(isDragging) {
266
266
  const { service, user, projects: configProjects, columns, config } = useTaskBoardContext();
267
267
  const [fetchedProjects, setFetchedProjects] = (0, import_react2.useState)([]);
268
268
  (0, import_react2.useEffect)(() => {
@@ -330,8 +330,9 @@ function useTaskBoard() {
330
330
  }
331
331
  }, [selectedProject, service, columns]);
332
332
  (0, import_react2.useEffect)(() => {
333
+ if (isDragging?.current) return;
333
334
  fetchTasks();
334
- }, [fetchTasks]);
335
+ }, [fetchTasks, isDragging]);
335
336
  const loadMoreTasks = (0, import_react2.useCallback)(async (statusKey) => {
336
337
  if (!selectedProject || loadingMore[statusKey]) return;
337
338
  const current = tasks[statusKey]?.length || 0;
@@ -388,10 +389,10 @@ function useTaskBoard() {
388
389
 
389
390
  // src/hooks/useTaskActions.ts
390
391
  var import_react3 = require("react");
391
- function useTaskActions(tasks, setTasks, fetchTasks) {
392
+ function useTaskActions(tasks, setTasks, fetchTasks, isDragging) {
392
393
  const { service, config } = useTaskBoardContext();
393
- const tasksRef = (0, import_react3.useRef)(tasks);
394
- tasksRef.current = tasks;
394
+ const internalDragging = (0, import_react3.useRef)(false);
395
+ const draggingRef = isDragging ?? internalDragging;
395
396
  const createTask = (0, import_react3.useCallback)(async (data) => {
396
397
  const task = await service.createTask(data);
397
398
  config.onTaskCreate?.(task);
@@ -414,36 +415,40 @@ function useTaskActions(tasks, setTasks, fetchTasks) {
414
415
  });
415
416
  }, [service]);
416
417
  const moveTask = (0, import_react3.useCallback)(async (taskId, sourceStatus, destStatus, sourceIndex, destIndex) => {
417
- const currentTasks = tasksRef.current;
418
- const sourceCol = [...currentTasks[sourceStatus] || []];
419
- const destCol = sourceStatus === destStatus ? sourceCol : [...currentTasks[destStatus] || []];
420
- const [movedTask] = sourceCol.splice(sourceIndex, 1);
421
- if (!movedTask) return;
422
- const updatedTask = { ...movedTask, status: destStatus };
423
- destCol.splice(destIndex, 0, updatedTask);
424
- let newPosition;
425
- if (destCol.length === 1) {
426
- newPosition = POSITION_GAP;
427
- } else if (destIndex === 0) {
428
- newPosition = (destCol[1]?.position ?? POSITION_GAP) - POSITION_GAP;
429
- } else if (destIndex === destCol.length - 1) {
430
- newPosition = (destCol[destCol.length - 2]?.position ?? 0) + POSITION_GAP;
431
- } else {
432
- const above = destCol[destIndex - 1]?.position ?? 0;
433
- const below = destCol[destIndex + 1]?.position ?? above + POSITION_GAP * 2;
434
- newPosition = (above + below) / 2;
435
- }
436
- updatedTask.position = newPosition;
437
- const newTasks = { ...currentTasks };
438
- newTasks[sourceStatus] = sourceCol;
439
- if (sourceStatus !== destStatus) {
440
- newTasks[destStatus] = destCol;
441
- }
442
- setTasks(newTasks);
418
+ draggingRef.current = true;
419
+ let newPosition = POSITION_GAP;
420
+ setTasks((prev) => {
421
+ const sourceCol = [...prev[sourceStatus] || []];
422
+ const destCol = sourceStatus === destStatus ? sourceCol : [...prev[destStatus] || []];
423
+ const [movedTask] = sourceCol.splice(sourceIndex, 1);
424
+ if (!movedTask) return prev;
425
+ const updatedTask = { ...movedTask, status: destStatus };
426
+ destCol.splice(destIndex, 0, updatedTask);
427
+ if (destCol.length === 1) {
428
+ newPosition = POSITION_GAP;
429
+ } else if (destIndex === 0) {
430
+ newPosition = (destCol[1]?.position ?? POSITION_GAP) - POSITION_GAP;
431
+ } else if (destIndex === destCol.length - 1) {
432
+ newPosition = (destCol[destCol.length - 2]?.position ?? 0) + POSITION_GAP;
433
+ } else {
434
+ const above = destCol[destIndex - 1]?.position ?? 0;
435
+ const below = destCol[destIndex + 1]?.position ?? above + POSITION_GAP * 2;
436
+ newPosition = (above + below) / 2;
437
+ }
438
+ updatedTask.position = newPosition;
439
+ const newTasks = { ...prev };
440
+ newTasks[sourceStatus] = sourceCol;
441
+ if (sourceStatus !== destStatus) {
442
+ newTasks[destStatus] = destCol;
443
+ }
444
+ return newTasks;
445
+ });
443
446
  try {
444
447
  await service.updateTask(taskId, { status: destStatus, position: newPosition });
445
448
  } catch {
446
449
  fetchTasks();
450
+ } finally {
451
+ draggingRef.current = false;
447
452
  }
448
453
  }, [setTasks, service, fetchTasks]);
449
454
  return { createTask, updateTask, deleteTask, markTaskRead, moveTask };
@@ -2091,8 +2096,9 @@ function TaskBoard({
2091
2096
  renderCreateTask
2092
2097
  }) {
2093
2098
  const { columns, features, service } = useTaskBoardContext();
2094
- const board = useTaskBoard();
2095
- const actions = useTaskActions(board.tasks, board.setTasks, board.fetchTasks);
2099
+ const isDraggingRef = (0, import_react13.useRef)(false);
2100
+ const board = useTaskBoard(isDraggingRef);
2101
+ const actions = useTaskActions(board.tasks, board.setTasks, board.fetchTasks, isDraggingRef);
2096
2102
  const { copiedTaskId, copyShareLink } = useShareLink();
2097
2103
  const [selectedTask, setSelectedTask] = (0, import_react13.useState)(null);
2098
2104
  const [createForStatus, setCreateForStatus] = (0, import_react13.useState)("");