mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-04 14:30:29 +03:00
Propery delete blank profile fields
This commit is contained in:
parent
5c2c8984aa
commit
c7f6e33a2b
1 changed files with 11 additions and 9 deletions
|
|
@ -32,7 +32,7 @@ import { UserEvent } from 'matrix-js-sdk';
|
||||||
import { SequenceCard } from '../../../components/sequence-card';
|
import { SequenceCard } from '../../../components/sequence-card';
|
||||||
import { SettingTile } from '../../../components/setting-tile';
|
import { SettingTile } from '../../../components/setting-tile';
|
||||||
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
import { useMatrixClient } from '../../../hooks/useMatrixClient';
|
||||||
import { getMxIdLocalPart, getMxIdServer, mxcUrlToHttp } from '../../../utils/matrix';
|
import { getMxIdServer, mxcUrlToHttp } from '../../../utils/matrix';
|
||||||
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
import { useMediaAuthentication } from '../../../hooks/useMediaAuthentication';
|
||||||
import { useFilePicker } from '../../../hooks/useFilePicker';
|
import { useFilePicker } from '../../../hooks/useFilePicker';
|
||||||
import { useObjectURL } from '../../../hooks/useObjectURL';
|
import { useObjectURL } from '../../../hooks/useObjectURL';
|
||||||
|
|
@ -173,7 +173,12 @@ function ProfileTextField<K extends keyof FilterByValues<ExtendedProfile, string
|
||||||
const hasChanges = defaultValue !== value;
|
const hasChanges = defaultValue !== value;
|
||||||
|
|
||||||
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
const handleChange: ChangeEventHandler<HTMLInputElement> = (evt) => {
|
||||||
setValue(evt.currentTarget.value);
|
const content = evt.currentTarget.value;
|
||||||
|
if (content.length > 0) {
|
||||||
|
setValue(evt.currentTarget.value);
|
||||||
|
} else {
|
||||||
|
setValue(undefined);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleReset = () => {
|
const handleReset = () => {
|
||||||
|
|
@ -390,12 +395,7 @@ export function Profile() {
|
||||||
const [fieldDefaults, setFieldDefaults] = useState<ExtendedProfile>({})
|
const [fieldDefaults, setFieldDefaults] = useState<ExtendedProfile>({})
|
||||||
useLayoutEffect(() => {
|
useLayoutEffect(() => {
|
||||||
if (extendedProfile !== undefined) {
|
if (extendedProfile !== undefined) {
|
||||||
setFieldDefaults(
|
setFieldDefaults(extendedProfile);
|
||||||
{
|
|
||||||
...extendedProfile,
|
|
||||||
displayname: extendedProfile.displayname ?? getMxIdLocalPart(userId) ?? userId,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}, [userId, setFieldDefaults, extendedProfile]);
|
}, [userId, setFieldDefaults, extendedProfile]);
|
||||||
|
|
||||||
|
|
@ -406,7 +406,9 @@ export function Profile() {
|
||||||
async (fields: ExtendedProfile) => {
|
async (fields: ExtendedProfile) => {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
Object.entries(fields).map(async ([key, value]) => {
|
Object.entries(fields).map(async ([key, value]) => {
|
||||||
if (value !== undefined) {
|
if (value === undefined) {
|
||||||
|
await mx.deleteExtendedProfileProperty(key);
|
||||||
|
} else {
|
||||||
await mx.setExtendedProfileProperty(key, value);
|
await mx.setExtendedProfileProperty(key, value);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue