2023-08-10 15:52:01 +00:00
|
|
|
import {Component} from "preact";
|
2023-08-15 10:15:16 +00:00
|
|
|
import {
|
|
|
|
fromStorage,
|
|
|
|
isReplacementType,
|
|
|
|
Feature,
|
|
|
|
ReplacementType,
|
|
|
|
} from "../../storage/exports.js";
|
2023-06-23 10:52:03 +00:00
|
|
|
import {Setting, type SettingProps} from "./index.js";
|
2022-02-23 17:17:22 +00:00
|
|
|
|
2023-08-10 15:52:01 +00:00
|
|
|
type State = {
|
|
|
|
data?: Awaited<ReturnType<typeof fromStorage<Feature.AnonymizeUsernames>>>;
|
|
|
|
};
|
|
|
|
|
|
|
|
export class AnonymizeUsernamesSetting extends Component<SettingProps, State> {
|
|
|
|
constructor(props: SettingProps) {
|
|
|
|
super(props);
|
|
|
|
|
|
|
|
this.state = {
|
|
|
|
data: undefined,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount(): Promise<void> {
|
|
|
|
const data = await fromStorage(Feature.AnonymizeUsernames);
|
|
|
|
this.setState({data});
|
|
|
|
}
|
|
|
|
|
|
|
|
replacementTypeChanged = async (event: Event) => {
|
|
|
|
const newValue = (event.target as HTMLInputElement)!.value;
|
|
|
|
const {data} = this.state;
|
2023-08-15 10:15:16 +00:00
|
|
|
if (data === undefined || !isReplacementType(newValue)) {
|
2023-08-10 15:52:01 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
data.value.replacementType = newValue;
|
|
|
|
await data.save();
|
|
|
|
this.setState({data});
|
|
|
|
};
|
|
|
|
|
|
|
|
render() {
|
|
|
|
const {data} = this.state;
|
|
|
|
if (data === undefined) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const replacementType = data.value.replacementType;
|
2023-08-11 09:23:46 +00:00
|
|
|
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>
|
|
|
|
));
|
2023-08-10 15:52:01 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<Setting {...this.props}>
|
|
|
|
<p class="info">
|
2023-09-11 10:43:46 +00:00
|
|
|
Anonymizes usernames by replacing them with an incrementing "Anonymous
|
|
|
|
#" or a SHA-256 hash of the username.
|
2023-08-10 15:52:01 +00:00
|
|
|
<br />
|
|
|
|
Note that User Labels and Username Colors will still be applied to any
|
|
|
|
usernames as normal.
|
|
|
|
</p>
|
|
|
|
|
|
|
|
<ul class="checkbox-list">
|
|
|
|
<li>
|
2023-09-11 10:43:46 +00:00
|
|
|
<label for="anonymize-usernames-replacement-type">
|
|
|
|
Replacement type:
|
|
|
|
</label>{" "}
|
|
|
|
<select
|
|
|
|
class="styled-select"
|
|
|
|
name="anonymize-usernames-replacement-type"
|
|
|
|
id="anonymize-usernames-replacement-type"
|
|
|
|
onChange={this.replacementTypeChanged}
|
|
|
|
>
|
2023-08-11 09:23:46 +00:00
|
|
|
{replacementTypeOptions}
|
2023-08-10 15:52:01 +00:00
|
|
|
</select>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
|
|
</Setting>
|
|
|
|
);
|
|
|
|
}
|
2022-02-23 17:17:22 +00:00
|
|
|
}
|