Last active
March 11, 2024 17:56
-
-
Save tombarys/45b114564ca97c24e06008a1d88bea54 to your computer and use it in GitHub Desktop.
Roam Plugin – Teleport task to Tomorrow :) – V2.2
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 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) |
Thank you for making this, have wanted it for a couple of years now! I added alt-t as my hotkey, super convenient.
Glad to hear that! ;) Have you seen my Nautilus extension?
Checking it out now, super cool!
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
V2.2 – updated with better error handling.