Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Monitoring: Navigation #2071

Merged
merged 20 commits into from
Mar 16, 2022
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/cljs/athens/electron/monitoring/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,20 @@
(fn [{:keys [_db]} [_ feature on?]]
{:posthog/capture-event! {:event-name (str "feature/" (name feature))
:opts-map {feature on?}}}))


(rf/reg-event-fx
:reporting/navigation
(fn [{:keys [_db]} [_ {:keys [source target pane]}]]
{:posthog/capture-event! {:event-name "feature/navigate"
:opts-map {:source source
:target target
:pane pane}}}))


(rf/reg-event-fx
:reporting/page.create
(fn [{:keys [_db]} [_ {:keys [source count]}]]
{:posthog/capture-event! {:event-name "feature/page.create"
:opts-map {:source source
:pages-created count}}}))
neotyk marked this conversation as resolved.
Show resolved Hide resolved
36 changes: 26 additions & 10 deletions src/cljs/athens/listeners.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
[athens.util :as util]
[clojure.string :as string]
[goog.events :as events]
[re-frame.core :refer [dispatch dispatch-sync subscribe]])
[re-frame.core :as rf :refer [dispatch dispatch-sync subscribe]])
(:import
(goog.events
EventType
Expand Down Expand Up @@ -87,8 +87,8 @@
meta
shift
alt]
:as destruct-keys} (util/destruct-key-down e)
editing-uid @(subscribe [:editing/uid])]
:as destruct-keys} (util/destruct-key-down e)
editing-uid @(subscribe [:editing/uid])]
(cond
(util/navigate-key? destruct-keys) (condp = key-code
KeyCodes.LEFT (when (nil? editing-uid)
Expand All @@ -115,15 +115,31 @@
KeyCodes.BACKSLASH (if shift
(dispatch [:right-sidebar/toggle])
(dispatch [:left-sidebar/toggle]))
KeyCodes.COMMA (router/navigate :settings)
KeyCodes.COMMA (do
(rf/dispatch [:reporting/navigation {:source :kbd-ctrl-comma
:target :settings
:pane :main-pane}])
(router/navigate :settings))
KeyCodes.T (util/toggle-10x)
nil)
alt (condp = key-code
KeyCodes.D (router/nav-daily-notes)
KeyCodes.G (router/navigate :graph)
KeyCodes.A (router/navigate :pages)
KeyCodes.T (dispatch [:theme/toggle])
nil))))
alt (condp = key-code
KeyCodes.D (do
(rf/dispatch [:reporting/navigation {:source :kbd-alt-d
:target :home
:pane :main-pane}])
(router/nav-daily-notes))
KeyCodes.G (do
(rf/dispatch [:reporting/navigation {:source :kbd-ctrl-g
neotyk marked this conversation as resolved.
Show resolved Hide resolved
:target :graph
:pane :main-pane}])
(router/navigate :graph))
KeyCodes.A (do
(rf/dispatch [:reporting/navigation {:source :kbd-ctrl-comma
neotyk marked this conversation as resolved.
Show resolved Hide resolved
:target :all-pages
:pane :main-pane}])
(router/navigate :pages))
KeyCodes.T (dispatch [:theme/toggle])
nil))))


;; -- Clipboard ----------------------------------------------------------
Expand Down
42 changes: 36 additions & 6 deletions src/cljs/athens/parse_renderer.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
[athens.style :refer [color OPACITIES]]
[clojure.string :as str]
[instaparse.core :as insta]
[re-frame.core :as rf]
[stylefy.core :as stylefy :refer [use-style]]))


Expand Down Expand Up @@ -84,14 +85,28 @@
(cond
(not (str/blank? title))
[:span {:on-click (fn [e]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(router/navigate-page (parse-title title-coll) e))}
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(rf/dispatch [:reporting/navigation {:source :pr-page-link
:target :page
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))}
title]

:else
(into [:span {:on-click (fn [e]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(router/navigate-page (parse-title title-coll) e))}]
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(.. e stopPropagation) ; prevent bubbling up click handler for nested links
(rf/dispatch [:reporting/navigation {:source :pr-page-link
:target :page
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))}]
title-coll))
[:span {:class "formatting"} "]]"]])

Expand All @@ -117,7 +132,14 @@
(str/replace (str "((" ref-uid "))")
bc-string)))
[:span {:class "contents"
:on-click #(router/navigate-uid ref-uid %)}
:on-click (fn [e]
(let [shift? (.-shiftKey e)]
(rf/dispatch [:reporting/navigation {:source :pr-block-ref
:target :block
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-uid ref-uid e)))}
(cond
(= uid ref-uid)
[parse-and-render "{{SELF}}"]
Expand Down Expand Up @@ -193,7 +215,15 @@
(render-page-link attr title-coll))
:hashtag (fn [{_from :from} & title-coll]
[:span (use-style hashtag {:class "hashtag"
:on-click #(router/navigate-page (parse-title title-coll) %)})
:on-click (fn [e]
(let [parsed-title (parse-title title-coll)
shift? (.-shiftKey e)]
(rf/dispatch [:reporting/navigation {:source :pr-hashtag
:target :hashtag
:pane (if shift?
:right-pane
:main-pane)}])
(router/navigate-page parsed-title e)))})
[:span {:class "formatting"} "#"]
[:span {:class "contents"} title-coll]])
:block-ref (fn [{_from :from :as attr} ref-uid]
Expand Down
146 changes: 89 additions & 57 deletions src/cljs/athens/views/app_toolbar.cljs
Original file line number Diff line number Diff line change
@@ -1,69 +1,101 @@
(ns athens.views.app-toolbar
(:require
["/components/AppToolbar/AppToolbar" :refer [AppToolbar]]
[athens.electron.db-menu.core :refer [db-menu]]
[athens.electron.db-modal :as db-modal]
[athens.electron.utils :as electron.utils]
[athens.router :as router]
[athens.self-hosted.presence.views :refer [toolbar-presence-el]]
[athens.style :refer [unzoom]]
[athens.electron.db-menu.core :refer [db-menu]]
[athens.electron.db-modal :as db-modal]
[athens.electron.utils :as electron.utils]
[athens.router :as router]
[athens.self-hosted.presence.views :refer [toolbar-presence-el]]
[athens.style :refer [unzoom]]
[athens.subs]
[athens.util :as util]
[re-frame.core :refer [subscribe dispatch]]
[reagent.core :as r]))
[athens.util :as util]
[re-frame.core :as rf]
[reagent.core :as r]))


(defn app-toolbar
[]
(let [left-open? (subscribe [:left-sidebar/open])
right-open? (subscribe [:right-sidebar/open])
route-name (subscribe [:current-route/name])
os (util/get-os)
electron? electron.utils/electron?
theme-dark (subscribe [:theme/dark])
win-focused? (if electron?
(subscribe [:win-focused?])
(r/atom false))
win-maximized? (if electron?
(subscribe [:win-maximized?])
(r/atom false))
win-fullscreen? (if electron?
(subscribe [:win-fullscreen?])
(r/atom false))
merge-open? (reagent.core/atom false)

selected-db (subscribe [:db-picker/selected-db])]
(let [left-open? (rf/subscribe [:left-sidebar/open])
right-open? (rf/subscribe [:right-sidebar/open])
help-open? (rf/subscribe [:help/open?])
athena-open? (rf/subscribe [:athena/open])
route-name (rf/subscribe [:current-route/name])
theme-dark (rf/subscribe [:theme/dark])
selected-db (rf/subscribe [:db-picker/selected-db])
electron? electron.utils/electron?
win-focused? (if electron?
(rf/subscribe [:win-focused?])
(r/atom false))
win-maximized? (if electron?
(rf/subscribe [:win-maximized?])
(r/atom false))
win-fullscreen? (if electron?
(rf/subscribe [:win-fullscreen?])
(r/atom false))
merge-open? (r/atom false)
os (util/get-os)
on-left-sidebar-toggle #(rf/dispatch [:left-sidebar/toggle])
on-back #(.back js/window.history)
on-forward #(.forward js/window.history)
on-daily-pages (fn [_]
(rf/dispatch [:reporting/navigation {:source :app-toolbar
:target :home
:pane :main-pane}])
(router/nav-daily-notes))
on-all-pages (fn [_]
(rf/dispatch [:reporting/navigation {:source :app-toolbar
:target :all-pages
:pane :main-pane}])
(router/navigate :pages))
on-graph (fn [_]
(rf/dispatch [:reporting/navigation {:source :app-toolbar
:target :graph
:pane :main-pane}])
(router/navigate :graph))
on-settings (fn [_]
(rf/dispatch [:reporting/navigation {:source :app-toolbar
:target :settings
:pane :main-pane}])
(router/navigate :settings))
on-athena #(rf/dispatch [:athena/toggle])
on-help #(rf/dispatch [:help/toggle])
on-theme #(rf/dispatch [:theme/toggle])
on-merge #(swap! merge-open? not)
on-right-sidebar #(rf/dispatch [:right-sidebar/toggle])
on-maximize #(rf/dispatch [:toggle-max-min-win])
on-minimize #(rf/dispatch [:minimize-win])
on-close #(rf/dispatch [:close-win])]
(fn []
[:<>
(when @merge-open?
[db-modal/merge-modal merge-open?])
[:> AppToolbar {:style (unzoom)
:os os
:isElectron electron?
:route @route-name
:isWinFullscreen @win-fullscreen?
:isWinMaximized @win-maximized?
:isWinFocused @win-focused?
:isHelpOpen @(subscribe [:help/open?])
:isThemeDark @theme-dark
:isLeftSidebarOpen @left-open?
:isRightSidebarOpen @right-open?
:isCommandBarOpen @(subscribe [:athena/open])
:onPressLeftSidebarToggle #(dispatch [:left-sidebar/toggle])
:onPressHistoryBack #(.back js/window.history)
:onPressHistoryForward #(.forward js/window.history)
:onPressDailyNotes router/nav-daily-notes
:onPressAllPages #(router/navigate :pages)
:onPressGraph #(router/navigate :graph)
:onPressCommandBar #(dispatch [:athena/toggle])
:onPressHelp #(dispatch [:help/toggle])
:onPressThemeToggle #(dispatch [:theme/toggle])
:onPressSettings #(router/navigate :settings)
:onPressMerge #(swap! merge-open? not)
:onPressRightSidebarToggle #(dispatch [:right-sidebar/toggle])
:onPressMaximizeRestore #(dispatch [:toggle-max-min-win])
:onPressMinimize #(dispatch [:minimize-win])
:onPressClose #(dispatch [:close-win])
:databaseMenu (r/as-element [db-menu])
:presenceDetails (when (electron.utils/remote-db? @selected-db)
(r/as-element [toolbar-presence-el]))}]])))
[:> AppToolbar {:style (unzoom)
:os os
:isElectron electron?
:route @route-name
:isWinFullscreen @win-fullscreen?
:isWinMaximized @win-maximized?
:isWinFocused @win-focused?
:isHelpOpen @help-open?
:isThemeDark @theme-dark
:isLeftSidebarOpen @left-open?
:isRightSidebarOpen @right-open?
:isCommandBarOpen @athena-open?
:onPressLeftSidebarToggle on-left-sidebar-toggle
:onPressHistoryBack on-back
:onPressHistoryForward on-forward
:onPressDailyNotes on-daily-pages
:onPressAllPages on-all-pages
:onPressGraph on-graph
:onPressCommandBar on-athena
:onPressHelp on-help
:onPressThemeToggle on-theme
:onPressSettings on-settings
:onPressMerge on-merge
:onPressRightSidebarToggle on-right-sidebar
:onPressMaximizeRestore on-maximize
:onPressMinimize on-minimize
:onPressClose on-close
:databaseMenu (r/as-element [db-menu])
:presenceDetails (when (electron.utils/remote-db? @selected-db)
(r/as-element [toolbar-presence-el]))}]])))
Loading