@emberai-engg/task-board 0.3.3 → 0.3.5

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.mjs CHANGED
@@ -1,5 +1,5 @@
1
1
  // src/components/TaskBoard.tsx
2
- import { useState as useState9, useEffect as useEffect8, useCallback as useCallback7 } from "react";
2
+ import { useState as useState9, useEffect as useEffect8, useCallback as useCallback7, useRef as useRef8 } from "react";
3
3
  import { DragDropContext } from "@hello-pangea/dnd";
4
4
 
5
5
  // src/context/TaskBoardProvider.tsx
@@ -185,7 +185,7 @@ function TaskBoardProvider({
185
185
 
186
186
  // src/hooks/useTaskBoard.ts
187
187
  import { useState, useEffect, useCallback, useRef } from "react";
188
- function useTaskBoard() {
188
+ function useTaskBoard(isDragging) {
189
189
  const { service, user, projects: configProjects, columns, config } = useTaskBoardContext();
190
190
  const [fetchedProjects, setFetchedProjects] = useState([]);
191
191
  useEffect(() => {
@@ -253,8 +253,9 @@ function useTaskBoard() {
253
253
  }
254
254
  }, [selectedProject, service, columns]);
255
255
  useEffect(() => {
256
+ if (isDragging?.current) return;
256
257
  fetchTasks();
257
- }, [fetchTasks]);
258
+ }, [fetchTasks, isDragging]);
258
259
  const loadMoreTasks = useCallback(async (statusKey) => {
259
260
  if (!selectedProject || loadingMore[statusKey]) return;
260
261
  const current = tasks[statusKey]?.length || 0;
@@ -311,10 +312,10 @@ function useTaskBoard() {
311
312
 
312
313
  // src/hooks/useTaskActions.ts
313
314
  import { useCallback as useCallback2, useRef as useRef2 } from "react";
314
- function useTaskActions(tasks, setTasks, fetchTasks) {
315
+ function useTaskActions(tasks, setTasks, fetchTasks, isDragging) {
315
316
  const { service, config } = useTaskBoardContext();
316
- const tasksRef = useRef2(tasks);
317
- tasksRef.current = tasks;
317
+ const internalDragging = useRef2(false);
318
+ const draggingRef = isDragging ?? internalDragging;
318
319
  const createTask = useCallback2(async (data) => {
319
320
  const task = await service.createTask(data);
320
321
  config.onTaskCreate?.(task);
@@ -337,36 +338,40 @@ function useTaskActions(tasks, setTasks, fetchTasks) {
337
338
  });
338
339
  }, [service]);
339
340
  const moveTask = useCallback2(async (taskId, sourceStatus, destStatus, sourceIndex, destIndex) => {
340
- const currentTasks = tasksRef.current;
341
- const sourceCol = [...currentTasks[sourceStatus] || []];
342
- const destCol = sourceStatus === destStatus ? sourceCol : [...currentTasks[destStatus] || []];
343
- const [movedTask] = sourceCol.splice(sourceIndex, 1);
344
- if (!movedTask) return;
345
- const updatedTask = { ...movedTask, status: destStatus };
346
- destCol.splice(destIndex, 0, updatedTask);
347
- let newPosition;
348
- if (destCol.length === 1) {
349
- newPosition = POSITION_GAP;
350
- } else if (destIndex === 0) {
351
- newPosition = (destCol[1]?.position ?? POSITION_GAP) - POSITION_GAP;
352
- } else if (destIndex === destCol.length - 1) {
353
- newPosition = (destCol[destCol.length - 2]?.position ?? 0) + POSITION_GAP;
354
- } else {
355
- const above = destCol[destIndex - 1]?.position ?? 0;
356
- const below = destCol[destIndex + 1]?.position ?? above + POSITION_GAP * 2;
357
- newPosition = (above + below) / 2;
358
- }
359
- updatedTask.position = newPosition;
360
- const newTasks = { ...currentTasks };
361
- newTasks[sourceStatus] = sourceCol;
362
- if (sourceStatus !== destStatus) {
363
- newTasks[destStatus] = destCol;
364
- }
365
- setTasks(newTasks);
341
+ draggingRef.current = true;
342
+ let newPosition = POSITION_GAP;
343
+ setTasks((prev) => {
344
+ const sourceCol = [...prev[sourceStatus] || []];
345
+ const destCol = sourceStatus === destStatus ? sourceCol : [...prev[destStatus] || []];
346
+ const [movedTask] = sourceCol.splice(sourceIndex, 1);
347
+ if (!movedTask) return prev;
348
+ const updatedTask = { ...movedTask, status: destStatus };
349
+ destCol.splice(destIndex, 0, updatedTask);
350
+ if (destCol.length === 1) {
351
+ newPosition = POSITION_GAP;
352
+ } else if (destIndex === 0) {
353
+ newPosition = (destCol[1]?.position ?? POSITION_GAP) - POSITION_GAP;
354
+ } else if (destIndex === destCol.length - 1) {
355
+ newPosition = (destCol[destCol.length - 2]?.position ?? 0) + POSITION_GAP;
356
+ } else {
357
+ const above = destCol[destIndex - 1]?.position ?? 0;
358
+ const below = destCol[destIndex + 1]?.position ?? above + POSITION_GAP * 2;
359
+ newPosition = (above + below) / 2;
360
+ }
361
+ updatedTask.position = newPosition;
362
+ const newTasks = { ...prev };
363
+ newTasks[sourceStatus] = sourceCol;
364
+ if (sourceStatus !== destStatus) {
365
+ newTasks[destStatus] = destCol;
366
+ }
367
+ return newTasks;
368
+ });
366
369
  try {
367
370
  await service.updateTask(taskId, { status: destStatus, position: newPosition });
368
371
  } catch {
369
372
  fetchTasks();
373
+ } finally {
374
+ draggingRef.current = false;
370
375
  }
371
376
  }, [setTasks, service, fetchTasks]);
372
377
  return { createTask, updateTask, deleteTask, markTaskRead, moveTask };
@@ -461,11 +466,15 @@ function formatDateTime(dateStr) {
461
466
  minute: "2-digit"
462
467
  });
463
468
  }
469
+ function stripMentionMarkup(text) {
470
+ return text.replace(/@\[(.*?)\]\(.*?\)/g, "@$1");
471
+ }
464
472
  function getDescriptionPreview(desc) {
465
473
  if (!desc) return "";
466
- if (typeof desc === "string") return desc;
474
+ if (typeof desc === "string") return stripMentionMarkup(desc);
467
475
  for (const section of DESCRIPTION_SECTIONS) {
468
- if (desc[section.key]?.trim()) return desc[section.key].trim();
476
+ const val = desc[section.key]?.trim();
477
+ if (val) return stripMentionMarkup(val);
469
478
  }
470
479
  return "";
471
480
  }
@@ -2014,8 +2023,9 @@ function TaskBoard({
2014
2023
  renderCreateTask
2015
2024
  }) {
2016
2025
  const { columns, features, service } = useTaskBoardContext();
2017
- const board = useTaskBoard();
2018
- const actions = useTaskActions(board.tasks, board.setTasks, board.fetchTasks);
2026
+ const isDraggingRef = useRef8(false);
2027
+ const board = useTaskBoard(isDraggingRef);
2028
+ const actions = useTaskActions(board.tasks, board.setTasks, board.fetchTasks, isDraggingRef);
2019
2029
  const { copiedTaskId, copyShareLink } = useShareLink();
2020
2030
  const [selectedTask, setSelectedTask] = useState9(null);
2021
2031
  const [createForStatus, setCreateForStatus] = useState9("");