Browse Source

fix: Could not find a page named error

Peng Xiao 3 years ago
parent
commit
5502959b67

+ 0 - 10
tldraw/packages/core/src/lib/TLApi/TLApi.ts

@@ -10,16 +10,6 @@ export class TLApi<S extends TLShape = TLShape, K extends TLEventMap = TLEventMa
     this.app = app
   }
 
-  /**
-   * Set the current page.
-   *
-   * @param page The new current page or page id.
-   */
-  changePage = (page: string | TLPage<S, K>): this => {
-    this.app.setCurrentPage(page)
-    return this
-  }
-
   editShape = (shape: string | S | undefined): this => {
     this.app.transition('select').selectedTool.transition('editingShape', { shape })
     return this

+ 3 - 6
tldraw/packages/core/src/lib/TLApp/TLApp.ts

@@ -283,7 +283,9 @@ export class TLApp<
     ['page', new TLPage(this, { id: 'page', name: 'page', shapes: [], bindings: {} })],
   ])
 
-  @observable currentPageId = 'page'
+  @computed get currentPageId() {
+    return this.pages.keys().next().value
+  }
 
   @computed get currentPage(): TLPage<S, K> {
     return this.getPageById(this.currentPageId)
@@ -295,11 +297,6 @@ export class TLApp<
     return page
   }
 
-  @action setCurrentPage(page: string | TLPage<S, K>): this {
-    this.currentPageId = typeof page === 'string' ? page : page.id
-    return this
-  }
-
   @action addPages(pages: TLPage<S, K>[]): this {
     pages.forEach(page => this.pages.set(page.id, page))
     this.persist()

+ 2 - 4
tldraw/packages/core/src/lib/TLHistory.ts

@@ -155,13 +155,11 @@ export class TLHistory<S extends TLShape = TLShape, K extends TLEventMap = TLEve
         }
       }
 
-      // Any pages remaining in the pages map need to be removed
-      if (pagesMap.size > 0) this.app.removePages(Array.from(pagesMap.values()))
-
       // Add any new pages
       if (pagesToAdd.length > 0) this.app.addPages(pagesToAdd)
 
-      this.app.setCurrentPage(currentPageId)
+      // Any pages remaining in the pages map need to be removed
+      if (pagesMap.size > 0) this.app.removePages(Array.from(pagesMap.values()))
 
       this.app.setSelectedShapes(newSelectedIds).setErasingShapes([])
     } catch (e) {