Skip to content

Instantly share code, notes, and snippets.

@tombarys
Last active March 11, 2024 17:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tombarys/45b114564ca97c24e06008a1d88bea54 to your computer and use it in GitHub Desktop.
Save tombarys/45b114564ca97c24e06008a1d88bea54 to your computer and use it in GitHub Desktop.
Roam Plugin – Teleport task to Tomorrow :) – V2.2
;; Warning: this plugin adds a "→ Move to tomorrow" 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 "tomorrow" 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 tomorrow's Daily Page does not exist, it is created first
;;
;; My thanks to Josh Brown for helping me.
(ns my-custom-roam-12102022
(: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 " %))))
(def ms-in-day "Millisenconds in a day of 86400 seconds." (* 86400 1000))
(defn days-from-today [n]
(js/window.roamAlphaAPI.util.dateToPageUid (new js/Date (+ (.now js/Date) (* n ms-in-day)))))
(defn days-from-today-title [n]
(js/window.roamAlphaAPI.util.dateToPageTitle (new js/Date (+ (.now js/Date) (* n ms-in-day)))))
(defn main []
(js/window.roamAlphaAPI.ui.commandPalette.addCommand
(clj->js
{:label "Move to tomorrow"
: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 (days-from-today-title 1)}})
(.then #(js/console.log "Created new Daily Page!"))
(.catch (fn [error]
(js/console.log (.-message error)))))
(move-block
parent-uid (days-from-today 1)))))}))
(js/window.roamAlphaAPI.ui.blockContextMenu.addCommand
(clj->js
{:label "→ Move to tomorrow"
:callback
(fn [ctx]
(p/do
(-> (roam.page/create
{:page {:title (days-from-today-title 1)}})
(.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))
(days-from-today 1))))})))
(main)
@tombarys
Copy link
Author

RPReplay_Final1656061548.mp4

@tombarys
Copy link
Author

Updated to V1.2 (creates tomorrow's Daily Page if it does not exist).

@tombarys
Copy link
Author

tombarys commented Aug 14, 2022

Update to V2.0 – adds Command Palette action.

image

@tombarys
Copy link
Author

Updated today to reflect some RoamAlphaAPI changes and make it work again. :)

@tombarys
Copy link
Author

V2.2 – updated with better error handling.

@coyotespike
Copy link

Thank you for making this, have wanted it for a couple of years now! I added alt-t as my hotkey, super convenient.

@tombarys
Copy link
Author

Glad to hear that! ;) Have you seen my Nautilus extension?

@coyotespike
Copy link

Checking it out now, super cool!

@tombarys
Copy link
Author

Checking it out now, super cool!

Thanks, new features soon!

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