Skip to content

Commit

Permalink
fixes:
Browse files Browse the repository at this point in the history
- org settings re-enabled
- org query includes roles
- account memberships include roles
- chat snippet shows other name
- text-field retains focus state when persisted-value changes
- image field shows uploaded image
  • Loading branch information
mhuebert committed Jan 17, 2024
1 parent af3d368 commit 30b35c8
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 43 deletions.
16 changes: 6 additions & 10 deletions src/sb/app/account/data.cljc
Expand Up @@ -59,31 +59,27 @@
:membership/_member
(mapcat #(cons % (:membership/_member %)))
(map #(assoc (:membership/entity %) :membership/roles (:membership/roles %)))))))

(q/defquery all
{:endpoint {:query true}
:prepare az/with-account-id!}
[{:keys [account-id]}]
(prn account-id)
(u/timed `all
(->> (q/pull `[{:membership/_member
[:membership/roles
:entity/id
:entity/kind
{:membership/member [:entity/id
:entity/kind
{:membership/member [~@entity.data/id-fields
:account/display-name
{:image/avatar [:entity/id]}]}
{:membership/entity [:entity/id
:entity/kind
:entity/title
:entity/created-at
{:membership/entity [~@entity.data/listing-fields
{:entity/parent [:entity/id]}
{:image/avatar [:entity/id]}
{:image/background [:entity/id]}]}
{:membership/_member :...}]}] account-id)
{:membership/_member :...}]}]
account-id)
:membership/_member
#_(mapcat #(cons % (:membership/_member %)))
#_(map #(assoc-in % [:membership/entity :membership/roles] (:membership/roles %)))
(map #(assoc-in % [:membership/entity :membership/roles] (:membership/roles %)))
#_clojure.pprint/pprint)))

#?(:clj
Expand Down
3 changes: 1 addition & 2 deletions src/sb/app/account/ui.cljc
Expand Up @@ -6,7 +6,6 @@
[sb.app.account.data :as data]
[sb.app.entity.ui :as entity.ui]
[sb.app.field.ui :as field.ui]
[sb.app.membership.data :as member.data]
[sb.app.views.header :as header]
[sb.app.views.radix :as radix]
[sb.app.views.ui :as ui]
Expand Down Expand Up @@ -121,7 +120,7 @@
(seq projects-by-board)
(ui/match-entity match-text org))]
[:div.contents {:key (:entity/id org)}
[:div.text-lg.font-semibold (:entity/title org)]
[:a.text-lg.font-semibold.flex.items-center.hover:underline {:href (routing/entity-path org 'ui/show)} (:entity/title org)]
(limit
(u/for! [board boards
:let [projects (get projects-by-board board)]]
Expand Down
7 changes: 3 additions & 4 deletions src/sb/app/board/ui.cljc
Expand Up @@ -7,10 +7,9 @@
[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.membership.ui :as member.ui]
[sb.app.field.ui :as field.ui]
[sb.app.form.ui :as form.ui]
[sb.app.membership.ui :as member.ui]
[sb.app.project.data :as project.data]
[sb.app.project.ui :as project.ui]
[sb.app.views.header :as header]
Expand Down Expand Up @@ -100,8 +99,8 @@
(ui/defview show
{:route "/b/:board-id"}
[{:as params :keys [board-id]}]
(let [{:as board :keys [membership/roles]} (data/show {:board-id board-id})
!current-tab (h/use-state (t :tr/members #_:tr/projects))
(let [board (data/show {:board-id board-id})
!current-tab (h/use-state (t :tr/projects))
?filter (h/use-memo #(io/field))
card-grid (v/from-element :div.grid.gap-4.grid-cols-1.md:grid-cols-2.lg:grid-cols-3)]
[:<>
Expand Down
4 changes: 2 additions & 2 deletions src/sb/app/chat/ui.cljc
Expand Up @@ -54,13 +54,13 @@
chat/last-message]} chat
other (other-participant account-id chat)
current? (sch/id= current-chat-id id)]
[:a.flex.gap-2.py-2.cursor-default.px-1.rounded.items-center.text-sm.w-full.text-left.focus-bg-gray-100
[:a.flex.gap-2.py-2.cursor-default.px-1.rounded.items-start.text-sm.w-full.text-left.focus-bg-gray-100
{:href (routing/path-for [`chat {:chat-id id}])
:class (if current? "bg-blue-100 rounded" "hover:bg-gray-100")}
[ui/avatar {:size 12 :class "flex-none"} (:membership/member other)]
[:div.flex-v.w-full.overflow-hidden
[:div.flex.items-center
[:div.font-bold.flex-auto (:account/display-name other)]]
[:div.font-bold.flex-auto (:account/display-name (:membership/member other))]]
[:div.text-gray-700.hidden.md:line-clamp-2.text-sm
{:class (when (data/unread? params chat) "font-semibold")}
(field.ui/show-prose
Expand Down
3 changes: 2 additions & 1 deletion src/sb/app/entity/ui.cljc
@@ -1,5 +1,6 @@
(ns sb.app.entity.ui
(:require [inside-out.forms :as io]
[re-db.api :as db]
[sb.app.asset.ui :as asset.ui]
[sb.app.entity.data :as data]
[sb.app.views.ui :as ui]
Expand Down Expand Up @@ -82,7 +83,7 @@
[:div.line-clamp-2 title]]])

(ui/defview settings-button [entity]
(let [roles (az/all-roles nil entity)]
(let [roles (az/all-roles (db/get :env/config :account-id) entity)]
(when-let [path (and (or (:role/admin roles)
(:role/org-admin roles))
(some-> (routing/entity-route entity 'admin-ui/settings)
Expand Down
25 changes: 16 additions & 9 deletions src/sb/app/field/ui.cljc
Expand Up @@ -169,7 +169,11 @@
classes)
data-props {:data-touched (:touched ?field)
:data-invalid (not (io/valid? ?field))
:data-focused (:focused ?field)}]
:data-focused (:focused ?field)}
!input-ref (h/use-ref)
focused? (some-> @!input-ref (= (j/get js/window.document :activeElement)))]
;; TODO ... shouldn't ?field retain :focused/:touched metadata when its persisted value changes?
;; currently we create a new ?field when the persisted value changes, which is a bit of a hack
(when (or can-edit? (u/some-str (:value props)))
[:div.field-wrapper
(merge data-props {:class (:wrapper classes)})
Expand All @@ -179,7 +183,8 @@
[auto-size (-> (u/dissoc-qualified props)
(v/merge-props
data-props
{:disabled (not can-edit?)
{:ref !input-ref
:disabled (not can-edit?)
:class ["w-full" (:input classes)]
:placeholder (:placeholder props)
:on-key-down (let [save (fn [^js e]
Expand All @@ -195,11 +200,11 @@
{:Enter save})
keybindings)))}))])
;; show pencil when value is modified
(when (and (or (:focused ?field) (:touched ?field))
(when (and (or focused? (:touched ?field))
(io/closest ?field :field/persisted?)
(not= (u/some-str (entity.data/persisted-value ?field))
(u/some-str (:value props))))
[:div.pointer-events-none.absolute.inset-y-0.right-0.top-0.bottom-0.flex.items-center.p-2 [icons/pencil-outline "w-4 h-4 text-txt/40"]])
[:div.pointer-events-none.absolute.right-0.top-0.flex.items-center.p-2 [icons/pencil-outline "w-4 h-4 text-txt/40"]])

(when (:loading? ?field)
[:div.loading-bar.absolute.bottom-0.left-0.right-0 {:class "h-[3px]"}])]
Expand Down Expand Up @@ -252,7 +257,9 @@
:style {:background-image (asset.ui/css-url (:video/thumbnail (parse-video-url url)))
:background-size "cover"
:background-position "center"}}
[:div.rounded.p-1.absolute.top-1.right-1.text-white {:class "hover:bg-black/20"} [icons/external-link " icon-lg drop-shadow"]]
[:div.rounded.p-1.absolute.top-1.right-1.text-white {:class "hover:bg-black/20"}
[icons/external-link " icon-lg drop-shadow"]]

[icons/play-circle "icon-xl w-20 h-20 text-white drop-shadow-2xl transition-all hover:scale-110 "]])

(ui/defview video-field
Expand All @@ -265,8 +272,8 @@
[:div.flex.items-center
(when (and can-edit? (not value))
[:div.flex-auto (form.ui/show-label ?field (:field/label props))])]
(when value
[show-video-url value])
(when-let [url (:video/url value)]
[show-video-url url])
(when can-edit?
(text-field ?field (merge props
{:field/label false
Expand Down Expand Up @@ -579,9 +586,9 @@
img)))

(ui/defview images-field [?images {:as props :field/keys [label can-edit?]}]
(let [!?current (h/use-state (first ?images))
(let [!?current (h/use-state-with-deps (first ?images) [?images])
use-order (ui/use-orderable-parent ?images {:axis :x})
[selected-url loading?] (some-> @!?current ('?id) deref (asset.ui/asset-src :card) ui/use-last-loaded)]
[selected-url loading?] (ui/use-last-loaded (some-> @!?current ('?id) deref (asset.ui/asset-src :card)) [?images])]
[:div.field-wrapper
(form.ui/show-label ?images label)
(when selected-url
Expand Down
7 changes: 7 additions & 0 deletions src/sb/app/membership/data.cljc
Expand Up @@ -156,6 +156,13 @@
account-id
search-term)))

(comment
;; does not work
(q/defquery my-membership
{:prepare az/with-account-id!}
[{:keys [account-id entity-id]}]
{:entity/id (sch/unwrap-id entity-id)
:membership/roles (az/all-roles account-id entity-id)}))
(comment
(search {:account-id [:entity/id #uuid "b08f39bf-4f31-3d0b-87a6-ef6a2f702d30"]
;:entity-id [:entity/id #uuid "a1630339-64b3-3604-8110-0f22355e12be"]
Expand Down
12 changes: 7 additions & 5 deletions src/sb/app/org/admin_ui.cljc
Expand Up @@ -9,13 +9,15 @@
(ui/defview settings
{:route "/o/:org-id/settings"}
[{:as params :keys [org-id]}]
(let [org (data/settings params)]
(let [org (data/settings params)
use-attr (fn [attr & [props]]
(entity.ui/use-persisted-attr org attr (merge {:field/can-edit? true} props)))]
[:<>
(header/entity org nil)
[:div {:class form.ui/form-classes}
(entity.ui/use-persisted-attr org :entity/title)
(entity.ui/use-persisted-attr org :entity/description)
(entity.ui/use-persisted-attr org :entity/domain-name)
(entity.ui/use-persisted-attr org :image/avatar {:field/label (i/t :tr/logo)})
(use-attr :entity/title)
(use-attr :entity/description)
(use-attr :entity/domain-name)
(use-attr :image/avatar {:field/label (i/t :tr/logo)})

]]))
16 changes: 9 additions & 7 deletions src/sb/app/org/data.cljc
Expand Up @@ -50,20 +50,22 @@
org-id))

(q/defquery show
{:prepare [az/with-account-id!]}
[{:keys [org-id]}]
(q/pull `[~@entity.data/listing-fields
~@entity.data/site-fields
{:entity/_parent ~entity.data/listing-fields}]
(dl/resolve-id org-id)))
{:prepare [az/require-account!
(az/with-roles :org-id)]}
[{:keys [org-id membership/roles]}]
(->> (dl/resolve-id org-id)
(q/pull `[~@entity.data/listing-fields
~@entity.data/site-fields
{:entity/_parent ~entity.data/listing-fields}])
(merge {:membership/roles roles})))

(q/defx search-once
[{:as params
:keys [org-id q]}]
(when q
{:q q
:boards (dl/q (u/template
`[:find [(pull ?board ~entity.data/entity-keys) ...]
`[:find [(pull ?board [~@entity.data/listing-fields]) ...]
:in $ ?terms ?org
:where
[?board :entity/parent ?org]
Expand Down
2 changes: 1 addition & 1 deletion src/sb/app/views/header.cljc
Expand Up @@ -123,7 +123,7 @@
[:a {:href path}
[:img.h-10
{:src (asset.ui/asset-src avatar :avatar)}]])
[:a.hover:underline.text-xl.font-semibold.text-ellipsis.truncate.self-center {:href path} title]
[:a.hover:underline.text-xl.font-medium.text-ellipsis.truncate.self-center {:href path} title]

[:div.flex-grow]
[:div.flex.gap-1
Expand Down
4 changes: 2 additions & 2 deletions src/sb/app/views/ui.cljs
Expand Up @@ -123,8 +123,8 @@
url
fallback)))

(defn use-last-loaded [image-url]
(let [!last-loaded (h/use-state image-url)
(defn use-last-loaded [image-url deps]
(let [!last-loaded (h/use-state-with-deps image-url deps)
!loaded (h/use-state #{})]
(h/use-effect
(fn []
Expand Down

0 comments on commit 30b35c8

Please sign in to comment.