[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
|
migrated?: boolean
|
||||||
}>
|
}>
|
||||||
|
|
||||||
// No doc? No problem. This was likely
|
// No doc? No problem. This was likely a newer document
|
||||||
if (doc) {
|
if (doc) {
|
||||||
const {
|
const {
|
||||||
document: {
|
document: {
|
||||||
|
|
|
@ -357,14 +357,16 @@ const InnerTldraw = React.memo(function InnerTldraw({
|
||||||
|
|
||||||
const page = document.pages[appState.currentPageId]
|
const page = document.pages[appState.currentPageId]
|
||||||
const pageState = document.pageStates[page.id]
|
const pageState = document.pageStates[page.id]
|
||||||
const { selectedIds } = state.document.pageStates[page.id]
|
const { selectedIds } = pageState
|
||||||
|
|
||||||
const isHideBoundsShape =
|
const isHideBoundsShape =
|
||||||
pageState.selectedIds.length === 1 &&
|
selectedIds.length === 1 &&
|
||||||
|
page.shapes[selectedIds[0]] &&
|
||||||
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideBounds
|
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideBounds
|
||||||
|
|
||||||
const isHideResizeHandlesShape =
|
const isHideResizeHandlesShape =
|
||||||
selectedIds.length === 1 &&
|
selectedIds.length === 1 &&
|
||||||
|
page.shapes[selectedIds[0]] &&
|
||||||
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideResizeHandles
|
TLDR.getShapeUtil(page.shapes[selectedIds[0]].type).hideResizeHandles
|
||||||
|
|
||||||
const isInSession = app.session !== undefined
|
const isInSession = app.session !== undefined
|
||||||
|
|
|
@ -548,15 +548,33 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
this.useStore.setState((current) => {
|
this.useStore.setState((current) => {
|
||||||
const { hoveredId, editingId, bindingId, selectedIds } = current.document.pageStates[pageId]
|
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,
|
...current,
|
||||||
document: {
|
document: {
|
||||||
...current.document,
|
...current.document,
|
||||||
pages: {
|
pages: {
|
||||||
[pageId]: {
|
[pageId]: {
|
||||||
...current.document.pages[pageId],
|
...current.document.pages[pageId],
|
||||||
shapes,
|
shapes: {
|
||||||
bindings,
|
...shapes,
|
||||||
|
...keepShapes,
|
||||||
|
},
|
||||||
|
bindings: {
|
||||||
|
...bindings,
|
||||||
|
...keepBindings,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
pageStates: {
|
pageStates: {
|
||||||
|
@ -569,11 +587,7 @@ export class TldrawApp extends StateManager<TDSnapshot> {
|
||||||
? undefined
|
? undefined
|
||||||
: hoveredId
|
: hoveredId
|
||||||
: undefined,
|
: undefined,
|
||||||
editingId: editingId
|
editingId: editingId,
|
||||||
? shapes[editingId] === undefined
|
|
||||||
? undefined
|
|
||||||
: hoveredId
|
|
||||||
: undefined,
|
|
||||||
bindingId: bindingId
|
bindingId: bindingId
|
||||||
? bindings[bindingId] === undefined
|
? bindings[bindingId] === undefined
|
||||||
? undefined
|
? undefined
|
||||||
|
|
Loading…
Reference in a new issue