[fix] multiplayer (sorta) (#426)
* Fix multiplayer * Update TldrawApp.ts * Update TldrawApp.ts * Update TldrawApp.ts
This commit is contained in:
parent
0334ac0f30
commit
33acf03004
3 changed files with 27 additions and 11 deletions
|
@ -121,7 +121,7 @@ export function useMultiplayerState(roomId: string) {
|
|||
migrated?: boolean
|
||||
}>
|
||||
|
||||
// No doc? No problem. This was likely
|
||||
// No doc? No problem. This was likely a newer document
|
||||
if (doc) {
|
||||
const {
|
||||
document: {
|
||||
|
|
|
@ -357,14 +357,16 @@ const InnerTldraw = React.memo(function InnerTldraw({
|
|||
|
||||
const page = document.pages[appState.currentPageId]
|
||||
const pageState = document.pageStates[page.id]
|
||||
const { selectedIds } = state.document.pageStates[page.id]
|
||||
const { selectedIds } = pageState
|
||||
|
||||
const isHideBoundsShape =
|
||||
pageState.selectedIds.length === 1 &&
|
||||
selectedIds.length === 1 &&
|
||||
page.shapes[selectedIds[0]] &&
|
||||
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideBounds
|
||||
|
||||
const isHideResizeHandlesShape =
|
||||
selectedIds.length === 1 &&
|
||||
page.shapes[selectedIds[0]] &&
|
||||
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideResizeHandles
|
||||
|
||||
const isInSession = app.session !== undefined
|
||||
|
|
|
@ -548,15 +548,33 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
|||
this.useStore.setState((current) => {
|
||||
const { hoveredId, editingId, bindingId, selectedIds } = current.document.pageStates[pageId]
|
||||
|
||||
const next = {
|
||||
const keepShapes: Record<string, TDShape> = {}
|
||||
const keepBindings: Record<string, TDBinding> = {}
|
||||
|
||||
if (this.session) {
|
||||
selectedIds.forEach((id) => (keepShapes[id] = this.getShape(id)))
|
||||
Object.assign(keepBindings, this.bindings) // ROUGH
|
||||
}
|
||||
|
||||
if (editingId) {
|
||||
keepShapes[editingId] = this.getShape(editingId)
|
||||
}
|
||||
|
||||
const next: TDSnapshot = {
|
||||
...current,
|
||||
document: {
|
||||
...current.document,
|
||||
pages: {
|
||||
[pageId]: {
|
||||
...current.document.pages[pageId],
|
||||
shapes,
|
||||
bindings,
|
||||
shapes: {
|
||||
...shapes,
|
||||
...keepShapes,
|
||||
},
|
||||
bindings: {
|
||||
...bindings,
|
||||
...keepBindings,
|
||||
},
|
||||
},
|
||||
},
|
||||
pageStates: {
|
||||
|
@ -569,11 +587,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
|||
? undefined
|
||||
: hoveredId
|
||||
: undefined,
|
||||
editingId: editingId
|
||||
? shapes[editingId] === undefined
|
||||
? undefined
|
||||
: hoveredId
|
||||
: undefined,
|
||||
editingId: editingId,
|
||||
bindingId: bindingId
|
||||
? bindings[bindingId] === undefined
|
||||
? undefined
|
||||
|
|
Loading…
Reference in a new issue