From 057007d21c21711510f74d25762c4f9d3502f170 Mon Sep 17 00:00:00 2001 From: Chen-I Lim Date: Mon, 12 Oct 2020 19:21:58 -0700 Subject: [PATCH] Switch board - attach listener to new board --- src/client/boardPage.tsx | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/src/client/boardPage.tsx b/src/client/boardPage.tsx index bfab5475f..39e116c50 100644 --- a/src/client/boardPage.tsx +++ b/src/client/boardPage.tsx @@ -23,8 +23,8 @@ class BoardPage implements IPageController { groupByButton: HTMLElement groupByLabel: HTMLElement - boardId: string - viewId: string + boardId?: string + viewId?: string workspaceTree: WorkspaceTree boardTree: BoardTree @@ -52,18 +52,12 @@ class BoardPage implements IPageController { this.workspaceTree = new WorkspaceTree(this.octo) - this.boardId = queryString.get("id") - this.viewId = queryString.get("v") + const boardId = queryString.get("id") + const viewId = queryString.get("v") console.log(`BoardPage. boardId: ${this.boardId}`) - if (this.boardId) { - this.boardTree = new BoardTree(this.octo, this.boardId) - this.sync() - - this.boardListener.open(this.boardId, (blockId: string) => { - console.log(`octoListener.onChanged: ${blockId}`) - this.sync() - }) + if (boardId) { + this.attachToBoard(boardId, viewId) } else { // Show error } @@ -185,6 +179,20 @@ class BoardPage implements IPageController { } } + private attachToBoard(boardId: string, viewId?: string) { + this.boardId = boardId + this.viewId = viewId + + this.boardTree = new BoardTree(this.octo, boardId) + + this.boardListener.open(boardId, (blockId: string) => { + console.log(`octoListener.onChanged: ${blockId}`) + this.sync() + }) + + this.sync() + } + async sync() { const { workspaceTree, boardTree } = this @@ -228,13 +236,12 @@ class BoardPage implements IPageController { } showBoard(boardId: string) { - if (this.boardTree.board.id === boardId) { return } + if (this.boardTree?.board?.id === boardId) { return } const newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + `?id=${encodeURIComponent(boardId)}` window.history.pushState({ path: newUrl }, "", newUrl) - this.boardTree = new BoardTree(this.octo, boardId) - this.sync() + this.attachToBoard(boardId) } showView(viewId: string) {