Skip to content

Commit

Permalink
feat: hide reactions and cover photo behind feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
filipesilva committed Jul 1, 2022
1 parent 83fa29d commit d441816
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 23 deletions.
7 changes: 7 additions & 0 deletions src/cljs/athens/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,13 @@
(-> db :athens/persist :settings)))


(rf/reg-sub
:feature-flags
:<- [:settings]
(fn [settings _]
(:feature-flags settings)))


(rf/reg-sub
:connection-status
(fn [db _]
Expand Down
19 changes: 12 additions & 7 deletions src/cljs/athens/views/blocks/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -187,10 +187,12 @@
:show-edit? show-edit?}
dragging? (rf/subscribe [::drag.subs/dragging? uid])
drag-target (rf/subscribe [::drag.subs/drag-target uid])
selected-items (rf/subscribe [::select-subs/items])]
selected-items (rf/subscribe [::select-subs/items])
feature-flags (rf/subscribe [:feature-flags])]
(rf/dispatch [::linked-ref.events/set-open! uid (or (false? linked-ref) initial-open)])
(rf/dispatch [::inline-refs.events/set-open! uid false])


(r/create-class
{:component-will-unmount
(fn will-unmount-block
Expand All @@ -208,13 +210,14 @@
_refs]} (merge (reactive/get-reactive-block-document ident) block)
children-uids (set (map :block/uid children))
uid-sanitized-block (s/transform
(specter-recursive-path #(contains? % :block/uid))
(fn [{:block/keys [original-uid uid] :as block}]
(assoc block :block/uid (or original-uid uid)))
block)
(specter-recursive-path #(contains? % :block/uid))
(fn [{:block/keys [original-uid uid] :as block}]
(assoc block :block/uid (or original-uid uid)))
block)
is-selected @(rf/subscribe [::select-subs/selected? uid])
present-user @(rf/subscribe [:presence/has-presence uid])
is-presence (seq present-user)]
is-presence (seq present-user)
reactions-enabled? (:reactions @feature-flags)]

;; (prn uid is-selected)

Expand All @@ -231,7 +234,9 @@
:isOpen open
:isLinkedRef (and (false? initial-open) (= uid linked-ref-uid))
:hasPresence is-presence
:actions (clj->js [(r/as-element [:> EmojiPickerPopover {:onEmojiSelected (fn [e] js/console.log e)}])])
:actions (clj->js
(into [] (when reactions-enabled?
[(r/as-element [:> EmojiPickerPopover {:onEmojiSelected (fn [e] js/console.log e)}])])))
:uid uid
;; need to know children for selection resolution
:childrenUids children-uids
Expand Down
24 changes: 15 additions & 9 deletions src/cljs/athens/views/blocks/editor.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
["/components/Block/Reactions" :refer [Reactions]]
["/components/Block/Toggle" :refer [Toggle]]
["/components/References/InlineReferences" :refer [ReferenceGroup ReferenceBlock]]
["@chakra-ui/react" :refer [VStack Button Breadcrumb BreadcrumbItem BreadcrumbLink HStack]]
["@chakra-ui/react" :refer [VStack Button Breadcrumb BreadcrumbItem BreadcrumbLink HStack]]
[athens.common-db :as common-db]
[athens.common-events.graph.ops :as graph-ops]
[athens.common.utils :as utils]
Expand Down Expand Up @@ -176,6 +176,7 @@
(sort-by first)
(mapv second))]))))


(defn editor-component
[block-el block-o children? linked-ref-data uid-sanitized-block state-hooks opts]
(let [{:keys [linked-ref
Expand All @@ -184,17 +185,22 @@
linked-ref-open? (rf/subscribe [::linked-ref.subs/open? uid])
inline-refs-open? (rf/subscribe [::inline-refs.subs/open? uid])
selected-items (rf/subscribe [::select-subs/items])
;; TODO: user-id for presence users is their username, TDB what it is for real auth users.
;; TODO: what should happen for local or in-memory db? there's no presence, atm it's hardcoded to "stuart"
user-id (or (:username @(rf/subscribe [:presence/current-user]))
"stuart")
reactions (props->reactions (:block/properties block-o))]
feature-flags (rf/subscribe [:feature-flags])]
(fn editor-component-render
[_block-el _block-o _children? _block _linked-ref-data _uid-sanitized-block _state-hooks _opts]
(let [{:block/keys [;; uid
open
children
_refs]} (reactive/get-reactive-block-document [:block/uid uid])]
properties
_refs]} (reactive/get-reactive-block-document [:block/uid uid])
reactions-enabled? (:reactions @feature-flags)
;; TODO: user-id for presence users is their username, TDB what it is for real auth users.
;; TODO: what should happen for local or in-memory db? there's no presence, atm it's hardcoded to "stuart"
user-id (or (:username @(rf/subscribe [:presence/current-user]))
"stuart")
reactions (and reactions-enabled?
(props->reactions properties))]

[:<>
[:div.block-body
(when (and children?
Expand Down Expand Up @@ -233,10 +239,10 @@
:on-drag-end (fn [e] (bullet-drag-end e uid))}]

[content/block-content-el block-o state-hooks]

(when reactions [:> Reactions {:reactions (clj->js reactions)
:currentUser user-id
:onToggleReaction (partial toggle-reaction [:block/uid uid])}])
:onToggleReaction (partial toggle-reaction [:block/uid uid])}])

[presence/inline-presence-el uid]

Expand Down
10 changes: 5 additions & 5 deletions src/cljs/athens/views/pages/node_page.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,8 @@
[_]
(let [state (r/atom init-state)
unlinked-refs (r/atom [])
block-uid (r/atom nil)]
block-uid (r/atom nil)
feature-flags (rf/subscribe [:feature-flags])]
(fn [node]
(when (not= @block-uid (:block/uid node))
(reset! state init-state)
Expand All @@ -408,9 +409,9 @@
on-daily-notes? (= :home @(subscribe [:current-route/name]))
is-current-route? (or (= @(subscribe [:current-route/uid]) uid)
(= @(subscribe [:current-route/page-title]) title))
cover-photo-enabled? (:cover-photo @feature-flags)
header-image-url (-> properties (get ":header/url") :block/string)]


(sync-title title state)

[:<>
Expand All @@ -428,9 +429,8 @@
:onChangeHeaderImageUrl (fn [url]
(dispatch [:properties/update-in [:node/title title] [":header/url"]
(fn [db uid] [(graph-ops/build-block-save-op db uid url)])]))
:headerImageUrl (or header-image-url
;; TODO: remove this default image, only here for testing.
"https://images.unsplash.com/photo-1651721675073-a992af85dfed?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=2670&q=80")}
:headerImageUrl header-image-url
:headerImageEnabled cover-photo-enabled?}

[:> TitleContainer {:isEditing @(subscribe [:editing/is-editing uid])}
;; Prevent editable textarea if a node/title is a date
Expand Down
5 changes: 3 additions & 2 deletions src/js/components/Page/Page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,8 @@ export const PageHeader = ({
onChangeHeaderImageUrl,
headerImageUrl,
onClickOpenInSidebar,
onClickOpenInMainView }
onClickOpenInMainView,
headerImageEnabled}
) => {
const [isPropertiesOpen, setIsPropertiesOpen] = React.useState(false)

Expand All @@ -92,7 +93,7 @@ export const PageHeader = ({
{children}

<ButtonGroup gridArea="extras" size="sm">
<Button onClick={() => setIsPropertiesOpen(!isPropertiesOpen)}>Properties</Button>
{headerImageEnabled && <Button onClick={() => setIsPropertiesOpen(!isPropertiesOpen)}>Properties</Button>}
{onClickOpenInMainView && <Tooltip label="Open in main view">
<IconButton
aria-label='Open in main view'
Expand Down

0 comments on commit d441816

Please sign in to comment.