Merge pull request #1009 from logseq/feat/google-login

Feat:  add google login
This commit is contained in:
Tienson Qin
2020-12-29 21:00:38 +08:00
committed by GitHub
7 changed files with 132 additions and 70 deletions

View File

@@ -155,11 +155,22 @@
(when (and (not logged?)
(not config/publishing?))
[:a.text-sm.font-medium.login.opacity-70.hover:opacity-100
{:href "/login/github"
:on-click (fn []
(storage/remove :git/current-repo))}
(t :login-github)])
(ui/dropdown-with-links
(fn [{:keys [toggle-fn]}]
[:a {:on-click toggle-fn}
[:span.ml-1.text-sm (t :login)]])
(let [list [{:title (t :login-google)
:url "/login/google"}
{:title (t :login-github)
:url "/login/github"}]]
(mapv
(fn [{:keys [title url]}]
{:title title
:options
{:on-click
(fn [_] (set! (.-href js/window.location) url))}})
list))))
(repo/sync-status)

View File

@@ -93,7 +93,7 @@
(blocks-cp repo page format))
(when intro? (widgets/add-repo))
(when intro? (widgets/add-graph))
(page/today-queries repo today? false)

View File

@@ -16,11 +16,17 @@
[frontend.components.commit :as commit]
[frontend.components.svg :as svg]
[frontend.context.i18n :as i18n]
[clojure.string :as string]))
[clojure.string :as string]
[clojure.string :as str]))
(rum/defc add-repo
[]
(widgets/add-repo))
[args]
(if-let [graph-types (get-in args [:query-params :graph-types])]
(let [graph-types-s (->> (str/split graph-types #",")
(mapv keyword))]
(when (seq graph-types-s)
(widgets/add-graph :graph-types graph-types-s)))
(widgets/add-graph)))
(rum/defc repos < rum/reactive
[]
@@ -42,7 +48,7 @@
(when (state/logged?)
(ui/button
"Add another git repo"
:href (rfe/href :repo-add)))]
:href (rfe/href :repo-add nil {:graph-types "github"})))]
(for [{:keys [id url] :as repo} repos]
(let [local? (config/local-db? url)]
[:div.flex.justify-between.mb-1 {:key id}
@@ -75,7 +81,7 @@
"Unlink"]]]))]
[:a#download-as-json.hidden]]
(widgets/add-repo)))))
(widgets/add-graph)))))
(rum/defc sync-status < rum/reactive
{:did-mount (fn [state]

View File

@@ -28,7 +28,8 @@
[goog.object :as gobj]
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]
[goog.dom :as gdom]))
[goog.dom :as gdom]
[frontend.handler.web.nfs :as nfs-handler]))
(defn nav-item
[title href svg-d active? close-modal-fn]
@@ -143,6 +144,7 @@
(defonce sidebar-inited? (atom false))
;; TODO: simplify logic
(rum/defc main-content < rum/reactive db-mixins/query
{:init (fn [state]
(when-not @sidebar-inited?
@@ -205,7 +207,7 @@
(journal/journals latest-journals)
(and logged? (empty? (:repos me)))
(widgets/add-repo)
(widgets/add-graph)
;; FIXME: why will this happen?
:else

View File

@@ -148,6 +148,16 @@
:stroke-linejoin "round"
:stroke-linecap "round"}]])
(def folder-add-large
[:svg
{:stroke "currentColor", :view-box "0 0 24 24", :fill "none" :width 64 :height 64 :display "inline-block"}
[:path
{:d
"M9 13h6m-3-3v6m-9 1V7a2 2 0 012-2h6l2 2h6a2 2 0 012 2v8a2 2 0 01-2 2H5a2 2 0 01-2-2z"
:stroke-width "2"
:stroke-linejoin "round"
:stroke-linecap "round"}]])
(def folder (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z"))
(def folder-sm (hero-icon "M3 7v10a2 2 0 002 2h14a2 2 0 002-2V9a2 2 0 00-2-2h-6l-2-2H5a2 2 0 00-2 2z" {:height "16" :width "16"}))
(def pages-sm [:svg {:viewBox "0 0 20 20", :fill "currentColor", :height "16", :width "16"}

View File

@@ -3,21 +3,15 @@
[frontend.util :as util]
[frontend.handler.user :as user-handler]
[frontend.handler.repo :as repo-handler]
[frontend.handler.route :as route-handler]
[frontend.handler.export :as export-handler]
[frontend.handler.notification :as notification]
[frontend.handler.web.nfs :as nfs]
[frontend.state :as state]
[frontend.config :as config]
[clojure.string :as string]
[frontend.ui :as ui]
[frontend.db :as db]
[frontend.version :as version]
[frontend.components.commit :as commit]
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
[frontend.handler.web.nfs :as nfs]))
(rum/defcs choose-preferred-format
(rum/defc choose-preferred-format
[]
(rum/with-context [[t] i18n/*tongue-context*]
[:div
@@ -26,65 +20,92 @@
[:div.mt-4.ml-1
(ui/button
"Markdown"
:on-click
#(user-handler/set-preferred-format! :markdown))
"Markdown"
:on-click
#(user-handler/set-preferred-format! :markdown))
[:span.ml-2.mr-2 "-OR-"]
(ui/button
"Org Mode"
:on-click
#(user-handler/set-preferred-format! :org))]]))
"Org Mode"
:on-click
#(user-handler/set-preferred-format! :org))]]))
(rum/defcs add-repo <
(rum/defcs add-github-repo <
(rum/local "" ::repo)
[state]
(let [repo (get state ::repo)]
(rum/with-context [[t] i18n/*tongue-context*]
[:div.p-8.flex.items-center.justify-center.flex-col
(let [nfs-supported? (nfs/supported?)]
[:div.cp__widgets-open-local-directory
[:div.select-file-wrap.cursor
(when nfs-supported?
{:on-click nfs/ls-dir-files})
[:div.flex.flex-col
[:div.w-full.mx-auto
[:div
[:div
[:h1.title
(t :git/add-repo-prompt)]
[:div.mt-4.mb-4.relative.rounded-md.shadow-sm.max-w-xs
[:input#repo.form-input.block.w-full.sm:text-sm.sm:leading-5
{:autoFocus true
:placeholder "https://github.com/username/repo"
:on-change (fn [e]
(reset! repo (util/evalue e)))}]]]]
[:div
[:h1.title "Open a local directory"]
[:p.text-sm
"Your data will be stored only in your device."]
(when-not nfs-supported?
(ui/admonition :warning
[:p "It seems that your browser doesn't support the "
(ui/button
(t :git/add-repo-prompt-confirm)
:on-click
(fn []
(let [repo (util/lowercase-first @repo)]
(if (util/starts-with? repo "https://github.com/")
(let [repo (string/replace repo ".git" "")]
(repo-handler/create-repo! repo))
[:a {:href "https://web.dev/file-system-access/"
:target "_blank"}
"new native filesystem API"]
[:span ", please use any chromium 86+ browser like Chrome, Vivaldi, Edge, Brave, etc."]]))]]])
(when (state/logged?)
[:div.w-full.mx-auto.mt-10
[:h1.title "Or you can"]
[:div
[:div
[:h1.title.mb-1
(t :git/add-repo-prompt)]
[:div.mt-4.mb-4.relative.rounded-md.shadow-sm.max-w-xs
[:input#repo.form-input.block.w-full.sm:text-sm.sm:leading-5
{:autoFocus true
:placeholder "https://github.com/username/repo"
:on-change (fn [e]
(reset! repo (util/evalue e)))}]]]]
(ui/button
(t :git/add-repo-prompt-confirm)
:on-click
(fn []
(let [repo (util/lowercase-first @repo)]
(if (util/starts-with? repo "https://github.com/")
(let [repo (string/replace repo ".git" "")]
(repo-handler/create-repo! repo))
(notification/show!
(notification/show!
[:p "Please input a valid repo url, e.g. https://github.com/username/repo"]
:error
false)))))])])))
false)))))]])))
(rum/defcs add-local-directory
[]
(rum/with-context [[t] i18n/*tongue-context*]
[:div.flex.flex-col
[:h1.title "Add a graph"]
(let [nfs-supported? (nfs/supported?)]
[:div.cp__widgets-open-local-directory
[:div.select-file-wrap.cursor
(when nfs-supported?
{:on-click nfs/ls-dir-files})
[:div
[:h1.title "Open a local directory"]
[:p.text-sm
"Your data will be stored only in your device."]
(when-not nfs-supported?
(ui/admonition :warning
[:p "It seems that your browser doesn't support the "
[:a {:href "https://web.dev/file-system-access/"
:target "_blank"}
"new native filesystem API"]
[:span ", please use any chromium 86+ browser like Chrome, Vivaldi, Edge, Brave, etc."]]))]]])]))
(rum/defcs add-graph <
[state & {:keys [graph-types]
:or {graph-types [:local :github]}
:as opts}]
(let [github-authed? (:github-authed? (state/get-me))
generate-f (fn [x]
(case x
:github
(when github-authed?
(rum/with-key (add-github-repo)
"add-github-repo"))
:local
(rum/with-key (add-local-directory)
"add-local-directory")
nil))
available-graph (->> (set graph-types)
(keep generate-f)
(vec)
(interpose [:b.mt-10.mb-5.opacity-50 "OR"]))]
(rum/with-context [[t] i18n/*tongue-context*]
[:div.p-8.flex.flex-col available-graph])))