This repository has been archived by the owner on Jun 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 28
QMAPS-2033 add "add to home" infobox on mobile after the 5th visit #1161
Draft
xem
wants to merge
3
commits into
master
Choose a base branch
from
QMAPS-2033
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* global _ */ | ||
import React, { useState } from 'react'; | ||
import { Notification } from './ui'; | ||
import { get, set } from 'src/adapters/store'; | ||
|
||
const AddToHomeInfoBox = () => { | ||
const [closed, setClosed] = useState(get('add_to_home_closed')); | ||
const closeBetaPopup = () => { | ||
set('add_to_home_closed', 1); | ||
setClosed(true); | ||
}; | ||
|
||
const visits = parseInt(get('visits') || 0) + 1; | ||
set('visits', visits); | ||
|
||
return ( | ||
// Show popup on mobile, at the fifth visit, if it hasn't already been closed | ||
visits >= 5 && | ||
!closed && ( | ||
<Notification | ||
title={_('Psst, do you come here often ?')} | ||
description={_('Add a Qwant Maps shortcut to your Home screen !')} | ||
type="info" | ||
onClose={closeBetaPopup} | ||
footer={ | ||
<div className="notification-link"> | ||
<a href="#">{_('Follow the guide to add the shortcut')}</a> | ||
</div> | ||
} | ||
/> | ||
) | ||
); | ||
}; | ||
|
||
export default AddToHomeInfoBox; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import React from 'react'; | ||
import cs from 'classnames'; | ||
import { string, func, node, oneOfType } from 'prop-types'; | ||
import { CloseButton } from 'src/components/ui'; | ||
import { IconInformation } from 'src/components/ui/icons'; | ||
import { ACTION_BLUE_BASE } from 'src/libs/colors'; | ||
|
||
const Notification = ({ className = '', title, description, onClose, footer }) => ( | ||
<div className={cs('notification', className)}> | ||
<span className="notification-title"> | ||
<span> | ||
<IconInformation className="u-mr-xs" fill={ACTION_BLUE_BASE} /> | ||
<span role="notification">{title}</span> | ||
</span> | ||
<CloseButton onClick={onClose} position="topRight" /> | ||
</span> | ||
<div className="notification-content"> | ||
<span role="notification">{description}</span> | ||
</div> | ||
{footer} | ||
</div> | ||
); | ||
Notification.propTypes = { | ||
className: string, | ||
title: string.isRequired, | ||
description: oneOfType([string, node]).isRequired, | ||
onClose: func.isRequired, | ||
}; | ||
|
||
export default Notification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
.notification { | ||
position: fixed; | ||
top: 92px; | ||
width: 360px; | ||
right: 12px; | ||
padding: 16px; | ||
border-radius: 12px; | ||
color: $grey-semi-darkness; | ||
background-color: $background; | ||
box-shadow: 0 1px 4px 0 rgba(12, 12, 14, 0.2), 0 0 2px 0 rgba(12, 12, 14, 0.12); | ||
|
||
@media (max-width: 760px) { | ||
width: 200px; | ||
} | ||
|
||
@media (max-width: 640px) { | ||
width: 360px; | ||
top: calc(64px + 16px); | ||
bottom: unset; | ||
right: 12px; | ||
max-width: calc(100vw - 24px); | ||
} | ||
|
||
&-title { | ||
display: inline-flex; | ||
align-items: center; | ||
justify-content: space-between; | ||
width: 100%; | ||
margin-bottom: $spacing-xs; | ||
font-size: 14px; | ||
font-weight: bold; | ||
line-height: 18px; | ||
color: $grey-black; | ||
|
||
> span { | ||
display: inline-flex; | ||
align-items: center; | ||
} | ||
} | ||
|
||
&-content { | ||
color: $grey-semi-darkness; | ||
font-size: 14px; | ||
line-height: 18px; | ||
} | ||
|
||
&-link { | ||
margin: $spacing-xs 0; | ||
cursor: pointer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,10 @@ | |
z-index: 3; | ||
} | ||
|
||
.notification { | ||
z-index: 3; | ||
} | ||
|
||
.modal_overlay { | ||
z-index: 6; | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a good example of a side effect that we want to control more and safely separate from the component rendering.
If we put it here in the render function, we will increment
visits
each time this component is re-rendered, which can happen at any moment in the app not related to a single hit.You can already see it in these cases:
DeviceContext.Provider
)setClosed(true)
To ensure this increment happens only on mounting the component, you could put it inside a
useEffect(…, [ ])
.But this still means if for some reason we unmount and remount this component during a user session, it will be counted twice.
So the safer approach IMO is to update this counter outside this component, where we are 100% sure we'll execute code only once per session. For example, as a sideEffect of
RootComponent
or inapp_panel
. Theget
can still happen here as it doesn't modify anything.