-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add <Onboarding/> Component * Adjust softkey styling * Add Onboarding utils and onboarding route * bump cypress version * Rename the key to prevent confusion with value Boolean * 🚨 Fix test spec * working tests skipping onboarding * Revert "working tests skipping onboarding" This reverts commit 7aa461b. * Update code review * 🚨 update test spec * don't show the background image for the first onboard image Co-authored-by: jose pita <[email protected]>
- Loading branch information
Showing
21 changed files
with
158 additions
and
18 deletions.
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,54 @@ | ||
import { h } from 'preact' | ||
import { useState, useEffect } from 'preact/hooks' | ||
import { route } from 'preact-router' | ||
import { useSoftkey, useI18n } from 'hooks' | ||
import { onboarding } from 'utils' | ||
|
||
export const Onboarding = () => { | ||
const i18n = useI18n() | ||
const [currentIndex, setCurrentIndex] = useState(0) | ||
const softkey = useSoftkey('onboarding') | ||
|
||
const exitOnboard = () => { | ||
onboarding.markAsDone() | ||
route('/') | ||
} | ||
|
||
const nextOnboard = () => { | ||
setCurrentIndex(currentIndex + 1) | ||
} | ||
|
||
const prevOnboard = () => { | ||
setCurrentIndex(currentIndex - 1) | ||
} | ||
|
||
const getImageBackgroundStyle = index => { | ||
// only the first onboard image doesn't have background image | ||
return index ? { backgroundImage: `url(/images/onboarding-${index}-background.png)` } : {} | ||
} | ||
|
||
const softkeyConfig = [ | ||
{ left: i18n.i18n('softkey-skip'), onKeyLeft: exitOnboard, right: i18n.i18n('softkey-next'), onKeyRight: nextOnboard }, | ||
{ left: i18n.i18n('softkey-back'), onKeyLeft: prevOnboard, right: i18n.i18n('softkey-next'), onKeyRight: nextOnboard }, | ||
{ left: i18n.i18n('softkey-back'), onKeyLeft: prevOnboard, right: i18n.i18n('softkey-next'), onKeyRight: nextOnboard }, | ||
{ left: i18n.i18n('softkey-back'), onKeyLeft: prevOnboard, center: i18n.i18n('softkey-get-started'), onKeyCenter: exitOnboard } | ||
] | ||
|
||
useEffect(() => { | ||
softkey.dispatch({ type: 'replace', config: softkeyConfig[currentIndex] }) | ||
}, [currentIndex]) | ||
|
||
return ( | ||
<div class='onboarding'> | ||
<div class='image' style={getImageBackgroundStyle(currentIndex)}> | ||
<img src={`/images/onboarding-${currentIndex}.png`} /> | ||
</div> | ||
<div class='title'> | ||
{i18n.i18n(`onboarding-${currentIndex}-title`)} | ||
</div> | ||
<div class='description'> | ||
{i18n.i18n(`onboarding-${currentIndex}-description`)} | ||
</div> | ||
</div> | ||
) | ||
} |
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 |
---|---|---|
@@ -1,16 +1,26 @@ | ||
import { h } from 'preact' | ||
import Router from 'preact-router' | ||
import { Router, route } from 'preact-router' | ||
import { createHashHistory } from 'history' | ||
import { Article, Search, Settings, QuickFacts, Language } from 'components' | ||
import { Article, Search, Settings, QuickFacts, Language, Onboarding } from 'components' | ||
import { onboarding } from 'utils' | ||
|
||
export const Routes = ({ onRouteChange }) => ( | ||
<Router history={createHashHistory()} onChange={onRouteChange}> | ||
<Search path='/' /> | ||
<Settings path='/settings' /> | ||
<Article path='/article/:lang/:title/:subtitle?' /> | ||
<QuickFacts path='/quickfacts/:lang/:title' /> | ||
<Language path='/language' /> | ||
</Router> | ||
) | ||
export const Routes = ({ onRouteChange }) => { | ||
const onChange = ({ url }) => { | ||
if (!onboarding.isDone()) { | ||
route('/onboarding') | ||
} | ||
onRouteChange(url) | ||
} | ||
return ( | ||
<Router history={createHashHistory()} onChange={onChange}> | ||
<Onboarding path='/onboarding' /> | ||
<Search path='/' /> | ||
<Settings path='/settings' /> | ||
<Article path='/article/:lang/:title/:subtitle?' /> | ||
<QuickFacts path='/quickfacts/:lang/:title' /> | ||
<Language path='/language' /> | ||
</Router> | ||
) | ||
} | ||
|
||
// todo: export navigation functions |
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
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,11 @@ | ||
const KEY = 'has-onboard-before' | ||
|
||
const isDone = () => { | ||
return !!localStorage.getItem(KEY) | ||
} | ||
|
||
const markAsDone = () => { | ||
localStorage.setItem(KEY, true) | ||
} | ||
|
||
export const onboarding = { isDone, markAsDone } |
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,29 @@ | ||
.onboarding { | ||
font-family: @textFont; | ||
padding: 0 20px; | ||
|
||
.image { | ||
text-align: center; | ||
margin: 15px 0; | ||
background-position: center center; | ||
background-repeat: no-repeat; | ||
background-size: 140px; | ||
|
||
img { | ||
width: 90px; | ||
height: 90px; | ||
} | ||
} | ||
|
||
.title { | ||
font-weight: bold; | ||
font-size: 22px; | ||
line-height: 26px; | ||
} | ||
|
||
.description { | ||
font-size: 12px; | ||
line-height: 17px; | ||
margin-top: 11px; | ||
} | ||
} |
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