Skip to content

Commit 4793dbd

Browse files
committed
Add media browser hint for first time usage
1 parent ae63af6 commit 4793dbd

File tree

7 files changed

+87
-10
lines changed

7 files changed

+87
-10
lines changed

packages/metastream-app/src/components/browser/Controls.css

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,10 @@
5353
.requestButtonContainer button {
5454
height: 100%;
5555
}
56+
57+
.addHintTooltip {
58+
background-color: white !important;
59+
color: #222 !important;
60+
max-width: 360px !important;
61+
padding: 1rem 2rem !important;
62+
}

packages/metastream-app/src/components/browser/Controls.tsx

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import React, { Component } from 'react'
22
import cx from 'classnames'
33

4+
import { t } from 'locale'
5+
import { StorageKey } from 'constants/storage'
6+
import { Webview } from 'components/Webview'
47
import { IconButton, HighlightButton } from 'components/common/button'
8+
import { HighlightText, MediumText } from '../common/typography'
59

610
import styles from './Controls.css'
7-
import { t } from 'locale'
8-
import { Webview } from 'components/Webview'
911

1012
interface IProps {
1113
initialUrl: string
@@ -18,18 +20,28 @@ interface IState {
1820
url?: string
1921
loading?: boolean
2022
canRequest?: boolean
23+
showAddHint?: boolean
2124
}
2225

2326
export class WebControls extends Component<IProps, IState> {
2427
private webview: Webview | null = null
2528
private addressInput: HTMLInputElement | null = null
29+
private mounted: boolean = false
2630

2731
state: IState = {}
2832

2933
private get addressUrl() {
3034
return (this.addressInput && this.addressInput.value) || ''
3135
}
3236

37+
componentDidMount() {
38+
this.mounted = true
39+
}
40+
41+
componentWillUnmount() {
42+
this.mounted = false
43+
}
44+
3345
render(): JSX.Element {
3446
// back, forward, location bar, play button, exit
3547
const addressUrl = this.addressUrl
@@ -57,7 +69,6 @@ export class WebControls extends Component<IProps, IState> {
5769
this.webview.goForward()
5870
}
5971
}}
60-
// disabled={this.webview ? !this.webContents.canGoForward() : true}
6172
/>
6273
)
6374

@@ -98,6 +109,19 @@ export class WebControls extends Component<IProps, IState> {
98109
onClick={this.onPlayClicked.bind(this)}
99110
disabled={!this.state.canRequest}
100111
highlight={this.state.canRequest}
112+
title={
113+
<MediumText>
114+
When you&rsquo;re ready to share, press the{' '}
115+
<HighlightText>Add To Session</HighlightText> button.
116+
</MediumText>
117+
}
118+
tooltipProps={
119+
{
120+
classes: { tooltip: styles.addHintTooltip },
121+
placement: 'bottom-end',
122+
open: !!this.state.showAddHint
123+
} as any
124+
}
101125
>
102126
{t('requestUrl')}
103127
</HighlightButton>
@@ -217,7 +241,6 @@ export class WebControls extends Component<IProps, IState> {
217241
this.requestUrl(url)
218242
} else if (url) {
219243
this.loadURL(url)
220-
// this.webview!.focus()
221244
}
222245
}
223246
}
@@ -227,6 +250,22 @@ export class WebControls extends Component<IProps, IState> {
227250
const canRequest = !!(url && url.length >= 1)
228251
if (canRequest !== this.state.canRequest) {
229252
this.setState({ canRequest })
253+
254+
if (canRequest) {
255+
this.checkShowAddHint()
256+
}
257+
}
258+
}
259+
260+
private checkShowAddHint() {
261+
const hasRequestedMediaBefore = Boolean(localStorage.getItem(StorageKey.RequestCount))
262+
263+
if (!hasRequestedMediaBefore) {
264+
setTimeout(() => {
265+
if (this.mounted) {
266+
this.setState({ showAddHint: true })
267+
}
268+
}, 5e3)
230269
}
231270
}
232271

packages/metastream-app/src/components/common/button.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@ import React from 'react'
22
import * as cx from 'classnames'
33
import styles from './button.css'
44
import { Icon } from 'components/Icon'
5-
import Tooltip from '@material-ui/core/Tooltip'
5+
import Tooltip, { TooltipProps } from '@material-ui/core/Tooltip'
66

77
export interface IIconButtonProps {
88
icon: string
99
iconSize?: 'small'
10-
title?: string
10+
11+
title?: React.ReactNode
12+
tooltipProps?: TooltipProps
1113

1214
/** Disable button interaction */
1315
disabled?: boolean
@@ -21,9 +23,10 @@ export interface IIconButtonProps {
2123
const nbsp = '\u00A0'
2224

2325
export const IconButton: React.SFC<IIconButtonProps> = ({
24-
title,
2526
icon,
2627
iconSize,
28+
title,
29+
tooltipProps,
2730
children,
2831
...props
2932
}) => {
@@ -40,7 +43,7 @@ export const IconButton: React.SFC<IIconButtonProps> = ({
4043
{...props}
4144
>
4245
{title ? (
43-
<Tooltip title={title}>
46+
<Tooltip {...tooltipProps} title={title}>
4447
<div className={styles.tooltip} />
4548
</Tooltip>
4649
) : null}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.highlightText {
2+
color: var(--color-highlight);
3+
font-weight: bold;
4+
}
5+
6+
.mediumText {
7+
font-size: 1.2rem;
8+
line-height: 1.8rem;
9+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import React from 'react'
2+
import cx from 'classnames'
3+
import styles from './typography.css'
4+
5+
export const HighlightText = (props: React.HTMLAttributes<HTMLSpanElement>) => (
6+
<span {...props} className={cx(props.className, styles.highlightText)}>
7+
{props.children}
8+
</span>
9+
)
10+
11+
export const MediumText = (props: React.HTMLAttributes<HTMLSpanElement>) => (
12+
<span {...props} className={cx(props.className, styles.mediumText)}>
13+
{props.children}
14+
</span>
15+
)
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export const enum StorageKey {
2+
RequestCount = 'requestCount'
3+
}

packages/metastream-app/src/lobby/actions/mediaPlayer.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import { addChat } from './chat'
1717
import { AppThunkAction } from 'types/redux-thunk'
1818
import { translateEscaped, t } from 'locale'
1919
import { isIP } from 'utils/network'
20+
import { StorageKey } from '../../constants/storage'
2021

2122
/** Code-split media parsing due to large dependencies and it's only used by the host. */
2223
const getMediaParser = () => import(/* webpackChunkName: "media-parser" */ 'media')
@@ -170,8 +171,8 @@ export const sendMediaRequest = (url: string, source: string): AppThunkAction =>
170171

171172
const requestPromise = dispatch(server_requestMedia(url))
172173

173-
const requestCount = parseInt(localStorage.getItem('requestCount') || '0', 10) || 0
174-
localStorage.setItem('requestCount', `${requestCount + 1}`)
174+
const requestCount = parseInt(localStorage.getItem(StorageKey.RequestCount) || '0', 10) || 0
175+
localStorage.setItem(StorageKey.RequestCount, `${requestCount + 1}`)
175176

176177
{
177178
ga('event', { ec: 'session', ea: 'request_media', el: source })

0 commit comments

Comments
 (0)