-
Notifications
You must be signed in to change notification settings - Fork 2
/
ui.cljc
154 lines (142 loc) · 6.64 KB
/
ui.cljc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
(ns sb.app.board.ui
(:require [inside-out.forms :as forms]
[promesa.core :as p]
[re-db.api :as db]
[sb.app.account.data :as account.data]
[sb.app.asset.ui :as asset.ui]
[sb.app.board.data :as data]
[sb.app.domain-name.ui :as domain.ui]
[sb.app.entity.ui :as entity.ui]
[sb.app.field.ui :as field.ui]
[sb.app.form.ui :as form.ui]
[sb.app.form.ui :as form.ui]
[sb.app.project.data :as project.data]
[sb.app.project.ui :as project.ui]
[sb.app.views.header :as header]
[sb.app.views.radix :as radix]
[sb.app.views.ui :as ui]
[sb.i18n :refer [t]]
[sb.routing :as routing]
[sb.util :as u]
[yawn.hooks :as h]
[yawn.view :as v]))
(ui/defview new
{:route "/new/b"
:view/router :router/modal}
[{:as params :keys [route]}]
(let [account (db/get :env/config :account)
owners (some->> (account.data/account-orgs {})
seq
(cons (account.data/account-as-entity account)))]
(forms/with-form [!board (u/prune
{:entity/title ?title
:entity/domain-name ?domain
:entity/parent [:entity/id (uuid (?owner
:init
(or (-> params :query-params :org)
(str (-> (db/get :env/config :account)
:entity/id)))))]})
:required [?title ?domain]]
[:form
{:class form.ui/form-classes
:on-submit (fn [^js e]
(.preventDefault e)
(ui/with-submission [result (data/new! {:board @!board})
:form !board]
(routing/nav! `show {:board-id (:entity/id result)})))
:ref (ui/use-autofocus-ref)}
[:h2.text-2xl (t :tr/new-board)]
(when owners
[:div.flex-v.gap-2
[:label.field-label {} (t :tr/owner)]
(radix/select-menu {:value @?owner
:on-value-change (partial reset! ?owner)
:field/options
(->> owners
(map (fn [{:keys [entity/id entity/title image/avatar]}]
{:value (str id)
:text title
:icon [:img.w-5.h-5.rounded-sm {:src (asset.ui/asset-src avatar :avatar)}]})))})])
[field.ui/text-field ?title {:field/label (t :tr/title)}]
(domain.ui/domain-field ?domain nil)
[form.ui/submit-form !board (t :tr/create)]])))
(ui/defview register
{:route "/b/:board-id/register"}
[{:as params :keys [route]}]
(ui/with-form [!member {:member/name ?name :member/password ?pass}]
[:div
[:h3 (t :tr/register)]
[field.ui/text-field ?name nil]
[field.ui/text-field ?pass nil]
[:button {:on-click #(p/let [res (routing/POST route @!member)]
;; TODO - how to determine POST success?
#_(when (http-ok? res)
(routing/nav! [:board/read params])
res))}
(t :tr/register)]]))
(ui/defview action-button [{:as props :keys [on-click]} child]
(let [!async-state (h/use-state nil)
on-click (fn [e]
(reset! !async-state {:loading? true})
(p/let [result (on-click e)]
(prn :res result)
(reset! !async-state (when (:error result) result))))
{:keys [loading? error]} @!async-state]
[radix/tooltip {:delay-duration 0} error
[:div.btn.btn-white.overflow-hidden.relative
(-> props
(v/merge-props {:class (when error "ring-destructive ring-2")})
(assoc :on-click
(when-not loading? on-click)))
(t :tr/new-project)
(when (:loading? @!async-state)
[:div.loading-bar.absolute.top-0.left-0.right-0.h-1])]]))
(ui/defview show
{:route "/b/:board-id"}
[{:as params :keys [board-id]}]
(let [{:as board :keys [member/roles]} (data/show {:board-id board-id})
!current-tab (h/use-state (t :tr/projects))
?filter (h/use-state nil)]
[:<>
[header/entity board (list (entity.ui/settings-button board))]
[:div.p-body
[:div.flex.gap-4.items-stretch
[form.ui/filter-field ?filter nil]
[action-button
{:on-click (fn [_]
(p/let [{:as result
:keys [entity/id]} (project.data/new! nil
{:entity/parent board-id
:entity/title (t :tr/untitled)
:entity/draft? true})]
(when id
(routing/nav! `project.ui/show {:project-id id}))
result))}
(t :tr/new-project)]]
[radix/tab-root {:class "flex flex-col gap-6 mt-6"
:value @!current-tab
:on-value-change #(do (reset! !current-tab %)
(reset! ?filter nil))}
;; tabs
[:div.flex.items-stretch.h-10.gap-3
[radix/show-tab-list
(for [x [:tr/projects :tr/members]
:let [x (t x)]]
{:title x :value x})]]
[radix/tab-content {:value (t :tr/projects)}
(into [:div.grid]
(comp (ui/filtered @?filter)
(map entity.ui/row))
(data/projects {:board-id board-id}))]
[radix/tab-content {:value (t :tr/members)}
(into [:div.grid]
(comp (map #(merge (account.data/account-as-entity (:member/account %))
(db/touch %)))
(map entity.ui/row))
(data/members {:board-id board-id}))
]]]]))
(comment
[:ul ;; i18n stuff
[:li "suggested locales:" (str (:entity/locale-suggestions board))]
[:li "default locale:" (str (:i18n/default-locale board))]
[:li "extra-translations:" (str (:i18n/locale-dicts board))]])