Merge branch 'master' into refactor/remove-editor-ugly-timers

This commit is contained in:
Tienson Qin
2020-11-12 12:34:32 +08:00
18 changed files with 268 additions and 229 deletions

View File

@@ -5,6 +5,7 @@
[frontend.handler.git :as git-handler]
[frontend.handler.file :as file]
[frontend.handler.notification :as notification]
[frontend.handler.common :as common-handler]
[frontend.state :as state]
[clojure.string :as string]
[frontend.db :as db]
@@ -138,38 +139,34 @@
{:will-mount
(fn [state]
(when-let [repo (state/get-current-repo)]
(git-handler/get-latest-commit
repo
(fn [commit]
(let [local-oid (gobj/get commit "oid")
remote-oid (db/get-key-value repo
:git/remote-latest-commit)]
(p/let [result (git/get-local-diffs repo local-oid remote-oid)]
(reset! diffs result)
(reset! remote-hash-id remote-oid)
(doseq [{:keys [type path]} result]
(when (contains? #{"added" "modify"}
type)
(github/get-content
(state/get-github-token repo)
repo
path
remote-oid
(fn [{:keys [repo-url path ref content]}]
(swap! state/state
assoc-in [:github/contents repo-url remote-oid path] content))
(fn [response]
(when (= (gobj/get response "status") 401)
(notification/show!
[:span.text-gray-700.mr-2
(util/format
"Please make sure that you've installed the logseq app for the repo %s on GitHub. "
repo)
(ui/button
"Install Logseq on GitHub"
:href (str "https://github.com/apps/" config/github-app-name "/installations/new"))]
:error
false)))))))))))
(p/let [remote-latest-commit (common-handler/get-remote-ref repo)
local-latest-commit (common-handler/get-ref repo)
result (git/get-local-diffs repo local-latest-commit remote-latest-commit)]
(reset! diffs result)
(reset! remote-hash-id remote-latest-commit)
(doseq [{:keys [type path]} result]
(when (contains? #{"added" "modify"}
type)
(github/get-content
(state/get-github-token repo)
repo
path
remote-latest-commit
(fn [{:keys [repo-url path ref content]}]
(swap! state/state
assoc-in [:github/contents repo-url remote-latest-commit path] content))
(fn [response]
(when (= (gobj/get response "status") 401)
(notification/show!
[:span.text-gray-700.mr-2
(util/format
"Please make sure that you've installed the logseq app for the repo %s on GitHub. "
repo)
(ui/button
"Install Logseq on GitHub"
:href (str "https://github.com/apps/" config/github-app-name "/installations/new"))]
:error
false))))))))
state)
:will-unmount
(fn [state]
@@ -206,13 +203,13 @@
(if pushing?
[:span (ui/loading "Pushing")]
(ui/button "Commit and push"
:on-click
(fn []
(let [commit-message (if (string/blank? @commit-message)
"Merge"
@commit-message)]
(reset! *pushing? true)
(git-handler/commit-and-force-push! commit-message *pushing?)))))]]
:on-click
(fn []
(let [commit-message (if (string/blank? @commit-message)
"Merge"
@commit-message)]
(reset! *pushing? true)
(git-handler/commit-and-force-push! commit-message *pushing?)))))]]
:else
[:div "No diffs"])]))

View File

@@ -135,7 +135,7 @@
(block-cp repo idx block-data)]]))
:page
(let [page-name (get-in block-data [:page :page/name])]
(let [page-name (:page/name block-data)]
[[:a {:href (rfe/href :page {:name (util/url-encode page-name)})}
(util/capitalize-all page-name)]
[:div.ml-2
@@ -171,24 +171,29 @@
(rum/defc sidebar-item < rum/reactive
[repo idx db-id block-type block-data t]
(let [collapse? (state/sub [:ui/sidebar-collapsed-blocks db-id])
item (build-sidebar-item repo idx db-id block-type block-data t)]
(let [item
(if (= :page block-type)
(let [page (db/query-entity-in-component db-id)]
(when (seq page)
(build-sidebar-item repo idx db-id block-type page t)))
(build-sidebar-item repo idx db-id block-type block-data t))]
(when item
[:div.sidebar-item.content
(let [[title component] item]
[:div.flex.flex-col
[:div.flex.flex-row.justify-between
[:div.flex.flex-row.justify-center
[:a.opacity-50.hover:opacity-100.flex.items-center.pr-1
{:on-click #(state/sidebar-block-toggle-collapse! db-id)}
(if collapse?
(svg/caret-right)
(svg/caret-down))]
[:div.ml-1
title]]
(close #(state/sidebar-remove-block! idx))]
[:div {:class (if collapse? "hidden" "initial")}
component]])])))
(let [collapse? (state/sub [:ui/sidebar-collapsed-blocks db-id])]
[:div.sidebar-item.content
(let [[title component] item]
[:div.flex.flex-col
[:div.flex.flex-row.justify-between
[:div.flex.flex-row.justify-center
[:a.opacity-50.hover:opacity-100.flex.items-center.pr-1
{:on-click #(state/sidebar-block-toggle-collapse! db-id)}
(if collapse?
(svg/caret-right)
(svg/caret-down))]
[:div.ml-1
title]]
(close #(state/sidebar-remove-block! idx))]
[:div {:class (if collapse? "hidden" "initial")}
component]])]))))
(defn- get-page
[match]