mirror of
https://github.com/Novaloop-AG/healthchat-web.git
synced 2026-12-04 07:10:07 +00:00
91a3cb03c1
mkdir apps/web/scripts
mv scripts/{cleanup.sh,ci_package.sh,copy-res.ts,deploy.py,package.sh} apps/web/scripts
And a couple of gitignore tweaks
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
60 lines
2.0 KiB
TypeScript
60 lines
2.0 KiB
TypeScript
/*
|
|
Copyright 2025 New Vector Ltd.
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only OR GPL-3.0-only OR LicenseRef-Element-Commercial
|
|
Please see LICENSE files in the repository root for full details.
|
|
*/
|
|
|
|
import React, { type ChangeEvent, type JSX, useCallback, useState } from "react";
|
|
import { EditInPlace } from "@vector-im/compound-web";
|
|
|
|
import SettingsStore from "../../../settings/SettingsStore";
|
|
import { _t } from "../../../languageHandler";
|
|
import { type SettingLevel } from "../../../settings/SettingLevel";
|
|
import { type StringSettingKey } from "../../../settings/Settings";
|
|
|
|
interface Props {
|
|
settingKey: StringSettingKey;
|
|
level: SettingLevel;
|
|
roomId?: string; // for per-room settings
|
|
label?: string;
|
|
isExplicit?: boolean;
|
|
onChange?(this: void, value: string): void;
|
|
}
|
|
|
|
const SettingsField = ({ settingKey, level, roomId, isExplicit, label, onChange: _onSave }: Props): JSX.Element => {
|
|
const settingsValue = SettingsStore.getValueAt(level, settingKey, roomId, isExplicit);
|
|
const [value, setValue] = useState(settingsValue);
|
|
const [busy, setBusy] = useState(false);
|
|
|
|
const onChange = useCallback((e: ChangeEvent<HTMLInputElement>) => {
|
|
setValue(e.target.value);
|
|
}, []);
|
|
const onCancel = useCallback(() => {
|
|
setValue(settingsValue);
|
|
}, [settingsValue]);
|
|
const onSave = useCallback(async () => {
|
|
setBusy(true);
|
|
await SettingsStore.setValue(settingKey, roomId ?? null, level, value);
|
|
setBusy(false);
|
|
_onSave?.(value);
|
|
}, [level, roomId, settingKey, value, _onSave]);
|
|
|
|
return (
|
|
<EditInPlace
|
|
label={label ?? SettingsStore.getDisplayName(settingKey, level) ?? ""}
|
|
value={value}
|
|
saveButtonLabel={_t("common|save")}
|
|
cancelButtonLabel={_t("common|cancel")}
|
|
savedLabel={_t("common|saved")}
|
|
savingLabel={_t("common|updating")}
|
|
onChange={onChange}
|
|
onCancel={onCancel}
|
|
onSave={onSave}
|
|
disabled={busy}
|
|
/>
|
|
);
|
|
};
|
|
|
|
export default SettingsField;
|