Browse Source

feat: add create whiteboard button

Konstantinos Kaloutas 2 years ago
parent
commit
a06594a79d

+ 2 - 0
src/main/frontend/extensions/tldraw.cljs

@@ -65,6 +65,8 @@
    :isWhiteboardPage model/whiteboard-page?
    :saveAsset save-asset-handler
    :makeAssetUrl editor-handler/make-asset-url
+   :addNewWhiteboard (fn [page-name]
+                       (whiteboard-handler/create-new-whiteboard-page! page-name))
    :addNewBlock (fn [content]
                   (str (whiteboard-handler/add-new-block! name content)))
    :sidebarAddBlock (fn [uuid type]

+ 1 - 0
tldraw/apps/tldraw-logseq/src/lib/logseq-context.ts

@@ -26,6 +26,7 @@ export interface LogseqContextValue {
       query: string,
       filters: { 'pages?': boolean; 'blocks?': boolean; 'files?': boolean }
     ) => Promise<SearchResult>
+    addNewWhiteboard: (pageName: string) => void
     addNewBlock: (content: string) => string // returns the new block uuid
     queryBlockByUUID: (uuid: string) => any
     isWhiteboardPage: (pageName: string) => boolean

+ 17 - 2
tldraw/apps/tldraw-logseq/src/lib/shapes/LogseqPortalShape.tsx

@@ -54,7 +54,7 @@ const LogseqTypeTag = ({
   type,
   active,
 }: {
-  type: 'B' | 'P' | 'BA' | 'PA' | 'WP' | 'BS' | 'PS'
+  type: 'B' | 'P' | 'BA' | 'PA' | 'WA' | 'WP' | 'BS' | 'PS'
   active?: boolean
 }) => {
   const nameMapping = {
@@ -63,6 +63,7 @@ const LogseqTypeTag = ({
     WP: 'whiteboard',
     BA: 'new-block',
     PA: 'new-page',
+    WA: 'new-whiteboard',
     BS: 'block-search',
     PS: 'page-search',
   }
@@ -470,7 +471,7 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
         ),
       })
 
-      // New page option when no exact match
+      // New page or whiteboard option when no exact match
       if (!searchResult?.pages?.some(p => p.toLowerCase() === q.toLowerCase()) && q) {
         options.push({
           actionIcon: 'circle-plus',
@@ -485,6 +486,20 @@ export class LogseqPortalShape extends TLBoxShape<LogseqPortalShapeProps> {
               {q}
             </div>
           ),
+        },{
+          actionIcon: 'circle-plus',
+          onChosen: () => {
+            handlers?.addNewWhiteboard(q)
+            finishCreating(q)
+            return true
+          },
+          element: (
+            <div className="tl-quick-search-option-row">
+              <LogseqTypeTag active type="WA" />
+              <strong>New whiteboard:</strong>
+              {q}
+            </div>
+          ),
         })
       }