Edit community

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
This commit is contained in:
Volodymyr Kozieiev 2021-05-21 11:44:30 +03:00
parent 177b905291
commit 2b0c498613
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
5 changed files with 55 additions and 40 deletions

View File

@ -199,8 +199,7 @@
(fx/defn create
{:events [::create-confirmation-pressed]}
[{:keys [db]}]
(let [{:keys [name description membership image]} (get db :communities/create)
my-public-key (get-in db [:multiaccount :public-key])]
(let [{:keys [name description membership image]} (get db :communities/create)]
;; If access is ENS only, we set the access to require approval and set the rule
;; of ens only
(let [params (cond-> {:name name
@ -227,18 +226,22 @@
(fx/defn edit
{:events [::edit-confirmation-pressed]}
[{:keys [db]}]
(let [{:keys [name description membership]} (get db :communities/create)
my-public-key (get-in db [:multiaccount :public-key])]
(log/error "Edit community is not yet implemented")))
;; {::json-rpc/call [{:method "wakuext_editCommunity"
;; :params [{:identity {:display_name name
;; :description description}
;; :permissions {:access membership}}]
;; :on-success #(re-frame/dispatch [::community-edited %])
;; :on-error #(do
;; (log/error "failed to create community" %)
;; (re-frame/dispatch [::failed-to-edit-community %]))}]}
(let [{:keys [id name description membership new-image color]} (get db :communities/create)]
{::json-rpc/call [{:method "wakuext_editCommunity"
:params [{:communityID id
:name name
:description description
:color color
:image (string/replace-first (str new-image) #"file://" "")
:imageAx 0
:imageAy 0
:imageBx crop-size
:imageBy crop-size
:membership membership}]
:on-success #(re-frame/dispatch [::community-edited %])
:on-error #(do
(log/error "failed to edit community" %)
(re-frame/dispatch [::failed-to-edit-community %]))}]}))
(fx/defn create-channel
{:events [::create-channel-confirmation-pressed]}
@ -315,14 +318,16 @@
(fx/defn open-edit-community
{:events [::open-edit-community]}
[{:keys [db] :as cofx} id]
(let [{:keys [identity permissions]} (get-in db [:communities id :description])
{:keys [display-name description image]} identity
{:keys [access]} permissions]
(let [{:keys [name description images permissions color]} (get-in db [:communities id])
{:keys [access]} permissions]
(fx/merge cofx
{:db (assoc db :communities/create {:name display-name
{:db (assoc db :communities/create {:id id
:name name
:description description
:image image
:membership access})}
:image (get-in images [:large :uri])
:membership access
:color color
:editing? true})}
(navigation/navigate-to :communities {:screen :community-edit}))))
(fx/defn community-imported
@ -351,6 +356,11 @@
[{:keys [db]} field value]
{:db (assoc-in db [:communities/create field] value)})
(fx/defn remove-field
{:events [::remove-field]}
[{:keys [db]} field]
{:db (update-in db [:communities/create] dissoc field)})
(fx/defn member-banned
{:events [::member-banned]}
[cofx response-js]

View File

@ -128,6 +128,7 @@
"multiaccounts_storeIdentityImage" {}
"multiaccounts_deleteIdentityImage" {}
"wakuext_createCommunity" {}
"wakuext_editCommunity" {}
"wakuext_createCommunityChat" {}
"wakuext_inviteUsersToCommunity" {}
"wakuext_shareCommunity" {}

View File

@ -34,7 +34,9 @@
(js/setTimeout
(fn []
(react/show-image-picker
#(>evt [::communities/create-field :image (.-path ^js %)])
#(do (>evt [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)]))
crop-opts))
300))
@ -43,11 +45,12 @@
(js/setTimeout
(fn []
(react/show-image-picker-camera
#(>evt [::communities/create-field :image (.-path ^js %)])
#(do (>evt [::communities/create-field :image (.-path ^js %)])
(>evt [::communities/create-field :new-image (.-path ^js %)]))
crop-opts))
300))
(defn bottom-sheet [has-picture]
(defn bottom-sheet [has-picture editing?]
(fn []
[:<>
[quo/list-item {:accessibility-label :take-photo
@ -64,20 +67,21 @@
:on-press #(do
(>evt [:bottom-sheet/hide])
(pick-pic))}]
(when has-picture
(when (and has-picture (not editing?))
[quo/list-item {:accessibility-label :remove-photo
:icon :main-icons/delete
:theme :accent
:title (i18n/label :t/community-image-remove)
:on-press #(do
(>evt [:bottom-sheet/hide]))}])]))
(>evt [:bottom-sheet/hide])
(>evt [::communities/remove-field :image]))}])]))
(defn photo-picker []
(let [{:keys [image]} (<sub [:communities/create])]
(let [{:keys [image editing?]} (<sub [:communities/create])]
[rn/view {:style {:padding-top 16
:align-items :center}}
[rn/touchable-opacity {:on-press #(>evt [:bottom-sheet/show-sheet
{:content (bottom-sheet (boolean image))}])}
{:content (bottom-sheet (boolean image) editing?)}])}
[rn/view {:style {:width 128
:height 128}}
[rn/view {:style {:flex 1
@ -126,7 +130,7 @@
(str (count value) "/" max-length)]])
(defn form []
(let [{:keys [name description membership]} (<sub [:communities/create])]
(let [{:keys [name description membership editing?]} (<sub [:communities/create])]
[rn/scroll-view {:keyboard-should-persist-taps :handled
:style {:flex 1}
:content-container-style {:padding-vertical 16}}
@ -155,16 +159,16 @@
[quo/list-header {:color :main}
(i18n/label :t/community-thumbnail-image)]
[photo-picker]
[:<>
[quo/separator {:style {:margin-vertical 10}}]
[quo/list-item {:title (i18n/label :t/membership-button)
:accessory-text (i18n/label (get-in memberships/options [membership :title] :t/membership-none))
:accessory :text
:on-press #(>evt [:navigate-to :community-membership])
:chevron true
:size :small}]
[quo/list-footer
(i18n/label (get-in memberships/options [membership :description] :t/membership-none-placeholder))]]]))
(when-not editing? [:<>
[quo/separator {:style {:margin-vertical 10}}]
[quo/list-item {:title (i18n/label :t/membership-button)
:accessory-text (i18n/label (get-in memberships/options [membership :title] :t/membership-none))
:accessory :text
:on-press #(>evt [:navigate-to :community-membership])
:chevron true
:size :small}]
[quo/list-footer
(i18n/label (get-in memberships/options [membership :description] :t/membership-none-placeholder))]])]))
(defn view []
(let [{:keys [name description]} (<sub [:communities/create])]

View File

@ -67,8 +67,7 @@
:icon :main-icons/notification}])
(when (or show-members-count? notifications (and admin roles))
[quo/separator {:style {:margin-vertical 8}}])
;; Disable as not implemented yet
(when false
(when admin
[quo/list-item {:theme :accent
:icon :main-icons/edit
:title (i18n/label :t/edit-community)

View File

@ -191,6 +191,7 @@
"community-image-take": "Take a photo",
"community-image-pick": "Pick an image",
"community-image-delete": "",
"community-image-remove": "Remove",
"community-color": "Community colour",
"community-color-placeholder": "Pick a colour",
"membership-button": "Membership requirement",