feat: g t for tomorrow, g p for prev journal, g n for next journal

pull/3052/head
Tienson Qin 2021-11-03 00:08:46 +08:00
parent 7c061e4605
commit 311f9701ac
3 changed files with 60 additions and 3 deletions

View File

@ -19,6 +19,7 @@
[frontend.extensions.graph :as graph]
[frontend.extensions.pdf.assets :as pdf-assets]
[frontend.format.mldoc :as mldoc]
[frontend.format.block :as format-block]
[frontend.handler.common :as common-handler]
[frontend.handler.config :as config-handler]
[frontend.handler.editor :as editor-handler]
@ -300,9 +301,8 @@
(db/entity repo))
(do
(when-not (db/entity repo [:block/name page-name])
(db/transact! repo [{:block/name page-name
:block/original-name path-page-name
:block/uuid (db/new-block-id)}]))
(let [m (format-block/page-name->map path-page-name true)]
(db/transact! repo [m])))
(db/pull [:block/name page-name])))
{:keys [title emoji] :as properties} (:block/properties page)
page-name (:block/name page)

View File

@ -0,0 +1,41 @@
(ns frontend.handler.journal
(:require [clojure.string :as string]
[frontend.date :as date]
[frontend.handler.editor :as editor-handler]
[frontend.handler.route :as route-handler]
[frontend.state :as state]
[frontend.util :as util]
[cljs-time.coerce :as tc]
[cljs-time.core :as t]))
(defn- redirect-to-journal!
[page]
(when (and page (state/enable-journals? (state/get-current-repo)))
(prn {:page page})
(route-handler/redirect! {:to :page
:path-params {:name page}})
(editor-handler/insert-first-page-block-if-not-exists! page)))
(defn go-to-tomorrow!
[]
(redirect-to-journal! (date/tomorrow)))
(defn- get-current-journal
[]
(let [current-page (state/get-current-page)]
(or (date/journal-title->long current-page)
(util/time-ms))))
(defn go-to-prev-journal!
[]
(let [current-journal (get-current-journal)
day (tc/from-long current-journal)
page (date/journal-name (t/minus day (t/days 1)))]
(redirect-to-journal! page)))
(defn go-to-next-journal!
[]
(let [current-journal (get-current-journal)
day (tc/from-long current-journal)
page (date/journal-name (t/plus day (t/days 1)))]
(redirect-to-journal! page)))

View File

@ -7,6 +7,7 @@
[frontend.handler.history :as history]
[frontend.handler.page :as page-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.journal :as journal-handler]
[frontend.handler.search :as search-handler]
[frontend.handler.ui :as ui-handler]
[frontend.handler.plugin :as plugin-handler]
@ -351,6 +352,18 @@
{:desc "Go to keyboard shortcuts"
:binding "g s"
:fn #(route-handler/redirect! {:to :shortcut-setting})}
:go/tomorrow
{:desc "Go to tomorrow"
:binding "g t"
:fn journal-handler/go-to-tomorrow!}
:go/next-journal
{:desc "Go to next journal"
:binding "g n"
:fn journal-handler/go-to-next-journal!}
:go/prev-journal
{:desc "Go to previous journal"
:binding "g p"
:fn journal-handler/go-to-prev-journal!}
:ui/toggle-document-mode
{:desc "Toggle document mode"
:binding "t d"
@ -509,6 +522,9 @@
^{:doc "Others"}
[:go/home
:go/journals
:go/tomorrow
:go/next-journal
:go/prev-journal
:command/run
:command-palette/toggle
:sidebar/clear