Skip to content

Commit c0b2781

Browse files
committed
Fix review
1 parent f027a40 commit c0b2781

File tree

15 files changed

+87
-173
lines changed

15 files changed

+87
-173
lines changed

app/custom-sounds/assets/stylesheets/customSoundsAdmin.css

Lines changed: 0 additions & 111 deletions
This file was deleted.

app/custom-sounds/client/admin/route.js

Lines changed: 0 additions & 6 deletions
This file was deleted.

app/custom-sounds/client/admin/startup.js

Lines changed: 0 additions & 11 deletions
This file was deleted.

app/custom-sounds/client/index.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import './notifications/deleteCustomSound';
22
import './notifications/updateCustomSound';
3-
import './admin/route';
4-
import './admin/startup';
5-
import '../assets/stylesheets/customSoundsAdmin.css';
63

74
export { CustomSounds } from './lib/CustomSounds';

app/custom-sounds/client/lib/CustomSounds.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import _ from 'underscore';
44

55
import { CachedCollectionManager } from '../../../ui-cached-collection';
66

7+
const getCustomSoundId = (sound) => `custom-sound-${ sound }`;
8+
79
class CustomSoundsClass {
810
constructor() {
911
this.list = new ReactiveVar({});
@@ -19,7 +21,7 @@ class CustomSoundsClass {
1921
if (!sound.src) {
2022
sound.src = this.getURL(sound);
2123
}
22-
const audio = $('<audio />', { id: sound._id, preload: true }).append(
24+
const audio = $('<audio />', { id: getCustomSoundId(sound._id), preload: true }).append(
2325
$('<source />', { src: sound.src }),
2426
);
2527
const list = this.list.get();
@@ -59,7 +61,7 @@ class CustomSoundsClass {
5961
}
6062

6163
play = (sound, { volume = 1, loop = false } = {}) => {
62-
const audio = document.querySelector(`audio#${ sound }`);
64+
const audio = document.querySelector(`#${ getCustomSoundId(sound) }`);
6365
if (!audio || !audio.play) {
6466
return;
6567
}

app/custom-sounds/client/admin/AdminSounds.js renamed to client/admin/customSounds/AdminSounds.js

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import React, { useMemo, useCallback, useState, useEffect } from 'react';
2-
import { Box, Table, TextInput, Icon } from '@rocket.chat/fuselage';
2+
import { Box, Table, TextInput, Icon, Button } from '@rocket.chat/fuselage';
33

4-
import { GenericTable, Th } from '../../../ui/client/components/GenericTable';
5-
import { useTranslation } from '../../../../client/contexts/TranslationContext';
6-
7-
const style = { whiteSpace: 'nowrap', textOverflow: 'ellipsis', overflow: 'hidden' };
4+
import { useTranslation } from '../../contexts/TranslationContext';
5+
import { CustomSounds } from '../../../app/custom-sounds/client/lib/CustomSounds';
6+
import { GenericTable, Th } from '../../../app/ui/client/components/GenericTable';
7+
import { useCustomSound } from '../../contexts/CustomSoundContext';
88

99
const FilterByText = ({ setFilter, ...props }) => {
1010
const t = useTranslation();
@@ -30,13 +30,26 @@ export function AdminSounds({
3030
const t = useTranslation();
3131

3232
const header = useMemo(() => [
33-
<Th key={'name'} direction={sort[1]} active={sort[0] === 'name'} onClick={onHeaderClick} sort='name' w='x200'>{t('Name')}</Th>,
34-
].filter(Boolean), [sort]);
33+
<Th key={'name'} direction={sort[1]} active={sort[0] === 'name'} onClick={onHeaderClick} sort='name'>{t('Name')}</Th>,
34+
<Th w='x40' key='action'></Th>,
35+
], [sort]);
36+
37+
const customSound = useCustomSound();
38+
39+
const handlePlay = useCallback((sound) => {
40+
customSound.play(sound);
41+
}, []);
3542

3643
const renderRow = (sound) => {
3744
const { _id, name } = sound;
45+
3846
return <Table.Row key={_id} onKeyDown={onClick(_id, sound)} onClick={onClick(_id, sound)} tabIndex={0} role='link' action qa-user-id={_id}>
39-
<Table.Cell fontScale='p1' color='default' style={style}>{name}</Table.Cell>
47+
<Table.Cell fontScale='p1' color='default'><Box withTruncatedText>{name}</Box></Table.Cell>
48+
<Table.Cell alignItems={'end'}>
49+
<Button ghost small square aria-label={t('Play')} onClick={(e) => e.preventDefault() & e.stopPropagation() & handlePlay(_id)}>
50+
<Icon name='play' size='x20' />
51+
</Button>
52+
</Table.Cell>
4053
</Table.Row>;
4154
};
4255

app/custom-sounds/client/admin/AdminSoundsRoute.js renamed to client/admin/customSounds/AdminSoundsRoute.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,16 @@ import React, { useMemo, useState, useCallback } from 'react';
44
import { Button, Icon } from '@rocket.chat/fuselage';
55
import { useDebouncedValue, useMediaQuery } from '@rocket.chat/fuselage-hooks';
66

7-
import { usePermission } from '../../../../client/contexts/AuthorizationContext';
8-
import { useTranslation } from '../../../../client/contexts/TranslationContext';
9-
import Page from '../../../../client/components/basic/Page';
7+
import { usePermission } from '../../contexts/AuthorizationContext';
8+
import { useTranslation } from '../../contexts/TranslationContext';
9+
import Page from '../../components/basic/Page';
1010
import { AdminSounds } from './AdminSounds';
1111
import { NewSound } from './NewSound';
1212
import { EditSound } from './EditSound';
13-
import { useRoute, useRouteParameter } from '../../../../client/contexts/RouterContext';
14-
import { useEndpointData } from '../../../../client/hooks/useEndpointData';
15-
import VerticalBar from '../../../../client/components/basic/VerticalBar';
16-
import { NotAuthorizedPage } from '../../../../client/admin/NotAuthorizedPage';
13+
import { useRoute, useRouteParameter } from '../../contexts/RouterContext';
14+
import { useEndpointData } from '../../hooks/useEndpointData';
15+
import VerticalBar from '../../components/basic/VerticalBar';
16+
import NotAuthorizedPage from '../NotAuthorizedPage';
1717

1818
const sortDir = (sortDir) => (sortDir === 'asc' ? 1 : -1);
1919

app/custom-sounds/client/admin/EditSound.js renamed to client/admin/customSounds/EditSound.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import React, { useCallback, useState, useMemo, useEffect } from 'react';
22
import { Box, Button, ButtonGroup, Margins, TextInput, Field, Icon, Skeleton, Throbber, InputBox } from '@rocket.chat/fuselage';
33

4-
import { useTranslation } from '../../../../client/contexts/TranslationContext';
5-
import { useMethod } from '../../../../client/contexts/ServerContext';
6-
import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext';
7-
import { Modal } from '../../../../client/components/basic/Modal';
8-
import { useFileInput } from '../../../../client/hooks/useFileInput';
9-
import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../../../client/hooks/useEndpointDataExperimental';
10-
import { validate, createSoundData } from './hooks';
4+
import { useTranslation } from '../../contexts/TranslationContext';
5+
import { useMethod } from '../../contexts/ServerContext';
6+
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
7+
import { Modal } from '../../components/basic/Modal';
8+
import { useFileInput } from '../../hooks/useFileInput';
9+
import { useEndpointDataExperimental, ENDPOINT_STATES } from '../../hooks/useEndpointDataExperimental';
10+
import { validate, createSoundData } from './lib';
1111

1212
const DeleteWarningModal = ({ onDelete, onCancel, ...props }) => {
1313
const t = useTranslation();

app/custom-sounds/client/admin/NewSound.js renamed to client/admin/customSounds/NewSound.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
import React, { useState, useCallback } from 'react';
22
import { Field, TextInput, Box, Icon, Margins, Button, ButtonGroup } from '@rocket.chat/fuselage';
33

4-
import { useToastMessageDispatch } from '../../../../client/contexts/ToastMessagesContext';
5-
import { useTranslation } from '../../../../client/contexts/TranslationContext';
6-
import { useMethod } from '../../../../client/contexts/ServerContext';
7-
import { useFileInput } from '../../../../client/hooks/useFileInput';
8-
import { validate, createSoundData } from './hooks';
4+
import { useToastMessageDispatch } from '../../contexts/ToastMessagesContext';
5+
import { useTranslation } from '../../contexts/TranslationContext';
6+
import { useMethod } from '../../contexts/ServerContext';
7+
import { useFileInput } from '../../hooks/useFileInput';
8+
import { validate, createSoundData } from './lib';
99

1010
export function NewSound({ goToNew, close, onChange, ...props }) {
1111
const t = useTranslation();
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import s from 'underscore.string';
2-
31
// Here previousData will define if it is an update or a new entry
42
export function validate(soundData, soundFile) {
53
const errors = [];
@@ -19,13 +17,11 @@ export function validate(soundData, soundFile) {
1917
}
2018
}
2119
}
22-
console.log(soundData, soundFile);
23-
2420

2521
return errors;
2622
}
2723

28-
export function createSoundData(soundFile, name, previousData) {
24+
export function createSoundData(soundFile, name = '', previousData) {
2925
const soundData = {};
3026

3127
if (previousData) {
@@ -37,7 +33,7 @@ export function createSoundData(soundFile, name, previousData) {
3733
soundData.name = name;
3834
soundData.newFile = false;
3935
} else {
40-
soundData.name = s.trim(name);
36+
soundData.name = name.trim();
4137
soundData.newFile = true;
4238
}
4339

0 commit comments

Comments
 (0)