1
Fork 0

Generate the replacement type options from the enum.

This commit is contained in:
Bauke 2023-08-11 11:23:46 +02:00
parent b908749d7c
commit 36bf5ece75
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 9 additions and 10 deletions

View File

@ -1,5 +1,5 @@
import {Component} from "preact"; import {Component} from "preact";
import {fromStorage, Feature} from "../../storage/exports.js"; import {fromStorage, Feature, ReplacementType} from "../../storage/exports.js";
import {Setting, type SettingProps} from "./index.js"; import {Setting, type SettingProps} from "./index.js";
type State = { type State = {
@ -39,6 +39,13 @@ export class AnonymizeUsernamesSetting extends Component<SettingProps, State> {
} }
const replacementType = data.value.replacementType; const replacementType = data.value.replacementType;
const replacementTypeOptions = Object.values(ReplacementType).map((key) => (
<option selected={key === replacementType} value={key}>
{key
.replace(/-/g, " ")
.replace(/(\b[a-z])/gi, (character) => character.toUpperCase())}
</option>
));
return ( return (
<Setting {...this.props}> <Setting {...this.props}>
@ -52,15 +59,7 @@ export class AnonymizeUsernamesSetting extends Component<SettingProps, State> {
<ul class="checkbox-list"> <ul class="checkbox-list">
<li> <li>
<select onChange={this.replacementTypeChanged}> <select onChange={this.replacementTypeChanged}>
<option {replacementTypeOptions}
selected={replacementType === "numerical"}
value="numerical"
>
Numerical
</option>
<option selected={replacementType === "hashed"} value="hashed">
Hashed
</option>
</select> </select>
</li> </li>
</ul> </ul>