Detect if incemental update resulted in changes

This commit is contained in:
Chen-I Lim 2020-11-06 15:10:36 -08:00
parent c00902cb6b
commit 7d2d1c252a
5 changed files with 22 additions and 12 deletions

View File

@ -61,8 +61,9 @@ class CardDetail extends React.Component<Props, State> {
async (blocks) => {
Utils.log(`cardListener.onChanged: ${blocks.length}`)
const newCardTree = cardTree.mutableCopy()
newCardTree.incrementalUpdate(blocks)
this.setState({cardTree: newCardTree, title: newCardTree.card.title})
if (newCardTree.incrementalUpdate(blocks)) {
this.setState({cardTree: newCardTree, title: newCardTree.card.title})
}
},
async () => {
Utils.log('cardListener.onReconnect')

View File

@ -189,14 +189,20 @@ export default class BoardPage extends React.Component<Props, State> {
private incrementalUpdate(blocks: IBlock[]) {
const {workspaceTree, boardTree, viewId} = this.state
let newState = {workspaceTree, boardTree}
const newWorkspaceTree = workspaceTree.mutableCopy()
newWorkspaceTree.incrementalUpdate(blocks)
if (newWorkspaceTree.incrementalUpdate(blocks)) {
newState = {...newState, workspaceTree: newWorkspaceTree}
}
const newBoardTree = boardTree ? boardTree.mutableCopy() : new MutableBoardTree(this.state.boardId)
newBoardTree.incrementalUpdate(blocks)
newBoardTree.setActiveView(viewId)
if (newBoardTree.incrementalUpdate(blocks)) {
newBoardTree.setActiveView(viewId)
newState = {...newState, boardTree: newBoardTree}
}
this.setState({workspaceTree: newWorkspaceTree, boardTree: newBoardTree})
this.setState(newState)
}
// IPageController

View File

@ -58,13 +58,14 @@ class MutableBoardTree implements BoardTree {
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
}
incrementalUpdate(updatedBlocks: IBlock[]) {
incrementalUpdate(updatedBlocks: IBlock[]): boolean {
const relevantBlocks = updatedBlocks.filter((block) => block.id === this.boardId || block.parentId === this.boardId)
if (relevantBlocks.length < 1) {
return
return false
}
this.rawBlocks = OctoUtils.mergeBlocks(this.rawBlocks, relevantBlocks)
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
return true
}
private rebuild(blocks: IMutableBlock[]) {

View File

@ -29,13 +29,14 @@ class MutableCardTree implements CardTree {
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
}
incrementalUpdate(updatedBlocks: IBlock[]) {
incrementalUpdate(updatedBlocks: IBlock[]): boolean {
const relevantBlocks = updatedBlocks.filter((block) => block.id === this.cardId || block.parentId === this.cardId)
if (relevantBlocks.length < 1) {
return
return false
}
this.rawBlocks = OctoUtils.mergeBlocks(this.rawBlocks, relevantBlocks)
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
return true
}
private rebuild(blocks: IBlock[]) {

View File

@ -26,13 +26,14 @@ class MutableWorkspaceTree {
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
}
incrementalUpdate(updatedBlocks: IBlock[]) {
incrementalUpdate(updatedBlocks: IBlock[]): boolean {
const relevantBlocks = updatedBlocks.filter((block) => block.type === 'board' || block.type === 'view')
if (relevantBlocks.length < 1) {
return
return false
}
this.rawBlocks = OctoUtils.mergeBlocks(this.rawBlocks, updatedBlocks)
this.rebuild(OctoUtils.hydrateBlocks(this.rawBlocks))
return true
}
private rebuild(blocks: IBlock[]) {