Skip to content

Instantly share code, notes, and snippets.

@tombarys
Last active August 6, 2022 18:46
Show Gist options
  • Save tombarys/2b095f43cdd5f7ce617c1cc94d6aa55f to your computer and use it in GitHub Desktop.
Save tombarys/2b095f43cdd5f7ce617c1cc94d6aa55f to your computer and use it in GitHub Desktop.
Erase Roam block (including children) V1.2
;; Warning: this plugin adds a "X Erase this block" item on both mobile and desktop Roam apps, but to activate Roam context menu on mobile, you need to install Victor Tabori's Long-tap script: https://gist.github.com/thesved/48cab2307cf0598fcc5cd37643d36cb4
;; 1) copy this block as children block `clojure` code block under parent containing {{[[roam/cljs]]}} anywhere on [[roam/cljs]] page
;; 2) confirm "Yes, I know what I am doing"
;; 3) restart Roam
;; 4) right-click on any block context menu (on a bullet)
;; 5) choose "X Erase this block" and confirm (attention: erases block including it's children; but do not worry: Cmd/Ctrl-Z works well)
(ns my-custom-roam-97
(:require
[roam.block :as block]))
(defn erase-block [block-uid]
(-> (block/delete
{:block {:uid block-uid}})
(.then #(js/console.log "ok"))
(.catch #(js/console.log "fail" %))))
(defn main []
(js/window.roamAlphaAPI.ui.blockContextMenu.addCommand
(clj->js
{:label "❌ Erase this block"
:callback (fn [ctx]
(if (or (js/confirm "Block erase: are you sure ?") js/window.roamAlphaAPI.platform.isMobileApp)
(erase-block
(:block-uid (js->clj ctx :keywordize-keys true)))))})))
(main)
@tombarys
Copy link
Author

tombarys commented Aug 6, 2022

Updated to V1.2 – added confirmation dialog for desktop, not yet functioning in Roam mobile app

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment