feat: create new list immediately adds to the board

This commit is contained in:
Henry
2024-08-13 14:53:21 +01:00
parent 1e3a903211
commit 18de6f03d8
4 changed files with 108 additions and 81 deletions

View File

@@ -12,6 +12,7 @@ import { usePopup } from "~/providers/popup";
import {
type GetBoardByIdOutput,
type NewCardInput,
type NewListInput,
type ReorderCardInput,
type ReorderListInput,
} from "~/types/router.types";
@@ -22,6 +23,7 @@ interface BoardContextProps {
updateList: (params: ReorderListInput) => void;
updateCard: (params: ReorderCardInput) => void;
addCard: (params: NewCardInput) => void;
addList: (params: NewListInput) => void;
refetchBoard: () => void;
}
@@ -129,6 +131,23 @@ export const BoardProvider: React.FC<{ children: ReactNode }> = ({
setBoardData({ ...boardData, lists: updatedLists });
};
const addList = ({ name, boardPublicId }: NewListInput) => {
if (!boardData) return;
const newList = {
publicId: generateUID(),
name,
boardId: 1,
boardPublicId,
cards: [],
index: boardData.lists.length,
};
const updatedLists = [...boardData.lists, newList];
setBoardData({ ...boardData, lists: updatedLists });
};
const updateList = ({
boardId,
listId,
@@ -159,6 +178,7 @@ export const BoardProvider: React.FC<{ children: ReactNode }> = ({
updateList,
updateCard,
addCard,
addList,
refetchBoard,
}}
>