Skip to content

Commit

Permalink
Improve nudges display
Browse files Browse the repository at this point in the history
  • Loading branch information
blackforestboi committed Jun 8, 2024
1 parent 7995f6f commit b702384
Show file tree
Hide file tree
Showing 9 changed files with 44 additions and 28 deletions.
2 changes: 1 addition & 1 deletion external/@worldbrain/memex-common
4 changes: 2 additions & 2 deletions src/authentication/upgrade-modal/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ const Powerups = [
powerUps: {
basic: {
title: 'Basic',
subTitle: `${DEFAULT_POWERUP_LIMITS.bookmarksPowerUp} uniquely new pages per month. Every page saved, annotated or added to a Space counts once, forever.`,
subTitle: `${DEFAULT_POWERUP_LIMITS.bookmarksPowerUp} uniquely new pages per day. Every page saved, annotated or added to a Space counts once, forever.`,
pricing: 'Free',
},
pro: {
Expand All @@ -549,7 +549,7 @@ const Powerups = [
powerUps: {
basic: {
title: 'Basic',
subTitle: `${DEFAULT_POWERUP_LIMITS.AIpowerup} page sessions per month with Claude-3-Haiku and GPT-3.5-Turbo`,
subTitle: `${DEFAULT_POWERUP_LIMITS.AIpowerup} page sessions per day with Claude-3-Haiku and GPT-3.5-Turbo`,
pricing: 'Free',
},
pro: {
Expand Down
4 changes: 2 additions & 2 deletions src/content-scripts/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ export const ONBOARDING_NUDGES_STORAGE = '@onboarding-nudges'

export const ONBOARDING_NUDGES_DEFAULT = {
enabled: true, // should the onboarding nudge be shown at all
bookmarksCount: 5, // how many times a page has been scrolled down
youtubeSummaryCount: 5, // how many times a youtube video has been opened
bookmarksCount: 4, // how many times a page has been scrolled down
youtubeSummaryCount: 4, // how many times a youtube video has been opened
youtubeTimestampCount: 0, // how many times a youtube video has been opened
pageSummaryCount: 0, // how many times did the user encounter a long article worth summarising
}
Expand Down
20 changes: 17 additions & 3 deletions src/content-scripts/content_script/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1644,11 +1644,12 @@ export async function main(
const pageHeight = document.documentElement.scrollHeight
const elapsedTime = Date.now() - tabOpenedTime

if (scrollPosition > 0.3 * pageHeight && elapsedTime > 1) {
if (scrollPosition > 0.3 * pageHeight && elapsedTime > 10000) {
const shouldShow = await updateNudgesCounter(
'bookmarksCount',
browser,
)
removeScrollListener()
if (shouldShow) {
await inPageUI.showRibbon({ action: 'bookmarksNudge' })
}
Expand All @@ -1657,10 +1658,23 @@ export async function main(

const debouncedCheckScrollPosition = debounce(checkScrollPosition, 2000)

document.addEventListener('scroll', debouncedCheckScrollPosition)
const excludedPages = [
'https://x.com/',
'https://twitter.com/',
'https://twitter.com/messages',
'https://www.facebook.com/',
'https://www.instagram.com/',
'https://www.pinterest.com/',
'https://web.whatsapp.com/',
'https://web.telegram.org/',
]

if (!excludedPages.includes(window.location.href) && !pageHasBookark) {
document.addEventListener('scroll', debouncedCheckScrollPosition)
}

function removeScrollListener() {
window.removeEventListener('scroll', checkScrollPosition)
document.removeEventListener('scroll', debouncedCheckScrollPosition)
}

if (analyticsBG && hasActivity) {
Expand Down
6 changes: 3 additions & 3 deletions src/in-page-ui/ribbon/react/components/ribbon.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export interface Props extends RibbonSubcomponentProps {
showFeed: boolean
toggleAskAI: (instaExecute: boolean) => void
showBookmarksNudge: boolean
setShowBookmarksNudge: (value: boolean, snooze: boolean) => void
setShowBookmarksNudge: (value: boolean, disable?: boolean) => void
toggleRabbitHole: () => void
toggleQuickSearch: () => void
openPDFinViewer: () => void
Expand Down Expand Up @@ -959,8 +959,8 @@ export default class Ribbon extends Component<Props, State> {
'Hover over the brain icon or use hotkeys to save with Memex.',
this.getHotKey('createBookmark', 'medium'),
'450px',
() => this.props.setShowBookmarksNudge(false, false), // hide forever
() => this.props.setShowBookmarksNudge(false, true), // snooze
() => this.props.setShowBookmarksNudge(false, true), // hide forever
() => this.props.setShowBookmarksNudge(false, false), // snooze
this.props.getRootElement,
this.memexLogoRef.current,
'top-end',
Expand Down
5 changes: 2 additions & 3 deletions src/in-page-ui/ribbon/react/containers/ribbon/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ export default class RibbonContainer extends StatefulUIElement<
this.props.inPageUI.hideRibbon()
this.processEvent('setShowBookmarksNudge', {
value: true,
snooze: null,
})
}
}
Expand Down Expand Up @@ -199,10 +198,10 @@ export default class RibbonContainer extends StatefulUIElement<
)
}}
showBookmarksNudge={this.state.showBookmarksNudge}
setShowBookmarksNudge={(value, snooze) => {
setShowBookmarksNudge={(value, disable) => {
this.processEvent('setShowBookmarksNudge', {
value,
snooze,
disable,
})
}}
toggleAskAI={(instaExecute: boolean) => {
Expand Down
4 changes: 2 additions & 2 deletions src/in-page-ui/ribbon/react/containers/ribbon/logic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export type RibbonContainerEvents = UIEvent<
setTutorialId: { tutorialIdToOpen: string }
toggleShowTutorial: null
toggleFeed: null
setShowBookmarksNudge: { value: boolean; snooze: boolean }
setShowBookmarksNudge: { value: boolean; disable?: boolean }
toggleReadingView: null
toggleAskAI: boolean | null
deletePage: null
Expand Down Expand Up @@ -977,7 +977,7 @@ export class RibbonContainerLogic extends UILogic<
showBookmarksNudge: { $set: event.value },
})

if (!event.snooze) {
if (event.disable) {
await disableNudgeType(
'bookmarksCount',
this.dependencies.browserAPIs,
Expand Down
3 changes: 2 additions & 1 deletion src/search-injection/img-action-buttons.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ export const handleRenderImgActionButtons = async (
const currentUrl = window.location.href

if (arrayOfSpecialCases.some((url) => currentUrl.includes(url))) {
element = element.parentNode.parentNode.parentNode
element = element.parentNode.parentNode
.parentNode as HTMLImageElement
if (element.getAttribute('jsaction')) {
element.setAttribute('jsaction', null)
}
Expand Down
24 changes: 13 additions & 11 deletions src/util/nudges-utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,20 +26,22 @@ export async function updateNudgesCounter(
return false
} else {
nudgeKeyCount = nudgeKeyCount + 1
if (nudgeKeyCount > ONBOARDING_NUDGES_MAX_COUNT[nudgeType]) {
nudgeKeyCount = 0
}

onboardingNudgesValues[nudgeType] = nudgeKeyCount

await browserAPIs.storage.local.set({
[ONBOARDING_NUDGES_STORAGE]: onboardingNudgesValues,
})

if (nudgeKeyCount === ONBOARDING_NUDGES_MAX_COUNT[nudgeType]) {
await browserAPIs.storage.local.set({
[ONBOARDING_NUDGES_STORAGE]: onboardingNudgesValues,
})
return true
} else {
if (nudgeKeyCount > ONBOARDING_NUDGES_MAX_COUNT[nudgeType]) {
nudgeKeyCount = 0
}
await browserAPIs.storage.local.set({
[ONBOARDING_NUDGES_STORAGE]: onboardingNudgesValues,
})

return false
}
return false
}
}
export async function disableNudgeType(
Expand Down Expand Up @@ -171,7 +173,7 @@ const NudgeBottomNote = styled.div`
color: ${(props) => props.theme.colors.blac};
font-size: 12px;
text-align: center;
border-top: 1px solid ${(props) => props.theme.colors.white};
/* border-top: 1px solid ${(props) => props.theme.colors.white}; */
box-sizing: border-box;
width: 100%;
margin-top: 15px;
Expand Down

0 comments on commit b702384

Please sign in to comment.