-
Notifications
You must be signed in to change notification settings - Fork 116
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(controls): Add Quality support to Dash controls (#1395)
- Loading branch information
Conrad Chan
authored
Jun 3, 2021
1 parent
110525a
commit 7392977
Showing
18 changed files
with
528 additions
and
89 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
@import '../styles'; | ||
|
||
.bp-HDBadge { | ||
padding: 2px 2px 2px 3px; | ||
color: $white; | ||
font-weight: bold; | ||
font-size: 8px; | ||
letter-spacing: .1em; | ||
background-color: $bdl-box-blue; | ||
border-radius: 3px; | ||
} |
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,6 @@ | ||
import React from 'react'; | ||
import './HDBadge.scss'; | ||
|
||
export default function HDBadge(): JSX.Element { | ||
return <div className="bp-HDBadge">HD</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
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
55 changes: 55 additions & 0 deletions
55
src/lib/viewers/controls/media/MediaSettingsMenuQuality.tsx
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,55 @@ | ||
import React from 'react'; | ||
import noop from 'lodash/noop'; | ||
import Settings, { Menu } from '../settings'; | ||
|
||
export type Props = { | ||
onQualityChange: (quality: Quality) => void; | ||
quality: Quality; | ||
}; | ||
|
||
export enum Quality { | ||
AUTO = 'auto', | ||
HD = 'hd', | ||
SD = 'sd', | ||
} | ||
|
||
const QUALITY_LABEL_MAP: Record<Quality, string> = { | ||
[Quality.AUTO]: __('media_quality_auto') as string, | ||
[Quality.HD]: '1080p', | ||
[Quality.SD]: '480p', | ||
}; | ||
|
||
export const getLabel = (quality: Quality): string => QUALITY_LABEL_MAP[quality]; | ||
|
||
export default function MediaSettingsMenuQuality({ onQualityChange = noop, quality }: Props): JSX.Element { | ||
const { setActiveMenu } = React.useContext(Settings.Context); | ||
|
||
const handleChange = (value: Quality): void => { | ||
setActiveMenu(Menu.MAIN); | ||
onQualityChange(value); | ||
}; | ||
|
||
return ( | ||
<Settings.Menu name={Menu.QUALITY}> | ||
<Settings.MenuBack label={__('media_quality')} /> | ||
<Settings.RadioItem<Quality> | ||
isSelected={quality === Quality.SD} | ||
label="480p" | ||
onChange={handleChange} | ||
value={Quality.SD} | ||
/> | ||
<Settings.RadioItem<Quality> | ||
isSelected={quality === Quality.HD} | ||
label="1080p" | ||
onChange={handleChange} | ||
value={Quality.HD} | ||
/> | ||
<Settings.RadioItem<Quality> | ||
isSelected={quality === Quality.AUTO} | ||
label={__('media_quality_auto')} | ||
onChange={handleChange} | ||
value={Quality.AUTO} | ||
/> | ||
</Settings.Menu> | ||
); | ||
} |
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
44 changes: 44 additions & 0 deletions
44
src/lib/viewers/controls/media/__tests__/MediaSettingsMenuQuality-test.tsx
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,44 @@ | ||
import React from 'react'; | ||
import { mount, ReactWrapper } from 'enzyme'; | ||
import MediaSettingsMenuQuality, { Quality } from '../MediaSettingsMenuQuality'; | ||
import Settings, { Context, Menu } from '../../settings'; | ||
|
||
describe('MediaSettingsMenuQuality', () => { | ||
const getContext = (): Partial<Context> => ({ setActiveMenu: jest.fn() }); | ||
const getWrapper = (props = {}, context = getContext()): ReactWrapper => | ||
mount(<MediaSettingsMenuQuality onQualityChange={jest.fn()} quality={Quality.AUTO} {...props} />, { | ||
wrappingComponent: Settings.Context.Provider, | ||
wrappingComponentProps: { value: context }, | ||
}); | ||
|
||
describe('event handlers', () => { | ||
test('should surface the selected item on change', () => { | ||
const onQualityChange = jest.fn(); | ||
const wrapper = getWrapper({ onQualityChange }); | ||
|
||
wrapper.find({ value: 'sd' }).simulate('click'); | ||
|
||
expect(onQualityChange).toBeCalledWith('sd'); | ||
}); | ||
|
||
test('should reset the active menu on change', () => { | ||
const context = getContext(); | ||
const wrapper = getWrapper({}, context); | ||
|
||
wrapper.find({ value: 'sd' }).simulate('click'); | ||
|
||
expect(context.setActiveMenu).toBeCalledWith(Menu.MAIN); | ||
}); | ||
}); | ||
|
||
describe('render', () => { | ||
test('should return a valid wrapper', () => { | ||
const wrapper = getWrapper(); | ||
const radioItems = wrapper.find(Settings.RadioItem); | ||
|
||
expect(wrapper.exists(Settings.MenuBack)).toBe(true); | ||
expect(radioItems.length).toBe(3); | ||
expect(radioItems.at(2).prop('isSelected')).toBe(true); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.