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

New Tab Page: Wait for prefs to make their way to state before deciding whether Brave News should peek or not #16757

Merged
merged 1 commit into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 25 additions & 14 deletions components/brave_new_tab_ui/containers/newTab/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -144,20 +144,6 @@ class NewTabPage extends React.Component<Props, State> {
this.trackBrandedWallpaperNotificationAutoDismiss()
}
this.checkShouldOpenSettings()
// Only prompt for brave today if we're not scrolling down.
const shouldPromptBraveToday =
this.props.newTabData.featureFlagBraveNewsPromptEnabled &&
this.props.newTabData.showToday &&
!this.props.todayData.articleScrollTo
if (shouldPromptBraveToday) {
this.braveNewsPromptTimerId = window.setTimeout(() => {
if (window.scrollY > 0) {
// Don't do anything if user has already scrolled
return
}
this.setState({ isPromptingBraveToday: true })
}, 1700)
}
const searchPromotionEnabled = this.props.newTabData.searchPromotionEnabled
this.setState({
showSearchPromotion: searchPromotionEnabled,
Expand All @@ -174,6 +160,7 @@ class NewTabPage extends React.Component<Props, State> {
}

componentDidUpdate (prevProps: Props) {
this.maybePeekBraveNews()
const oldImageSource = GetBackgroundImageSrc(prevProps)
const newImageSource = GetBackgroundImageSrc(this.props)
this.imageSource = newImageSource
Expand All @@ -196,6 +183,30 @@ class NewTabPage extends React.Component<Props, State> {
}
}

maybePeekBraveNews () {
const hasPromptedBraveNews = !!this.braveNewsPromptTimerId
const shouldPromptBraveNews =
!hasPromptedBraveNews && // Don't start a prompt if we already did
window.scrollY === 0 && // Don't start a prompt if we are scrolled
this.props.newTabData.featureFlagBraveNewsPromptEnabled &&
this.props.newTabData.initialDataLoaded && // Wait for accurate showToday
this.props.newTabData.showToday &&
// Don't prompt if the user has navigated back and we're going to scroll
// down to a previous place in the feed.
!this.props.todayData.articleScrollTo
if (shouldPromptBraveNews) {
this.braveNewsPromptTimerId = window.setTimeout(() => {
if (window.scrollY > 0) {
// If the user happens to start scrolling whilst waiting for the timer,
// make sure we cancel the timer otherwise content will shift and provide
// a poor UX.
return
}
this.setState({ isPromptingBraveToday: true })
}, 1700)
}
}

shouldOverrideReadabilityColor (newTabData: NewTab.State) {
return !newTabData.brandedWallpaper && newTabData.backgroundWallpaper?.type === 'color' && !isReadableOnBackground(newTabData.backgroundWallpaper)
}
Expand Down