diff --git a/src/status_im/communities/core.cljs b/src/status_im/communities/core.cljs index d84ea8f938..29bd4a69c4 100644 --- a/src/status_im/communities/core.cljs +++ b/src/status_im/communities/core.cljs @@ -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] diff --git a/src/status_im/ethereum/json_rpc.cljs b/src/status_im/ethereum/json_rpc.cljs index af30565445..a304655bad 100644 --- a/src/status_im/ethereum/json_rpc.cljs +++ b/src/status_im/ethereum/json_rpc.cljs @@ -128,6 +128,7 @@ "multiaccounts_storeIdentityImage" {} "multiaccounts_deleteIdentityImage" {} "wakuext_createCommunity" {} + "wakuext_editCommunity" {} "wakuext_createCommunityChat" {} "wakuext_inviteUsersToCommunity" {} "wakuext_shareCommunity" {} diff --git a/src/status_im/ui/screens/communities/create.cljs b/src/status_im/ui/screens/communities/create.cljs index c2d6821f65..55861ea4e1 100644 --- a/src/status_im/ui/screens/communities/create.cljs +++ b/src/status_im/ui/screens/communities/create.cljs @@ -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]} (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]} ( - [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]} (