Custom Discriminator in EditUsernameModalBody

This commit is contained in:
Fedor Indutny 2024-01-18 11:53:24 -08:00 committed by GitHub
parent fa3937e084
commit 38914a45cb
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
26 changed files with 615 additions and 165 deletions

View file

@ -22,6 +22,8 @@ import type {
ZoomFactorType,
} from '../types/Storage.d';
import type { ThemeSettingType } from '../types/StorageUIKeys';
import type { AnyToast } from '../types/Toast';
import { ToastType } from '../types/Toast';
import type { ConversationType } from '../state/ducks/conversations';
import type {
ConversationColorType,
@ -47,7 +49,9 @@ import { PhoneNumberDiscoverability } from '../util/phoneNumberDiscoverability';
import { PhoneNumberSharingMode } from '../util/phoneNumberSharingMode';
import { Select } from './Select';
import { Spinner } from './Spinner';
import { ToastManager } from './ToastManager';
import { getCustomColorStyle } from '../util/getCustomColorStyle';
import { shouldNeverBeCalled } from '../util/shouldNeverBeCalled';
import {
DEFAULT_DURATIONS_IN_SECONDS,
DEFAULT_DURATIONS_SET,
@ -357,6 +361,7 @@ export function Preferences({
string | null
>(localeOverride);
const [languageSearchInput, setLanguageSearchInput] = useState('');
const [toast, setToast] = useState<AnyToast | undefined>();
function closeLanguageDialog() {
setLanguageDialog(null);
@ -1464,16 +1469,16 @@ export function Preferences({
text: i18n('icu:Preferences__pnp__discoverability__everyone'),
value: PhoneNumberDiscoverability.Discoverable,
},
...(whoCanSeeMe === PhoneNumberSharingMode.Nobody
? [
{
text: i18n(
'icu:Preferences__pnp__discoverability__nobody'
),
value: PhoneNumberDiscoverability.NotDiscoverable,
},
]
: []),
{
text: i18n('icu:Preferences__pnp__discoverability__nobody'),
value: PhoneNumberDiscoverability.NotDiscoverable,
readOnly: whoCanSeeMe === PhoneNumberSharingMode.Everybody,
onClick:
whoCanSeeMe === PhoneNumberSharingMode.Everybody
? () =>
setToast({ toastType: ToastType.WhoCanFindMeReadOnly })
: noop,
},
]}
value={whoCanFindMe}
/>
@ -1572,6 +1577,14 @@ export function Preferences({
{settings}
</div>
</div>
<ToastManager
OS="unused"
hideToast={() => setToast(undefined)}
i18n={i18n}
onUndoArchive={shouldNeverBeCalled}
openFileInFolder={shouldNeverBeCalled}
toast={toast}
/>
</>
);
}
@ -1638,6 +1651,8 @@ function Control({
type SettingsRadioOptionType<Enum> = Readonly<{
text: string;
value: Enum;
readOnly?: boolean;
onClick?: () => void;
}>;
function SettingsRadio<Enum>({
@ -1655,11 +1670,13 @@ function SettingsRadio<Enum>({
return (
<div className="Preferences__padding">
{options.map(({ text, value: optionValue }, i) => {
{options.map(({ text, value: optionValue, readOnly, onClick }, i) => {
const htmlId = htmlIds[i];
return (
<label
className="Preferences__settings-radio__label"
className={classNames('Preferences__settings-radio__label', {
'Preferences__settings-radio__label--readonly': readOnly,
})}
key={htmlId}
htmlFor={htmlId}
>
@ -1668,7 +1685,8 @@ function SettingsRadio<Enum>({
variant={CircleCheckboxVariant.Small}
id={htmlId}
checked={value === optionValue}
onChange={() => onChange(optionValue)}
onClick={onClick}
onChange={readOnly ? noop : () => onChange(optionValue)}
/>
{text}
</label>