Sidebar: Switch to board when adding

This commit is contained in:
Chen-I Lim 2020-10-12 19:28:15 -07:00
parent 057007d21c
commit 8ac37839a6
2 changed files with 13 additions and 4 deletions

View file

@ -1,5 +1,6 @@
import React from "react"
import { Board } from "../board"
import { BoardTree } from "../boardTree"
import { Mutator } from "../mutator"
import { IPageController } from "../octoTypes"
import { WorkspaceTree } from "../workspaceTree"
@ -7,7 +8,8 @@ import { WorkspaceTree } from "../workspaceTree"
type Props = {
mutator: Mutator
pageController: IPageController
workspaceTree: WorkspaceTree
workspaceTree: WorkspaceTree,
boardTree?: BoardTree
}
class Sidebar extends React.Component<Props> {
@ -42,9 +44,16 @@ class Sidebar extends React.Component<Props> {
}
async addBoardClicked() {
const { mutator } = this.props
const { mutator, boardTree, pageController } = this.props
const oldBoardId = boardTree?.board?.id
const board = new Board()
await mutator.insertBlock(
board,
"add board",
async () => { pageController.showBoard(board.id) },
async () => { if (oldBoardId) { pageController.showBoard(oldBoardId) } })
await mutator.insertBlock(board)
}
}

View file

@ -17,11 +17,11 @@ type Props = {
class WorkspaceComponent extends React.Component<Props> {
render() {
const { mutator, workspaceTree, pageController } = this.props
const { mutator, boardTree, workspaceTree, pageController } = this.props
const element =
<div className="octo-workspace">
<Sidebar mutator={mutator} pageController={pageController} workspaceTree={workspaceTree}></Sidebar>
<Sidebar mutator={mutator} pageController={pageController} workspaceTree={workspaceTree} boardTree={boardTree}></Sidebar>
{this.mainComponent()}
</div>