diff --git a/client/src/context/BoardContext.tsx b/client/src/context/BoardContext.tsx index 76b3385..bf450a4 100644 --- a/client/src/context/BoardContext.tsx +++ b/client/src/context/BoardContext.tsx @@ -98,22 +98,25 @@ export const BoardProvider = ({ children }: { children: ReactNode }) => { }; const handleDownloadTemplate = async (board: Board) => { - await postNewBoard(board); - - setUserBoards((prev) => [...prev, board]); - - board.cards!.forEach(async (card) => { - if (card.id !== "0") { - console.log("POSTING", card.id); - const postResponse = await postNewCard( - { ...card, id: uuidv4() }, - board!.uuid! - ); - console.log("POST RESPONSE", postResponse); - } - }); - - setSelectedBoard(null); + if (!userBoards.some((myBoard) => myBoard.name === board.name)) { + await postNewBoard(board); + + setUserBoards((prev) => [...prev, board]); + + board.cards!.forEach(async (card) => { + if (card.id !== "0") { + console.log("POSTING", card.id); + const postResponse = await postNewCard( + { ...card, id: uuidv4() }, + board!.uuid! + ); + console.log("POST RESPONSE", postResponse); + } + }); + setSelectedBoard(null); + } else { + // TOAST ERRROR MESSAGE SAYING "THIS TEMPLATE WAS ALREADY DOWNLOADED" + } }; const handleUpdateCard = async (newCard: Card) => { diff --git a/client/src/context/TemplateContext.tsx b/client/src/context/TemplateContext.tsx index f6d7dbc..292aa5c 100644 --- a/client/src/context/TemplateContext.tsx +++ b/client/src/context/TemplateContext.tsx @@ -56,7 +56,6 @@ export const TemplateProvider = ({ children }: { children: ReactNode }) => { // Above component set up with async/await const handleUploadNewTemplate = async (template: Board) => { - console.log("CARDSSSS", template.cards); try { await postNewTemplate(template);