Fix sharing

This commit is contained in:
Chen-I Lim 2021-03-26 21:26:34 -07:00
parent 0b479ff3ae
commit 7a50a9339e
2 changed files with 34 additions and 30 deletions

View file

@ -26,7 +26,7 @@ class WorkspaceComponent extends React.PureComponent<Props> {
render(): JSX.Element {
const {boardTree, workspaceTree, showBoard, showView, setLanguage} = this.props
Utils.assert(workspaceTree)
Utils.assert(workspaceTree || !this.props.readonly)
const element = (
<div className='WorkspaceComponent'>
{!this.props.readonly &&

View file

@ -202,37 +202,41 @@ class BoardPage extends React.Component<Props, State> {
private async sync(boardId: string = this.state.boardId, viewId: string | undefined = this.state.viewId) {
Utils.log(`sync start: ${boardId}`)
const workspace = await octoClient.getWorkspace()
if (!workspace) {
location.href = '/error?id=no_workspace'
if (!this.props.readonly) {
// Require workspace for editing, not for sharing (readonly)
const workspace = await octoClient.getWorkspace()
if (!workspace) {
location.href = '/error?id=no_workspace'
}
const workspaceTree = await MutableWorkspaceTree.sync()
const boardIds = [...workspaceTree.boards.map((o) => o.id), ...workspaceTree.boardTemplates.map((o) => o.id)]
this.setState({workspaceTree})
let boardIdsToListen: string[]
if (boardIds.length > 0) {
boardIdsToListen = ['', ...boardIds]
} else {
// Read-only view
boardIdsToListen = [this.state.boardId]
}
// Listen to boards plus all blocks at root (Empty string for parentId)
this.workspaceListener.open(
octoClient.workspaceId,
boardIdsToListen,
async (blocks) => {
Utils.log(`workspaceListener.onChanged: ${blocks.length}`)
this.incrementalUpdate(blocks)
},
() => {
Utils.log('workspaceListener.onReconnect')
this.sync()
},
)
}
const workspaceTree = await MutableWorkspaceTree.sync()
const boardIds = [...workspaceTree.boards.map((o) => o.id), ...workspaceTree.boardTemplates.map((o) => o.id)]
this.setState({workspaceTree})
let boardIdsToListen: string[]
if (boardIds.length > 0) {
boardIdsToListen = ['', ...boardIds]
} else {
// Read-only view
boardIdsToListen = [this.state.boardId]
}
// Listen to boards plus all blocks at root (Empty string for parentId)
this.workspaceListener.open(
octoClient.workspaceId,
boardIdsToListen,
async (blocks) => {
Utils.log(`workspaceListener.onChanged: ${blocks.length}`)
this.incrementalUpdate(blocks)
},
() => {
Utils.log('workspaceListener.onReconnect')
this.sync()
},
)
if (boardId) {
const boardTree = await MutableBoardTree.sync(boardId, viewId)