From 3961a8a314e188e19e89cfd5af4a040d45d46152 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Tue, 17 Nov 2020 14:16:53 -0800 Subject: [PATCH] Refactor templateCopy --- webapp/src/viewModel/boardTree.ts | 2 +- webapp/src/viewModel/cardTree.ts | 12 +++--------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/webapp/src/viewModel/boardTree.ts b/webapp/src/viewModel/boardTree.ts index 9911b0010..a285401d8 100644 --- a/webapp/src/viewModel/boardTree.ts +++ b/webapp/src/viewModel/boardTree.ts @@ -408,7 +408,7 @@ class MutableBoardTree implements BoardTree { } templateCopy(): MutableBoardTree { - const [newBlocks, newBoard] = OctoUtils.duplicateBlockTree(this.allBlocks, this.board.id) + const [newBlocks, newBoard] = OctoUtils.duplicateBlockTree(this.rawBlocks, this.board.id) const boardTree = new MutableBoardTree(newBoard.id) boardTree.incrementalUpdate(newBlocks) diff --git a/webapp/src/viewModel/cardTree.ts b/webapp/src/viewModel/cardTree.ts index 1ec470da6..89385b48c 100644 --- a/webapp/src/viewModel/cardTree.ts +++ b/webapp/src/viewModel/cardTree.ts @@ -58,16 +58,10 @@ class MutableCardTree implements CardTree { } templateCopy(): MutableCardTree { - const card = this.card.duplicate() + const [newBlocks, newCard] = OctoUtils.duplicateBlockTree(this.rawBlocks, this.card.id) - const contents: IOrderedBlock[] = this.contents.map((content) => { - const copy = MutableBlock.duplicate(content) - copy.parentId = card.id - return copy as IOrderedBlock - }) - - const cardTree = new MutableCardTree(card.id) - cardTree.incrementalUpdate([card, ...contents]) + const cardTree = new MutableCardTree(newCard.id) + cardTree.incrementalUpdate(newBlocks) return cardTree } }