Skip to content

Commit

Permalink
make task IDs not depend on list length
Browse files Browse the repository at this point in the history
  • Loading branch information
HumorousBrine committed Dec 1, 2023
1 parent 12f5d04 commit 47da871
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions client/src/components/Board/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ export enum Tool {
Arrow
};

let lastTaskID = 5;
let lastArrowID = 5;

export default function Board() {
const [board, setBoard] = useState<Board>({
id: 1,
Expand Down Expand Up @@ -222,8 +225,9 @@ export default function Board() {
const handleAddNewTask = (e: React.MouseEvent<HTMLDivElement>) => {
// TODO: Technically, we should do more calculations to account for a panned canvas
const { clientX, clientY } = e.nativeEvent;
lastTaskID++;
const newTask: Task = {
id: board.tasks.length + 1, // TODO: Better way of assigning task IDs
id: lastTaskID,
title: "Untitled task",
description: "",
width: 200,
Expand Down Expand Up @@ -271,8 +275,9 @@ export default function Board() {
};

const addArrow = (firstTaskId: number, secondTaskId: number) => {
lastArrowID++;
const newArrow: Arrow = {
id: board.arrows.length + 1, // TODO: Better way of assigning arrow IDs
id: lastArrowID,
from: firstTaskId,
to: secondTaskId,
color: arrowToolState.color
Expand Down

0 comments on commit 47da871

Please sign in to comment.