mirror of https://github.com/vizality/vizality
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
63 lines
2.0 KiB
63 lines
2.0 KiB
import { TextInput, SwitchItem } from '@vizality/components/settings';
|
|
import React, { memo, useEffect } from 'react';
|
|
import { useFilter } from '@vizality/hooks';
|
|
import { Messages } from '@vizality/i18n';
|
|
|
|
/**
|
|
* Commands settings options.
|
|
* @component
|
|
* @returns {React.MemoExoticComponent<function(): React.ReactElement>}
|
|
*/
|
|
export default memo(({ builtin, search = '' }) => {
|
|
const [ commandPrefix, setCommandPrefix ] = vizality.api.settings.useSetting('commandPrefix', '.');
|
|
const [ replaceClyde, setReplaceClyde ] = vizality.api.settings.useSetting('replaceClyde', true);
|
|
|
|
const items = [
|
|
{
|
|
search: [
|
|
Messages.VIZALITY_COMMAND_PREFIX
|
|
],
|
|
render: query =>
|
|
<TextInput
|
|
defaultValue={commandPrefix}
|
|
onChange={p => setCommandPrefix(!p ? '.' : p.replace(/\s+(?=\S)|(?<=\s)\s+/g, '').toLowerCase())}
|
|
onBlur={({ target }) => target.value = commandPrefix}
|
|
error={commandPrefix === '/' ? 'Prefix should not be set to `/` as it is already in use by Discord and may disable Vizality autocompletions.' : ''}
|
|
>
|
|
{Messages.VIZALITY_COMMAND_PREFIX}
|
|
</TextInput>
|
|
},
|
|
{
|
|
search: [
|
|
Messages.VIZALITY_SETTINGS_NO_CLYDE,
|
|
Messages.VIZALITY_SETTINGS_NO_CLYDE_DESC.format({
|
|
discordiaUrl: 'https://discordia.me/clyde',
|
|
apiUrl: `${window.location.origin}/vizality/docs`
|
|
})
|
|
],
|
|
render: query =>
|
|
<SwitchItem
|
|
description={Messages.VIZALITY_SETTINGS_NO_CLYDE_DESC.format({
|
|
discordiaUrl: 'https://discordia.me/clyde',
|
|
apiUrl: `${window.location.origin}/vizality/docs`
|
|
})}
|
|
value={replaceClyde}
|
|
onChange={() => setReplaceClyde(!replaceClyde)}
|
|
>
|
|
{Messages.VIZALITY_SETTINGS_NO_CLYDE}
|
|
</SwitchItem>
|
|
}
|
|
];
|
|
|
|
const [ query, setQuery, filteredResults ] = useFilter({
|
|
keys: [ 'search' ],
|
|
data: items
|
|
});
|
|
|
|
useEffect(() => {
|
|
setQuery(search);
|
|
}, [ search ]);
|
|
|
|
return filteredResults.map(result => result.render(query));
|
|
});
|