Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixing bug #1706 edit profile from drawer resetting username to default #1733

Merged
merged 1 commit into from
Sep 9, 2017

Conversation

yenda
Copy link
Contributor

@yenda yenda commented Sep 1, 2017

#1706

Summary:

Username is changed to default if Profile screen was opened and user taps on status and username fields

The pull request solves the bug by reworking the way state is stored for profile editing.
Before the drawer profile was in local state and the profile was in app-db. This PR puts everything into the app-db and simplifies future UX changes by defining small events for each user action.

Tests are also adapted to reflect the changes (only simple cases of status changes, maybe in the future some generative testing could be used to check more complex events, or at least more cases could be added). I also removed the phone change test because it was not a phone change test

Behaviors tested on Android emulator

  • status field is unfocused and saved in drawer and unfocused in edit screen when pressing linebreak
  • when name is invalid the save button is not available in edit profile screen and reverted to placeholder if saved
  • when name is invalid the name is shown in red in the drawer

Additional UX improvements tested:

  • when name is invalid in drawer and saved it is reverted to placeholder (instead of previous name)
  • when exiting the edit-profile screen without saving the state is kept unless user edits from drawer (instead of lost as soon as user goes back to profile screen)
  • pressing the vertical dots icon in the drawer while editing name or status saves it and goes to profile screen (before it was not saving)

Steps to test:

  • Open Status
  • Open drawer, go to profile screen
  • Go back and tap status then username screen

status: ready

@yenda yenda changed the title Fixing bug #1706 edit profile from drawer resetting username to default [WIP] Fixing bug #1706 edit profile from drawer resetting username to default Sep 1, 2017
@yenda yenda force-pushed the bug/username-changed-to-default branch 2 times, most recently from 67e5a62 to 81b407a Compare September 2, 2017 00:12
@yenda yenda self-assigned this Sep 2, 2017
@yenda yenda changed the title [WIP] Fixing bug #1706 edit profile from drawer resetting username to default Fixing bug #1706 edit profile from drawer resetting username to default Sep 2, 2017
@yenda yenda force-pushed the bug/username-changed-to-default branch from 81b407a to 71b0aca Compare September 2, 2017 07:51
(close-drawer)
(when-let [save-event @(rf/subscribe [:my-profile.drawer/save-event])]
(rf/dispatch [save-event]))
(rf/dispatch [:navigate-to :accounts]))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both block of code are very similar. Maybe introduce a function?

[view
[ci/chat-icon (:photo-path account) {:size 52}]]])
(letsubs [account [:get-current-account]]
[touchable-opacity {:on-press #(navigate-to-profile)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just navigate-to-profile ?

{:on-press (fn []
(close-drawer)
(rf/dispatch [:navigate-to :my-profile]))}
{:on-press #(navigate-to-profile)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

{:on-press (fn []
(close-drawer)
(rf/dispatch [:navigate-to :accounts]))}
{:on-press #(navigate-to-accounts)}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment

{:keys [name public-key]} (get-current-account db)]
{:db (cond-> db
(not default-name) (assoc :my-profile/default-name (gfycat/generate-gfy public-key))
:always (assoc-in [:my-profile/drawer :name] name))})))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am more used to see :else. I don't know if we have such convention in the project.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We used true in some places, but i like :always much more than true tbh. And :else isn't quite correct here, because other branches can be executed as well.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indeed :always is more appropriate for cond->.

:<- [:get-current-account]
:<- [:get :my-profile/drawer]
(fn [[current-account profile] [_ k]]
(or (get profile k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both blocks are similar. Introduce a function?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

(reg-sub :my-profile.drawer/valid-name?
:<- [:get :my-profile/drawer]
(fn [profile]
(get profile :valid-name? true)))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure how to introduce a function there it is subscriptions, the idea is that it only recomputes when the profile or drawer changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(or (get ..) (get ..)) is used for 2 subscriptions. This part could be abstracted?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it is worth trading 2 lines for a function and an indirection

(assoc-in [:my-profile/profile :edit-status?] edit-status?)
(update-in [:my-profile/profile]
#(merge (select-keys (get-current-account db) db/account-profile-keys) %)))]
{:db new-db
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

alignment in map

@yenda yenda force-pushed the bug/username-changed-to-default branch from 71b0aca to 1951698 Compare September 4, 2017 08:46
@annadanchenko
Copy link

#1746 Default username becomes empty if open Profile screen [bug/username-changed-to-default] is introduced by this PR
still testing

@yenda yenda force-pushed the bug/username-changed-to-default branch from 1951698 to d93d300 Compare September 4, 2017 23:09
@annadanchenko
Copy link

annadanchenko commented Sep 5, 2017

Wrong QR code (picture - if scan then no public key is recognized), no username and no avatar is shown on Show QR opened on Profile screen. Same issue for Show QR of the Public key and Address.
screenshot_20170905-111340

Test session (from 00:50) https://app.testfairy.com/projects/4803622-status/builds/6498278/sessions/3/?accessToken=Sw2XZ7nnooCNL6a49kGzIbIeia4

Steps:

  • Open Status and sign in
  • Open drawer
  • Tap on 3 dots icon to open Profile screen
  • Tap on Show QR
  • Check values shown on the screen. Try to scan QR by another device with Status to add it as a contact
  • Return to Profile screen
  • Next to Public key tap on 3 dots and select Show QR.
  • Check values shown on the screen. Try to scan QR by another device with Status to add it as a contact

On both Android and iOS, build #6 for bug/username-changed-to-defaulthttp://185.90.37.243:8080/job/Github%20Org%20Builder/job/status-react/job/bug%252Fusername-changed-to-default/

@yenda yenda force-pushed the bug/username-changed-to-default branch from d93d300 to f34c98a Compare September 5, 2017 08:30
@yenda
Copy link
Contributor Author

yenda commented Sep 5, 2017

The QR code bug was caused by a missing import:

With the refactoring the navigation code got moved from events to navigation namespace and navigation namespace has to be imported in events otherwise the code is never there. In this case there was data to be pre-loaded when opening the qr-code modal window that was not anymore.

@yenda yenda force-pushed the bug/username-changed-to-default branch from f34c98a to deb1dbb Compare September 5, 2017 09:39
@@ -34,60 +34,70 @@
(defn open-drawer [] (.openDrawer @drawer-atom))
(defn close-drawer [] (.closeDrawer @drawer-atom))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about calling this open-drawer! to signify side effect? Same with close-drawer and possibly save-profile.

status [:my-profile.drawer/get :status]]
(let [placeholder (i18n/label :t/update-status)]
[view st/status-container
(if edit-status?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd consider breaking these two vectors out into util fns so if statement is clear, no need for newline then

@@ -6,6 +6,8 @@
[status-im.constants :as constants]
[status-im.utils.homoglyph :as homoglyph]))

(def account-profile-keys [:name :photo-path :status])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this always used as a cursor? If so I think we should indicate it as such, e.g. photo-status-path or something

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not a cursor it is a list of keys to select from the profile when extracting profile

:on-change-text #(dispatch [:set-in [:my-profile/edit :name] %])}]]))
[text-input-with-label
{:label (label :t/name)
:default-value profile-name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Align

[react/view styles/edit-profile-status
[react/scroll-view
(if edit-status?
[react/text-input
{:ref #(reset! input-ref %)
:auto-focus edit-status?
{:auto-focus (if edit-status? true false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this just edit-status? would consider renaming it to auto-focus?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about this one, the focus can be on something else, auto-focus in the app-db wouldn't be really helpful to figure our what it implies. Here it means user is editing the status field.

:<- [:get-current-account]
:<- [:get :my-profile/drawer]
(fn [[current-account profile] [_ k]]
(or (get profile k)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed

{:db new-db
:dispatch-n [[:check-status-change status]
[:account-update {:status status}]]}))))

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we would like to have :check-status-change and :account-update refactored into pure functions and just call them there instead of the dispatch, but I understand it's not focus of this PR and it's another module (accounts), so it can be done later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it's an old part of the code where there is still ui/side-effects

@annadanchenko
Copy link

annadanchenko commented Sep 5, 2017

  1. Wrong QR code is fixed in last build
  2. Pressing save button in edit profile screen return to profile screen - OK

New issue: #1769 picture is not saved as avatar if use Capture. After tap on camera icon Edit profile screen is shown but avatar contains old default picture

@yenda yenda force-pushed the bug/username-changed-to-default branch 2 times, most recently from 1ad5d20 to 9044db9 Compare September 6, 2017 18:24
@annadanchenko
Copy link

annadanchenko commented Sep 7, 2017

#1769 is fixed.
New issue is found in this PR, can't reproduce it on develop build: #1778 Username of the first account is changed to the username of second account on same device [bug/username-changed-to-default]

@yenda yenda force-pushed the bug/username-changed-to-default branch from 9044db9 to 4ced8d4 Compare September 7, 2017 12:41
@asemiankevich asemiankevich self-assigned this Sep 8, 2017
@asemiankevich
Copy link
Contributor

Looks good, #1769
#1746
#1747
#1706 are not reproducible, QR issue is also fixed

@yenda yenda force-pushed the bug/username-changed-to-default branch from 3686067 to 26db180 Compare September 8, 2017 14:34
@rasom rasom merged commit ab98de0 into develop Sep 9, 2017
@rasom rasom deleted the bug/username-changed-to-default branch September 9, 2017 04:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants