Skip to content
This repository was archived by the owner on Nov 22, 2022. It is now read-only.

Commit 3768e45

Browse files
Replace sound selector with FileSelectorField
1 parent 2213203 commit 3768e45

File tree

1 file changed

+43
-79
lines changed
  • packages/builder/src/components/ComponentOptions/components/Behavior/components/Timeline

1 file changed

+43
-79
lines changed

packages/builder/src/components/ComponentOptions/components/Behavior/components/Timeline/itemForm.js

Lines changed: 43 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ import { CardBody } from 'reactstrap'
66
import { Field } from 'formik'
77
import { Button, ButtonGroup,
88
UncontrolledButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem,
9-
InputGroup, InputGroupAddon, InputGroupText, FormGroup,
9+
InputGroup, InputGroupText, FormGroup,
1010
UncontrolledTooltip, Row, Col, Alert } from 'reactstrap'
1111
import { capitalize } from 'lodash'
1212

1313
import Icon from '../../../../../Icon'
14-
import FileSelector from '../../../../../FileSelector'
14+
import FileSelectorField from '../../../../../FileSelector/field'
1515
import { Input } from '../../../../../Form'
1616

1717
import { numberOrPlaceholder } from './util'
@@ -290,83 +290,47 @@ const GlobalSettings = ({ activeItem }) =>
290290
</Row>
291291
</>
292292

293-
const SoundForm = ({ activeItem, handleChange }, { id }) => {
294-
const fileSelector = createRef()
295-
296-
return (
297-
<>
298-
<FileSelector
299-
accept="audio/*,video/ogg"
300-
component={ id }
301-
ref={ fileSelector }
302-
/>
303-
<GlobalSettings activeItem={ activeItem } />
304-
<Row form>
305-
<Col>
306-
<FormGroup>
307-
<InputGroup>
308-
<InputGroupAddon addonType="prepend">
309-
<InputGroupText>
310-
<Icon fixedWidth icon="file-audio" />
311-
</InputGroupText>
312-
</InputGroupAddon>
313-
<Field
314-
name={ `timeline[${ activeItem }].payload.src` }
315-
component={ Input }
316-
placeholder="source"
317-
className="text-monospace"
318-
/>
319-
<InputGroupAddon addonType="append">
320-
<Button
321-
outline color="secondary"
322-
style={{ minWidth: '3rem' }}
323-
onClick={ async () => {
324-
try {
325-
const files = await fileSelector.current.select()
326-
handleChange(
327-
'payload.src',
328-
`\${ this.files["${ files[0].localPath }"] }`
329-
)
330-
} catch (error) {
331-
console.log('Error while inserting audio', error)
332-
}
333-
} }
334-
>
335-
<Icon fixedWidth icon="folder" />
336-
</Button>
337-
</InputGroupAddon>
338-
</InputGroup>
339-
</FormGroup>
340-
</Col>
341-
<Col>
342-
<FormGroup>
343-
<InputGroup>
344-
<SettingGroupIcon
345-
icon="repeat"
346-
fallbackIcon="redo"
347-
tooltip="Loop audio"
348-
unit="boolean"
349-
/>
350-
<Field
351-
name={ `timeline[${ activeItem }].payload.loop` }
352-
as="select"
353-
className="form-control custom-select text-monospace"
354-
>
355-
<option value="false">Play sound once</option>
356-
<option value="true">Repeat continuously</option>
357-
</Field>
358-
</InputGroup>
359-
</FormGroup>
360-
</Col>
361-
</Row>
362-
<Row>
363-
<Col>
364-
<small className="text-muted">Please note that, for security reasons, audio files must be either embedded in the study, hosted on the same server on which the study is running, or on a server with <a href="https://enable-cors.org/server.html" target="_blank" rel="noopener noreferrer">cross-origin resource sharing</a> enabled. Please also note that Chrome and Safari do not support loading sounds offline; please consider hosting the study on a server instead.</small>
365-
</Col>
366-
</Row>
367-
</>
368-
)
369-
}
293+
const SoundForm = ({ activeItem }, { id }) =>
294+
<>
295+
<GlobalSettings activeItem={ activeItem } />
296+
<Row form>
297+
<Col>
298+
<FormGroup>
299+
<FileSelectorField
300+
name={ `timeline[${ activeItem }].payload.src` }
301+
accept="audio/*,video/ogg"
302+
icon="file-audio"
303+
component={ id }
304+
/>
305+
</FormGroup>
306+
</Col>
307+
<Col>
308+
<FormGroup>
309+
<InputGroup>
310+
<SettingGroupIcon
311+
icon="repeat"
312+
fallbackIcon="redo"
313+
tooltip="Loop audio"
314+
unit="boolean"
315+
/>
316+
<Field
317+
name={ `timeline[${ activeItem }].payload.loop` }
318+
as="select"
319+
className="form-control custom-select text-monospace"
320+
>
321+
<option value="false">Play sound once</option>
322+
<option value="true">Repeat continuously</option>
323+
</Field>
324+
</InputGroup>
325+
</FormGroup>
326+
</Col>
327+
</Row>
328+
<Row>
329+
<Col>
330+
<small className="text-muted">Please note that, for security reasons, audio files must be either embedded in the study, hosted on the same server on which the study is running, or on a server with <a href="https://enable-cors.org/server.html" target="_blank" rel="noopener noreferrer">cross-origin resource sharing</a> enabled. Please also note that Chrome and Safari do not support loading sounds offline; please consider hosting the study on a server instead.</small>
331+
</Col>
332+
</Row>
333+
</>
370334

371335
SoundForm.contextTypes = {
372336
id: PropTypes.oneOfType([

0 commit comments

Comments
 (0)