Skip to content

Commit

Permalink
feat: add a slash command to insert own name link
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Apr 11, 2022
1 parent f1bcdf5 commit ad53214
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
6 changes: 6 additions & 0 deletions src/cljs/athens/electron/db_picker.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
(selected-db db)))


(rf/reg-sub
:db-picker/remote-db?
(fn [db _]
(remote-db? db)))


;; Add a db to the db picker list and select it as the current db.
;; Adding a db with the same id will overwrite the previous one.
(rf/reg-event-fx
Expand Down
32 changes: 19 additions & 13 deletions src/cljs/athens/views/blocks/textarea_keydown.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
["@material-ui/icons/DesktopWindows" :default DesktopWindows]
["@material-ui/icons/Done" :default Done]
["@material-ui/icons/FlipToFront" :default FlipToFront]
["@material-ui/icons/Person" :default Person]
["@material-ui/icons/Timer" :default Timer]
["@material-ui/icons/Today" :default Today]
["@material-ui/icons/ViewDayRounded" :default ViewDayRounded]
Expand Down Expand Up @@ -97,16 +98,21 @@
;; Dropdown: inline-search and slash commands

;; TODO: some expansions require caret placement after
(def slash-options
[["Add Todo" Done "{{[[TODO]]}} " "cmd-enter" nil]
["Current Time" Timer (fn [] (.. (js/Date.) (toLocaleTimeString [] (clj->js {"timeStyle" "short"})))) nil nil]
["Today" Today (fn [] (str "[[" (:title (dates/get-day 0)) "]] ")) nil nil]
["Tomorrow" Today (fn [] (str "[[" (:title (dates/get-day -1)) "]]")) nil nil]
["Yesterday" Today (fn [] (str "[[" (:title (dates/get-day 1)) "]]")) nil nil]
["YouTube Embed" YouTube "{{[[youtube]]: }}" nil 2]
["iframe Embed" DesktopWindows "{{iframe: }}" nil 2]
["Block Embed" ViewDayRounded "{{[[embed]]: (())}}" nil 4]
["Template" FlipToFront ";;" nil nil]])
(defn slash-options
[]
(cond->
[["Add Todo" Done "{{[[TODO]]}} " "cmd-enter" nil]
["Current Time" Timer (fn [] (.. (js/Date.) (toLocaleTimeString [] (clj->js {"timeStyle" "short"})))) nil nil]
["Today" Today (fn [] (str "[[" (:title (dates/get-day 0)) "]] ")) nil nil]
["Tomorrow" Today (fn [] (str "[[" (:title (dates/get-day -1)) "]]")) nil nil]
["Yesterday" Today (fn [] (str "[[" (:title (dates/get-day 1)) "]]")) nil nil]
["YouTube Embed" YouTube "{{[[youtube]]: }}" nil 2]
["iframe Embed" DesktopWindows "{{iframe: }}" nil 2]
["Block Embed" ViewDayRounded "{{[[embed]]: (())}}" nil 4]
["Template" FlipToFront ";;" nil nil]]
@(subscribe [:db-picker/remote-db?])
(conj (let [username (:username @(rf/subscribe [:presence/current-user]))]
[(str "Me (" username ")") Person (fn [] (str "[[" username "]] ")) nil nil]))))


;; [ "Block Embed" #(str "[[" (:title (dates/get-day 1)) "]]")]
Expand All @@ -118,10 +124,10 @@
(defn filter-slash-options
[query]
(if (blank? query)
slash-options
(slash-options)
(filterv (fn [[text]]
(includes? (lower-case text) (lower-case query)))
slash-options)))
(slash-options))))


(defn update-query
Expand Down Expand Up @@ -770,7 +776,7 @@
:search/index 0
:search/query ""
:search/type :slash
:search/results slash-options)
:search/results (slash-options))
(and (= key "#") (nil? type)) (swap! state assoc
:search/index 0
:search/query ""
Expand Down

0 comments on commit ad53214

Please sign in to comment.