Created
April 17, 2023 07:58
-
-
Save tombarys/1465f99f5e4dfdb5f33c3d70e32b272d to your computer and use it in GitHub Desktop.
Move Roam block to today Daily Page (from any page)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Warning: this plugin adds a "→ Move to today" item on both mobile and desktop Roam apps | |
;; to the context plugin menu and to command pallete (Mac: Cmd-P / Windows: Ctrl-P, then search for "Move" or "today" etc.). | |
;; To activate Roam context menu on mobile, you need to install Victor Tabori's Long-tap script first: | |
;; https://gist.github.com/thesved/48cab2307cf0598fcc5cd37643d36cb4 | |
;; Installation: | |
;; 1) copy this block as children block `clojure` code block under parent containing {{[[roam/cljs]]}} anywhere | |
;; in [[roam/cljs]] page | |
;; 2) confirm "Yes, I know what I am doing" | |
;; 3) restart Roam | |
;; 4) desktop: right-click on any block context menu (on the bullet) / mobile: long-tap the bullet | |
;; 5) choose Plugins/Move to tomorrow (attention: moves block including it's children; but do not worry: Cmd/Ctrl-Z works well) | |
;; PS: if the today's Daily Page does not exist, it is created first | |
;; | |
;; My thanks to Josh Brown for helping me. | |
(ns my-custom-roam-16042023 | |
(:require | |
[roam.block :as block] | |
[roam.page :as page] | |
[promesa.core :as p])) | |
(defn move-block [block-uid parent-uid] | |
(-> (block/move | |
{:location {:parent-uid parent-uid | |
:order 0} | |
:block {:uid block-uid}}) | |
(.then #(js/console.log "Block moved!")) | |
(.catch #(js/console.log "Block move failed " %)))) | |
(defn today [] | |
(js/window.roamAlphaAPI.util.dateToPageUid (new js/Date (.now js/Date)))) | |
(defn today-title [] | |
(js/window.roamAlphaAPI.util.dateToPageTitle (new js/Date (.now js/Date)))) | |
(defn main [] | |
(js/window.roamAlphaAPI.ui.commandPalette.addCommand | |
(clj->js | |
{:label "Move to today" | |
:callback | |
(fn [e] | |
(let [parent-uid (:block-uid (js->clj (js/window.roamAlphaAPI.ui.getFocusedBlock) :keywordize-keys true))] | |
(p/do | |
(-> | |
(roam.page/create | |
{:page {:title (today-title)}}) | |
(.then #(js/console.log "Created new Daily Page!")) | |
(.catch (fn [error] | |
(js/console.log (.-message error))))) | |
(move-block | |
parent-uid (today)))))})) | |
(js/window.roamAlphaAPI.ui.blockContextMenu.addCommand | |
(clj->js | |
{:label "↧ Move to today" | |
:callback | |
(fn [ctx] | |
(p/do | |
(-> (roam.page/create | |
{:page {:title (today-title)}}) | |
(.then #(js/console.log "Created new Daily Page!")) | |
(.catch (fn [error] | |
(js/console.log (.-message error))))) | |
(move-block | |
(:block-uid (js->clj ctx :keywordize-keys true)) | |
(today))))}))) | |
(main) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment