Skip to content

Updates NTP's Sponsored Images toggle functionality. #16895

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

Merged
merged 2 commits into from
Feb 14, 2023

Conversation

mkarolin
Copy link
Collaborator

Resolves brave/brave-browser#27304

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

@mkarolin mkarolin self-assigned this Jan 27, 2023
@github-actions github-actions bot added the CI/storybook-url Deploy storybook and provide a unique URL for each build label Jan 27, 2023
@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

Copy link
Collaborator

@sangwoo108 sangwoo108 left a comment

Choose a reason for hiding this comment

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

This looks good to me! But you might want to wait for reviews from @petemill or @fallaciousreasoning

Copy link
Contributor

@fallaciousreasoning fallaciousreasoning left a comment

Choose a reason for hiding this comment

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

LGTM, with a few (mostly optional) nits

@@ -301,7 +302,10 @@ class NewTabPage extends React.Component<Props, State> {

startRewards = () => {
const { rewardsState } = this.props.newTabData
if (!rewardsState.rewardsEnabled) {
if (!rewardsState.rewardsEnabled ||
(rewardsState.externalWallet &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit:

Suggested change
(rewardsState.externalWallet &&
rewardsState.externalWallet?.status === mojom.WalletStatus.kConnected

canSupportAds={!!this.props.newTabData.rewardsState.adsSupported}/>
canSupportAds={!!this.props.newTabData.rewardsState.adsSupported}
isExternalWalletConnected={
!!this.props.newTabData.rewardsState.externalWallet &&
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit:

Suggested change
!!this.props.newTabData.rewardsState.externalWallet &&
this.props.newTabData.rewardsState.externalWallet?.status !== mojom.WalletStatus.kNotConnected


import * as React from 'react'

export function SponsoredImageInfoIcon () {
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional:

This doesn't need to be a functional component as it doesn't take any props, so you can just assign it to a constant:

const SponsoredImageInfoIcon = <svg ....> .... </svg>

And then use it like this:

import SponsoredImageInfoIcon from '...'
// .
// .
// .
return <div>
     {SponsoredImageInfoIcon}
</div>

Copy link
Member

Choose a reason for hiding this comment

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

Semi-related question: If we had a lot of components using this pattern in our codebase, does it negatively affect performance for sessions which don't result in uses of those components. Instead of exporting functions that don't get called, there would instead be a lot of React.createClass calls during initial JS module parsing. A single (or a few hundred??) instances of this of course won't matter, but it would be interesting to know if this is a best practice and at what point it causes negative impact.

return getLocale('sponsoredImageOnDescription')
}

function GetDescriptionText (rewardsEnabled: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think functions should be lower case (except for components) to fit in with most other stuff. This is pretty inconsistently enforced though (sorry)

Suggested change
function GetDescriptionText (rewardsEnabled: boolean,
function getDescriptionText (rewardsEnabled: boolean,

`

export default function SponsoredImageToggle ({ onChange, onEnableRewards, checked, disabled, rewardsEnabled: rewardEnabled, adsEnabled, canSupportAds }: Props) {
const showRewardButton = checked && !disabled && (!rewardEnabled || (!adsEnabled && canSupportAds))
function GetInfoTooltipText (checked: boolean, rewardsEnabled: boolean) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think functions should be lower case (except for components) to fit in with most other stuff. This is pretty inconsistently enforced though (sorry)

Suggested change
function GetInfoTooltipText (checked: boolean, rewardsEnabled: boolean) {
function getInfoTooltipText (checked: boolean, rewardsEnabled: boolean) {

return getLocale('sponsoredImageOnAdsOff')
}

function GetButtonText (rewardsEnabled: boolean,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: I think functions should be lower case (except for components) to fit in with most other stuff. This is pretty inconsistently enforced though (sorry)

Suggested change
function GetButtonText (rewardsEnabled: boolean,
function getButtonText (rewardsEnabled: boolean,

@mkarolin
Copy link
Collaborator Author

Thanks @fallaciousreasoning, all great points. Addressed in 23d9e1a

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@mkarolin mkarolin force-pushed the maxk-ntp-settings-si-toggle-update branch from 23d9e1a to 8330e4e Compare January 31, 2023 14:20
@mkarolin
Copy link
Collaborator Author

Squashed commits.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

display: none;
}

&:hover .tooltip {
Copy link
Member

Choose a reason for hiding this comment

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

This won't show for non-mouse users. I think it could be pretty trivial to have the tooltip show when the icon is focused. Could you try?

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Just some issues with positioning in rtl and keyboard activation

.tooltip {
position: absolute;
bottom: 100%;
left: -200px;
Copy link
Member

Choose a reason for hiding this comment

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

In RTL UI (which you can force and still keep english via chrome://flags), this is making the text get clipped
image

This could get fixed by the following (as I can't think of a better way right now!):

[dir=rtl] & {
  right: -200px;
}

Unfortunately that puts the arrow in the wrong place, so that also needs repositioning similarly.
image

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@petemill inset-inline-start seems to work for both directions. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

@petemill It also looks like toggles' bullet doesn't move correctly to the ON position with RTL set.

@brave-builds
Copy link
Collaborator

A Storybook has been deployed to preview UI for the latest push

@mkarolin mkarolin requested a review from petemill February 3, 2023 20:23
@mkarolin
Copy link
Collaborator Author

mkarolin commented Feb 6, 2023

@petemill, could you, please, take another look. Thanks

@mkarolin
Copy link
Collaborator Author

Updated screenshots:

LTRRTL

Copy link
Member

@petemill petemill left a comment

Choose a reason for hiding this comment

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

Thanks for addressing!

@mkarolin mkarolin merged commit 4262787 into master Feb 14, 2023
@mkarolin mkarolin deleted the maxk-ntp-settings-si-toggle-update branch February 14, 2023 01:35
@mkarolin mkarolin added this to the 1.50.x - Nightly milestone Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI/storybook-url Deploy storybook and provide a unique URL for each build
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve Rewards text on Sponsored Images toggle in background settings
6 participants