@emberai-engg/task-board 0.3.2 → 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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +40 -34
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +41 -35
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
317
|
-
|
|
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
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
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 };
|
|
@@ -2014,8 +2019,9 @@ function TaskBoard({
|
|
|
2014
2019
|
renderCreateTask
|
|
2015
2020
|
}) {
|
|
2016
2021
|
const { columns, features, service } = useTaskBoardContext();
|
|
2017
|
-
const
|
|
2018
|
-
const
|
|
2022
|
+
const isDraggingRef = useRef8(false);
|
|
2023
|
+
const board = useTaskBoard(isDraggingRef);
|
|
2024
|
+
const actions = useTaskActions(board.tasks, board.setTasks, board.fetchTasks, isDraggingRef);
|
|
2019
2025
|
const { copiedTaskId, copyShareLink } = useShareLink();
|
|
2020
2026
|
const [selectedTask, setSelectedTask] = useState9(null);
|
|
2021
2027
|
const [createForStatus, setCreateForStatus] = useState9("");
|
|
@@ -2161,7 +2167,7 @@ function TaskBoard({
|
|
|
2161
2167
|
onSetFilterTags: setFilterTags
|
|
2162
2168
|
}
|
|
2163
2169
|
),
|
|
2164
|
-
board.boardLoading ? /* @__PURE__ */ jsx15(BoardSkeleton, {}) : /* @__PURE__ */ jsx15("div", { className: "flex-1 min-h-0 eb-tb-board-scroll overflow-
|
|
2170
|
+
board.boardLoading ? /* @__PURE__ */ jsx15(BoardSkeleton, {}) : /* @__PURE__ */ jsx15("div", { className: "flex-1 min-h-0 eb-tb-board-scroll overflow-y-hidden pb-4", children: /* @__PURE__ */ jsx15(DragDropContext, { onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsx15("div", { className: "flex gap-4 min-w-max h-full", children: columns.map((col) => {
|
|
2165
2171
|
const allColumnTasks = board.tasks[col.key] || [];
|
|
2166
2172
|
const columnTasks = filterTags.length > 0 ? allColumnTasks.filter((t) => {
|
|
2167
2173
|
const taskTags = t.tags || [];
|