fix(init-repo): init repo when login first time

pull/1009/head
defclass 2020-12-28 15:58:21 +08:00
parent 7d74e024bb
commit 338e66cea1
6 changed files with 80 additions and 59 deletions

View File

@ -3,5 +3,5 @@
[frontend.components.sidebar :as sidebar]))
(rum/defc home
[args]
(sidebar/main-content args))
[]
(sidebar/main-content))

View File

@ -20,7 +20,7 @@
(rum/defc add-repo
[]
(widgets/add-repo))
(widgets/add-graph))
(rum/defc repos < rum/reactive
[]
@ -79,7 +79,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

@ -163,10 +163,8 @@
(state/sidebar-add-block! current-repo db-id block-type nil))))
(reset! sidebar-inited? true))))
state)}
[args]
(let [query (get-in args [:parameters :query])
login-source (:login_source query)
today (state/sub :today)
[]
(let [today (state/sub :today)
cloning? (state/sub :repo/cloning?)
default-home (get-default-home-if-valid)
importing-to-db? (state/sub :repo/importing-to-db?)
@ -209,16 +207,7 @@
(journal/journals latest-journals)
(and logged? (empty? (:repos me)))
(case login-source
"google"
(if-not (nfs-handler/supported?)
[:div (t :help/select-nfs-browser)]
[:div (t :help/open-top-right-open-button)])
"github"
(widgets/add-repo)
(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

@ -14,7 +14,9 @@
[frontend.version :as version]
[frontend.components.commit :as commit]
[frontend.context.i18n :as i18n]
[reitit.frontend.easy :as rfe]))
[reitit.frontend.easy :as rfe]
[frontend.components.svg :as svg]
[frontend.handler.web.nfs :as nfs]))
(rum/defcs choose-preferred-format
[]
@ -36,52 +38,68 @@
:on-click
#(user-handler/set-preferred-format! :org))]]))
(rum/defcs add-repo <
(rum/defcs add-graph <
(rum/local "" ::repo)
(rum/local "master" ::branch)
[state]
(let [repo (get state ::repo)
branch (get state ::branch)]
branch (get state ::branch)
login-source (state/get-login-source)]
(rum/with-context [[t] i18n/*tongue-context*]
[:div.p-8.flex.items-center.justify-center
[:div.w-full.mx-auto
[:div
(if (= "github" login-source)
[:div.p-8.flex.items-center.justify-center
[:div.w-full.mx-auto
[:div
[:h1.title.mb-1
(t :git/add-repo-prompt)]
(ui/admonition :warning
[:p "Make sure that you've created this repo on GitHub."])
[: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.mb-1
(t :git/add-repo-prompt)]
(ui/admonition :warning
[:p "Make sure that you've created this repo on GitHub."])
[: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)))}]]
[:label.font-medium "Default Branch (make sure it's matched with your setting on Github): "]
[:div.mt-2.mb-4.relative.rounded-md.shadow-sm.max-w-xs
[:input#branch.form-input.block.w-full.sm:text-sm.sm:leading-5
{:value @branch
:placeholder "master"
:on-change (fn [e]
(reset! branch (util/evalue e)))}]]]]
[:label.font-medium "Default Branch (make sure it's matched with your setting on Github): "]
[:div.mt-2.mb-4.relative.rounded-md.shadow-sm.max-w-xs
[:input#branch.form-input.block.w-full.sm:text-sm.sm:leading-5
{:value @branch
:placeholder "master"
:on-change (fn [e]
(reset! branch (util/evalue e)))}]]]]
(ui/button
(t :git/add-repo-prompt-confirm)
:on-click
(fn []
(let [branch (string/trim @branch)]
(if (string/blank? branch)
(notification/show!
[:p "Please input a branch, make sure it's matched with your setting on Github."]
:error
false)
(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 branch))
(ui/button
(t :git/add-repo-prompt-confirm)
:on-click
(fn []
(let [branch (string/trim @branch)]
(if (string/blank? branch)
(notification/show!
[:p "Please input a branch, make sure it's matched with your setting on Github."]
:error
false)
(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 branch))
(notification/show!
[:p "Please input a valid repo url, e.g. https://github.com/username/repo"]
:error
false)))))))]])))
(notification/show!
[:p "Please input a valid repo url, e.g. https://github.com/username/repo"]
:error
false)))))))]]
[:div.p-8.flex.items-center.justify-center
[:div.w-full.mx-auto
[:div
[:div
[:h1.title.mb-1
"Please open a local directory : "]]
[:a.text-lg.font-medium.opacity-70.hover:opacity-100.ml-3.block
{:on-click (fn [] (nfs/ls-dir-files))}
[:div.flex.flex-row
[:span.inline-block svg/folder-add-large]
(when-not config/mobile?
[:span.ml-1.inline-block {:style {:margin-top "20px"}}
(t :open)])]]]]]))))

View File

@ -249,6 +249,10 @@
[]
(get-in @state [:me :repos]))
(defn get-login-source
[]
(get-in @state [:me :login_source]))
(defn set-repos!
[repos]
(set-state! [:me :repos] repos))