Update config editor (#37)
* Update config-editor.tsx * Fix minor grammar error * Fix minor grammar error --------- Co-authored-by: Kas-tle <26531652+Kas-tle@users.noreply.github.com>
This commit is contained in:
1 parent
6926df9337
commit
97dd0dab0a
1 file changed
+52
-13
@@ -53,7 +53,9 @@ const ConfigEditorPage: React.FC = () => {
|
||||
let currentSection = '';
|
||||
let currentComment = '';
|
||||
|
||||
const newConfig = {};
|
||||
const newConfig = {"": {}};
|
||||
|
||||
let ignore = false;
|
||||
|
||||
// Parse each line of the config
|
||||
for (let i = 0; i < lines.length; i++) {
|
||||
@@ -72,7 +74,7 @@ const ConfigEditorPage: React.FC = () => {
|
||||
|
||||
const commented = line.startsWith('#');
|
||||
|
||||
const match = line.match(keyReg)
|
||||
const match = line.match(keyReg);
|
||||
if (match === null) {
|
||||
// Check if we are in a comment
|
||||
if (commented) {
|
||||
@@ -84,12 +86,26 @@ const ConfigEditorPage: React.FC = () => {
|
||||
// Check if we are in a new section
|
||||
if (line.endsWith(':')) {
|
||||
currentSection = line.replace(':', '');
|
||||
|
||||
// Ignore user auths section
|
||||
if (currentSection === 'saved-user-logins') {
|
||||
ignore = true;
|
||||
continue;
|
||||
}
|
||||
ignore = false;
|
||||
if (commented) {
|
||||
currentComment += '<strong>Note: This option is commented out by default. It will be automatically uncommented if modified.</strong>' + '<br>';
|
||||
}
|
||||
|
||||
currentComment = currentComment.replace(URL_REGEX, function ($0) {
|
||||
return '<a href="' + $0 + '">' + $0 + '</a>';
|
||||
})
|
||||
newConfig[currentSection] = {sectionDesc0: currentComment};
|
||||
currentComment = '';
|
||||
continue;
|
||||
}
|
||||
|
||||
// Ignore user auths section
|
||||
if (currentSection === 'saved-user-logins') {
|
||||
if (ignore) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -108,11 +124,14 @@ const ConfigEditorPage: React.FC = () => {
|
||||
}
|
||||
|
||||
if (commented) {
|
||||
currentComment += '<strong>Note: This option is commented on, and if you change it, it will be automatically uncommented.</strong>' + '<br>';
|
||||
currentComment += '<strong>Note: This option is commented out by default. It will be automatically uncommented if modified.</strong>' + '<br>';
|
||||
}
|
||||
|
||||
currentComment = currentComment.replace(URL_REGEX, function ($0) {
|
||||
return '<a href="' + $0 + '">' + $0 + '</a>';
|
||||
})
|
||||
|
||||
// Add the config option to the config object
|
||||
newConfig[currentSection] = newConfig[currentSection] || {};
|
||||
newConfig[currentSection][splitLine[0]] = {
|
||||
desc: currentComment,
|
||||
value: val,
|
||||
@@ -132,6 +151,16 @@ const ConfigEditorPage: React.FC = () => {
|
||||
<div className={styles.cardBody}>
|
||||
{Object.keys(config[configKey]).map(configOption => {
|
||||
const configOptionInfo = config[configKey][configOption];
|
||||
if (configOption == "sectionDesc0") {
|
||||
if (configOptionInfo === "") {
|
||||
return;
|
||||
}
|
||||
return (
|
||||
<div className={styles.configOption}>
|
||||
<p dangerouslySetInnerHTML={{__html: configOptionInfo}}/>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
const configOptionKey = configKey === '' ? configOption : `${configKey}.${configOption}`;
|
||||
const showOptionName = configOption.replace('#', '').trim()
|
||||
return (
|
||||
@@ -147,6 +176,8 @@ const ConfigEditorPage: React.FC = () => {
|
||||
))
|
||||
}
|
||||
|
||||
const URL_REGEX = /https?:\/\/(([0-9a-z.]+\.[a-z]+)|(([0-9]{1,3}\.){3}[0-9]{1,3}))(:[0-9]+)?(\/[0-9a-z%\/.\-_]*)?(\?[0-9a-z=&%_\-]*)?(#[0-9a-z=&%_\-]*)?/ig;
|
||||
|
||||
const handleExport = () => {
|
||||
let newConfig = config;
|
||||
const lines = newConfig.split('\n');
|
||||
@@ -188,7 +219,8 @@ const ConfigEditorPage: React.FC = () => {
|
||||
// Handle all the dropdowns
|
||||
case 'remote.auth-type':
|
||||
return (
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||
onChange={handleChange}>
|
||||
<option value='offline'>offline</option>
|
||||
<option value='online'>online</option>
|
||||
<option value='floodgate'>floodgate</option>
|
||||
@@ -196,7 +228,8 @@ const ConfigEditorPage: React.FC = () => {
|
||||
);
|
||||
case 'show-cooldown':
|
||||
return (
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||
onChange={handleChange}>
|
||||
<option value='title'>title</option>
|
||||
<option value='actionbar'>actionbar</option>
|
||||
<option value='false'>false</option>
|
||||
@@ -204,16 +237,19 @@ const ConfigEditorPage: React.FC = () => {
|
||||
);
|
||||
case 'emote-offhand-workaround':
|
||||
return (
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value} onChange={handleChange}>
|
||||
<select key={name} className={styles.formInput} id={name} defaultValue={value}
|
||||
onChange={handleChange}>
|
||||
<option value='disabled'>disabled</option>
|
||||
<option value='no-emotes'>no-emotes</option>
|
||||
<option value='emotes-and-offhand'>emotes-and-offhand</option>
|
||||
</select>
|
||||
);
|
||||
case 'config-version':
|
||||
return <input key={name} className={styles.formInput} type='text' disabled defaultValue={value.replace(/"/g, '')} />;
|
||||
return <input key={name} className={styles.formInput} type='text' disabled
|
||||
defaultValue={value.replace(/"/g, '')}/>;
|
||||
case 'metrics.uuid':
|
||||
return <input key={name} className={styles.formInput} id={name} type='text' disabled defaultValue={value === 'generateduuid' ? crypto.randomUUID() : value} />;
|
||||
return <input key={name} className={styles.formInput} id={name} type='text' disabled
|
||||
defaultValue={value === 'generateduuid' ? crypto.randomUUID() : value}/>;
|
||||
|
||||
default:
|
||||
// Handle all the other inputs
|
||||
@@ -251,13 +287,16 @@ const ConfigEditorPage: React.FC = () => {
|
||||
a.click()
|
||||
document.body.removeChild(a)
|
||||
|
||||
setTimeout(() => { URL.revokeObjectURL(a.href) }, 1500)
|
||||
setTimeout(() => {
|
||||
URL.revokeObjectURL(a.href)
|
||||
}, 1500)
|
||||
}
|
||||
|
||||
const NoConfigSection = () => (
|
||||
<>
|
||||
<h1><Translate id='pages.configeditor.noconfigselected.heading'>No config selected.</Translate></h1>
|
||||
<h3 className={styles.fontNormal}><Translate id='pages.configeditor.noconfigselected.subheading'>Upload a file or get started with the default config!</Translate></h3>
|
||||
<h3 className={styles.fontNormal}><Translate id='pages.configeditor.noconfigselected.subheading'>Upload a
|
||||
file or get started with the default config!</Translate></h3>
|
||||
|
||||
<div className={styles.buttonsContainer}>
|
||||
<button className={styles.button} onClick={loadDefault}>
|
||||
|
||||
Reference in new issue
Block a user