Switch board - attach listener to new board

This commit is contained in:
Chen-I Lim 2020-10-12 19:21:58 -07:00
parent c92f5a8ec0
commit 057007d21c

View file

@ -23,8 +23,8 @@ class BoardPage implements IPageController {
groupByButton: HTMLElement groupByButton: HTMLElement
groupByLabel: HTMLElement groupByLabel: HTMLElement
boardId: string boardId?: string
viewId: string viewId?: string
workspaceTree: WorkspaceTree workspaceTree: WorkspaceTree
boardTree: BoardTree boardTree: BoardTree
@ -52,18 +52,12 @@ class BoardPage implements IPageController {
this.workspaceTree = new WorkspaceTree(this.octo) this.workspaceTree = new WorkspaceTree(this.octo)
this.boardId = queryString.get("id") const boardId = queryString.get("id")
this.viewId = queryString.get("v") const viewId = queryString.get("v")
console.log(`BoardPage. boardId: ${this.boardId}`) console.log(`BoardPage. boardId: ${this.boardId}`)
if (this.boardId) { if (boardId) {
this.boardTree = new BoardTree(this.octo, this.boardId) this.attachToBoard(boardId, viewId)
this.sync()
this.boardListener.open(this.boardId, (blockId: string) => {
console.log(`octoListener.onChanged: ${blockId}`)
this.sync()
})
} else { } else {
// Show error // 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() { async sync() {
const { workspaceTree, boardTree } = this const { workspaceTree, boardTree } = this
@ -228,13 +236,12 @@ class BoardPage implements IPageController {
} }
showBoard(boardId: string) { 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)}` const newUrl = window.location.protocol + "//" + window.location.host + window.location.pathname + `?id=${encodeURIComponent(boardId)}`
window.history.pushState({ path: newUrl }, "", newUrl) window.history.pushState({ path: newUrl }, "", newUrl)
this.boardTree = new BoardTree(this.octo, boardId) this.attachToBoard(boardId)
this.sync()
} }
showView(viewId: string) { showView(viewId: string) {