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

[User Settings] Add new Preferences view #1716

Merged
merged 33 commits into from
Mar 23, 2021

Conversation

Maftalion
Copy link
Contributor

@Maftalion Maftalion commented Mar 11, 2021

Details

  • Add new toggle on the settings/preferences page to allow users to toggle their expensifyNewsStatus value

Fixed Issues

#1677

Tests

  1. Go to profile by clicking your avatar
  2. Click on preferences
  3. Toggle and confirm expensifyNewsStatus is being updated

Tested On

  • Web
  • Mobile Web
  • Desktop
  • iOS
  • Android

Video

Screen.Recording.2021-03-09.at.3.48.10.PM.mov

Web

Screen Shot 2021-03-09 at 3 50 48 PM

Mobile Web

Screen Shot 2021-03-09 at 3 51 38 PM

Desktop

Screen Shot 2021-03-09 at 3 52 50 PM

iOS

Screen Shot 2021-03-09 at 3 48 42 PM

Android

Screen Shot 2021-03-09 at 3 51 54 PM

@Maftalion Maftalion requested a review from a team as a code owner March 11, 2021 00:54
@botify botify requested review from bondydaa and removed request for a team March 11, 2021 00:54
src/pages/home/HomePage.js Outdated Show resolved Hide resolved
@Maftalion
Copy link
Contributor Author

@shawnborton updated

Screen Shot 2021-03-11 at 9 08 41 AM

Screen Shot 2021-03-11 at 9 08 29 AM

@shawnborton
Copy link
Contributor

Looks great! Perhaps we can make the margin below the first block slightly bigger to creates some more visual separation? Maybe like mb-6 or something?

value={priorityMode}
Icon={() => <Icon src={DownArrow} />}
/>
class PreferencesPage extends Component {
Copy link
Contributor

Choose a reason for hiding this comment

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

why did you convert this from a functional component? couldn't we keep it as a functional component and pass user as a prop like we were doing before with priorityMode?

The state you've added should be handled already by Onyx so as long as the isOn is bound to the prop user.expensifyNewsStatus I'm pretty sure it will update properly without the need for this to be a regular/pure component and reference state.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hey, so this was the direction I went down to follow the "offline first" approach. Basically if it was going purely based off the user.expensifyNewsStatus then it would seem unresponsive/slow for users with no or slow connections. I guess a nice follow up to handle the errors would be to show a toast & reset back to the initial onyx value but I believe that's out of scope.

I can also revert it back to a func component and go solely off the prop if needed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm I see that does make sense now but that makes me question whether the User.setExpensifyNewsStatus should first be setting the data in onyx and then calling the API.

cc @tgolen what are your thoughts on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the idea of optimistically setting the value in Onyx before calling the API, yeah. Then if the API fails, the Onyx data can be reset.

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmm, I'm not sure I agree with this, as I think we're going to end up with a lot of duplicated code with having to handle the case where we don't get a response at all and when we get a failed response (see here). I get that we want to keep that offline first functionality though, so I'm not really sure which is the best route to go.

@marcaaron this didn't get brought up when I first added User.setExpensifyNewsStatus so I'm curious to see if you have opinions on this.

Copy link
Contributor

Choose a reason for hiding this comment

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

I like the optimistic approach here as well. Only thought is that we should consider updating the value of this data with the data returned from the response instead of relying purely on response codes - but it's probably OK with this particular setting being a boolean and all.

I'm also inclined to wait and see how many examples like this we end up with (though I agree it will be a lot eventually). Would love to see a more elegant or baked in approach to this optimistic response pattern soon!

src/pages/settings/PreferencesPage.js Outdated Show resolved Hide resolved
src/pages/settings/PreferencesPage.js Outdated Show resolved Hide resolved
src/pages/settings/PreferencesPage.js Outdated Show resolved Hide resolved
@NikkiWines NikkiWines linked an issue Mar 15, 2021 that may be closed by this pull request
# Conflicts:
#	config/webpack/webpack.common.js
#	src/pages/home/HomePage.js
#	src/pages/settings/PreferencesPage.js
Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

Tested and work well! No idea if this is something we can change but I noticed a funny little animation when we navigate to the Preferences page and you are subscribed to Expensify news.

Screen.Recording.2021-03-16.at.4.30.11.PM.mov

src/libs/Navigation/AppNavigator/AuthScreens.js Outdated Show resolved Hide resolved
@Maftalion
Copy link
Contributor Author

Tested and work well! No idea if this is something we can change but I noticed a funny little animation when we navigate to the Preferences page and you are subscribed to Expensify news.

@NikkiWines yeah, noticed that as well. It looks like it's initialized to "off" and gets animated to "on":
https://github.com/aminebenkeroum/toggle-switch-react-native/blob/master/ToggleSwitch.js#L89

but looking at this closer...it seems inefficient that it's doing everything in the render rather than watching for prop changes. it looks like a pretty simple component if we wanted to re-create it and modify it instead of using the package.

@shawnborton
Copy link
Contributor

@Maftalion is there a way to customize how the toggle itself looks? In our mockups, we have the toggle at 50px wide by 28px tall, with the inner button at 22px by 22px.

@Maftalion
Copy link
Contributor Author

@shawnborton yup, updated the styles on the track/thumb:
Screen Shot 2021-03-17 at 7 05 42 AM

@Maftalion
Copy link
Contributor Author

Maftalion commented Mar 17, 2021

@roryabraham AFAIK the switch component isn't customizable enough to meet the design expectations: https://reactnative.dev/docs/switch. For example you can control thumb/track color but not it's height/width. Also you can't make all platforms render the "iOS switch".

But yeah what I'm suggesting is if we don't want to use the 3rd party library, we can just create a components/switch component and implement something similar that's pure JS that fits the needs of design parity across all platforms.

@tgolen
Copy link
Contributor

tgolen commented Mar 17, 2021

we can just create a components/switch component and implement something similar that's pure JS that fits the needs of design parity across all platforms.

+💯

We should definitely do this. I don't think it will be very difficult at all. This helps to ensure consistent code patterns in our components which lowers the barrier of entry to other people who need to work on this.

@shawnborton
Copy link
Contributor

@Maftalion I also wanted to confirm again if you know what's going on with the picker menus? It looks like this exists on the current app, so this might not be your doing, but the border radius is now set to 0 instead of matching other inputs:
image

@Maftalion
Copy link
Contributor Author

@shawnborton hmm looks like it's using variables.componentBorderRadius which doesn't exist
https://github.com/Expensify/Expensify.cash/blob/master/src/styles/variables.js

@Maftalion
Copy link
Contributor Author

Swapped to use the new Switch component, here's On/Off screenshots:

Screen Shot 2021-03-18 at 9 30 43 AM
Screen Shot 2021-03-18 at 9 30 47 AM

Screen Shot 2021-03-18 at 9 31 03 AM

Screen Shot 2021-03-18 at 9 31 08 AM

Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

One minor minor comment, but overall looking great! Tested on web and works well

src/components/Switch.js Outdated Show resolved Hide resolved
@shawnborton
Copy link
Contributor

@shawnborton hmm looks like it's using variables.componentBorderRadius which doesn't exist
https://github.com/Expensify/Expensify.cash/blob/master/src/styles/variables.js

@Maftalion do you mind adding that variable back in? It should have a value of 8

@Maftalion
Copy link
Contributor Author

@shawnborton sure! added that back in:
Screen Shot 2021-03-19 at 8 41 19 AM

@shawnborton
Copy link
Contributor

Looks great, thank you!

NikkiWines
NikkiWines previously approved these changes Mar 20, 2021
Copy link
Contributor

@NikkiWines NikkiWines left a comment

Choose a reason for hiding this comment

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

Looks good!

Copy link
Contributor

@bondydaa bondydaa left a comment

Choose a reason for hiding this comment

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

looks good overall just one thing I think we should do with the switch component.

src/components/Switch.js Show resolved Hide resolved
src/components/Switch.js Show resolved Hide resolved
src/components/Switch.js Show resolved Hide resolved
bondydaa
bondydaa previously approved these changes Mar 23, 2021
Copy link
Contributor

@bondydaa bondydaa left a comment

Choose a reason for hiding this comment

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

actually I'm reversing course on my last comments, I think your points are valid and not worth the refactor to functional component with so many unknowns or potential drawbacks.

# Conflicts:
#	src/styles/styles.js
@Maftalion Maftalion dismissed stale reviews from bondydaa and NikkiWines via 41ae751 March 23, 2021 19:37
@bondydaa
Copy link
Contributor

nikki had already approved and the only new changes are fixing merge conflicts so i'm going to merge. marc and I also chatted about this PR 1:1 so i'm considered that an implicit approval too. merging so we get wrap this up as i've caused it to be drawn out for way too long already.

@bondydaa bondydaa merged commit 163efa2 into Expensify:master Mar 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[User Settings] Add new Preferences view
7 participants