Skip to content

Commit ecba9f3

Browse files
committed
add volume control to Audio detail view
1 parent 526f61d commit ecba9f3

File tree

5 files changed

+54
-16
lines changed

5 files changed

+54
-16
lines changed

client/common/DropDownMenu.tsx

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import React, {useEffect, useRef} from 'react';
22
import {Tooltip, TooltipTrigger, TooltipContent} from '../common/Tooltip';
33

44

5-
export default function DropDownMenu(props){
5+
export default function DropDownMenu(props) {
66
const ref = useRef(null);
77
const WrapperElement = props.wrapperElement ?? 'li';
88

@@ -45,14 +45,23 @@ export default function DropDownMenu(props){
4545
aria-haspopup="listbox"
4646
aria-expanded="false"
4747
className={props.className}
48-
>
48+
>{
49+
props.tooltip ? (
4950
<Tooltip>
5051
<TooltipTrigger>{props.label ? props.label : ''}{props.icon && <i>{props.icon}</i>}</TooltipTrigger>
5152
<TooltipContent root={props.root}>{props.tooltip}</TooltipContent>
5253
<ul role="listbox">
5354
{props.children}
5455
</ul>
5556
</Tooltip>
56-
</WrapperElement>
57+
) : (
58+
<>
59+
<div>{props.label ? props.label : ''}{props.icon && <i>{props.icon}</i>}</div>
60+
<ul role="listbox">
61+
{props.children}
62+
</ul>
63+
</>
64+
)
65+
}</WrapperElement>
5766
)
5867
}

client/components/editor/Audio.tsx

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ import React, {Fragment, useState} from 'react';
22
import WavesurferPlayer from '@wavesurfer/react';
33
import RegionsPlugin from 'wavesurfer.js/dist/plugins/regions.js';
44
import FileDetails from '../../admin/FileDetails';
5+
import {useAudioSettings} from '../../common/Storage';
6+
import DropDownMenu from '../../common/DropDownMenu';
57
import PauseIcon from '../../icons/pause.svg';
68
import PlayIcon from '../../icons/play.svg';
79

@@ -14,6 +16,7 @@ export default function Audio(props) {
1416
};
1517
const [wavesurfer, setWavesurfer] = useState(null);
1618
const [isPlaying, setIsPlaying] = useState(false);
19+
const [audioSettings, setAudioSettings] = useAudioSettings();
1720

1821
const onReady = (ws) => {
1922
document.getElementById('wavesurfer-initializing')?.remove();
@@ -42,11 +45,23 @@ export default function Audio(props) {
4245
wavesurfer && wavesurfer.playPause();
4346
};
4447

48+
function setVolume(event) {
49+
const volume = parseFloat(event.target.value);
50+
setAudioSettings({volume: volume});
51+
wavesurfer && wavesurfer.setVolume(volume);
52+
}
53+
4554
const controlButtons = [
4655
<Fragment key="play-pause">{isPlaying ?
4756
<button type="button" onClick={onPlayPause}><PauseIcon/>{gettext("Pause")}</button> :
4857
<button type="button" onClick={onPlayPause}><PlayIcon/>{gettext("Play")}</button>
49-
}</Fragment>
58+
}</Fragment>,
59+
<DropDownMenu key="volume-control" className="volume-control with-caret" label={gettext("Set Volume")}>
60+
<li>
61+
<label htmlFor="volume_level">{gettext("Volume level")}:</label>
62+
<input name="volume_level" type="range" min="0.0" max="1.0" step="0.001" value={audioSettings.volume} onChange={setVolume}/>
63+
</li>
64+
</DropDownMenu>,
5065
];
5166

5267
const placeholderStyle: React.CSSProperties = {

client/scss/_menubar.scss

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@use "colors";
2+
@use "volume-control";
23

34
@mixin menubar {
45
[role="menubar"] {
@@ -106,25 +107,15 @@
106107
margin-left: 1rem;
107108
margin-right: auto;
108109

109-
ul > li {
110-
padding: 0.5rem 0.75rem;
111-
112-
label {
113-
display: block;
114-
}
115-
116-
input[type="range"] {
117-
vertical-align: initial;
118-
padding: 0;
119-
}
120-
}
110+
@include volume-control.volume-control;
121111
}
122112

123113
&[aria-haspopup="listbox"]:has(>[role~="listbox"]) {
124114
width: auto;
125115
}
126116

127117
&.sorting-options {
118+
margin-left: auto;
128119
&:not(:has(+.filter-by-label)) {
129120
margin-right: auto;
130121
}

client/scss/_volume-control.scss

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@mixin volume-control {
2+
ul > li {
3+
padding: 0.5rem 0.75rem;
4+
5+
label {
6+
display: block;
7+
color: inherit;
8+
}
9+
10+
input[type="range"] {
11+
vertical-align: initial;
12+
padding: 0;
13+
}
14+
}
15+
}

client/scss/finder-admin.scss

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
@use "progress";
66
@use "labels";
77
@use "tooltip";
8+
@use "volume-control";
89

910
// messagelist appears after saving a file
1011
ul.messagelist {
@@ -759,20 +760,27 @@ ul.messagelist {
759760
background: var(--default-button-bg);
760761
margin-right: 10px;
761762
margin-bottom: 10px;
763+
762764
&[aria-expanded="false"] {
763765
cursor: pointer;
764766
&:hover {
765767
background: var(--default-button-hover-bg);
766768
}
767769
}
770+
768771
&::after {
769772
margin-left: 10px;
770773
border-top-color: var(--button-fg);
771774
}
775+
&.volume-control {
776+
@include volume-control.volume-control;
777+
}
778+
772779
[role="listbox"] {
773780
color: inherit;
774781
background-color: inherit;
775782
padding: 5px;
783+
776784
> li {
777785
padding: 0 30px 0 10px;
778786
cursor: pointer;

0 commit comments

Comments
 (0)