Skip to content

Commit

Permalink
feat(neuron-ui): limit the times of guide bubble to 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Keith-CY committed Nov 15, 2019
1 parent 59f2dd5 commit 9b85589
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/neuron-ui/src/containers/Footer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useTranslation } from 'react-i18next'
import { Stack, getTheme, Text, ProgressIndicator, Icon, TooltipHost, TeachingBubble } from 'office-ui-fabric-react'

import { openExternal } from 'services/remote'
import { guideBubbleTimes } from 'services/localCache'
import { StateWithDispatch } from 'states/stateProvider/reducer'
import { NeuronWalletContext } from 'states/stateProvider'
import { ConnectionStatus, FULL_SCREENS, RUN_NODE_GUIDE_URL, Routes } from 'utils/const'
Expand Down Expand Up @@ -79,8 +80,9 @@ const Footer = ({
const [showGuide, setShowGuide] = useState(false)

useEffect(() => {
if (connectionStatus !== ConnectionStatus.Online) {
if (connectionStatus !== ConnectionStatus.Online && guideBubbleTimes.getRemaining()) {
setShowGuide(true)
guideBubbleTimes.reduce()
} else {
setShowGuide(false)
}
Expand Down
14 changes: 14 additions & 0 deletions packages/neuron-ui/src/services/localCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ export enum LocalCacheKey {
CurrentWallet = 'currentWallet',
CurrentNetworkID = 'currentNetworkID',
SystemScript = 'systemScript',
GuideBubbleTimes = 'guideBubbleTimes',
}

export const addresses = {
Expand Down Expand Up @@ -122,6 +123,18 @@ export const systemScript = {
},
}

export const guideBubbleTimes = {
getRemaining: () => {
const t = window.localStorage.getItem(LocalCacheKey.GuideBubbleTimes)
const remaining = t === null ? 3 : +t
return remaining
},
reduce: () => {
const remaining = guideBubbleTimes.getRemaining()
window.localStorage.setItem(LocalCacheKey.GuideBubbleTimes, `${Math.max(remaining - 1, 0)}`)
},
}

export default {
LocalCacheKey,
addresses,
Expand All @@ -130,4 +143,5 @@ export default {
currentWallet,
currentNetworkID,
systemScript,
guideBubbleTimes,
}

0 comments on commit 9b85589

Please sign in to comment.