mirror of
https://github.com/cinnyapp/cinny.git
synced 2025-11-10 01:00:28 +03:00
Fix flickering issues when updating profile fields
This commit is contained in:
parent
c3901804c0
commit
5c2c8984aa
2 changed files with 25 additions and 17 deletions
|
|
@ -1,4 +1,4 @@
|
||||||
import React, { MouseEventHandler, useCallback, useMemo, useState } from 'react';
|
import React, { MouseEventHandler, useCallback, useEffect, useMemo, useState } from 'react';
|
||||||
import { useNavigate } from 'react-router-dom';
|
import { useNavigate } from 'react-router-dom';
|
||||||
import FocusTrap from 'focus-trap-react';
|
import FocusTrap from 'focus-trap-react';
|
||||||
import { isKeyHotkey } from 'is-hotkey';
|
import { isKeyHotkey } from 'is-hotkey';
|
||||||
|
|
@ -538,11 +538,16 @@ export function TimezoneChip({ timezone }: { timezone: string }) {
|
||||||
);
|
);
|
||||||
const [shortTime, setShortTime] = useState(shortFormat.format());
|
const [shortTime, setShortTime] = useState(shortFormat.format());
|
||||||
const [longTime, setLongTime] = useState(longFormat.format());
|
const [longTime, setLongTime] = useState(longFormat.format());
|
||||||
|
const updateTime = useCallback(() => {
|
||||||
useInterval(() => {
|
|
||||||
setShortTime(shortFormat.format());
|
setShortTime(shortFormat.format());
|
||||||
setLongTime(longFormat.format());
|
setLongTime(longFormat.format());
|
||||||
}, 1000);
|
}, [setShortTime, setLongTime, shortFormat, longFormat]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
updateTime();
|
||||||
|
}, [timezone, updateTime]);
|
||||||
|
|
||||||
|
useInterval(updateTime, 1000);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TooltipProvider
|
<TooltipProvider
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import React, {
|
||||||
ReactNode,
|
ReactNode,
|
||||||
useCallback,
|
useCallback,
|
||||||
useEffect,
|
useEffect,
|
||||||
|
useLayoutEffect,
|
||||||
useMemo,
|
useMemo,
|
||||||
useRef,
|
useRef,
|
||||||
useState,
|
useState,
|
||||||
|
|
@ -385,16 +386,18 @@ export function Profile() {
|
||||||
const [extendedProfileState, refreshExtendedProfile] = useExtendedProfile(userId);
|
const [extendedProfileState, refreshExtendedProfile] = useExtendedProfile(userId);
|
||||||
const extendedProfile =
|
const extendedProfile =
|
||||||
extendedProfileState.status === AsyncStatus.Success ? extendedProfileState.data : undefined;
|
extendedProfileState.status === AsyncStatus.Success ? extendedProfileState.data : undefined;
|
||||||
const fieldDefaults = useMemo<ExtendedProfile>(
|
|
||||||
() =>
|
const [fieldDefaults, setFieldDefaults] = useState<ExtendedProfile>({})
|
||||||
extendedProfile !== undefined
|
useLayoutEffect(() => {
|
||||||
? {
|
if (extendedProfile !== undefined) {
|
||||||
...extendedProfile,
|
setFieldDefaults(
|
||||||
displayname: extendedProfile.displayname ?? getMxIdLocalPart(userId) ?? userId,
|
{
|
||||||
}
|
...extendedProfile,
|
||||||
: {},
|
displayname: extendedProfile.displayname ?? getMxIdLocalPart(userId) ?? userId,
|
||||||
[userId, extendedProfile]
|
}
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
}, [userId, setFieldDefaults, extendedProfile]);
|
||||||
|
|
||||||
const useAuthentication = useMediaAuthentication();
|
const useAuthentication = useMediaAuthentication();
|
||||||
|
|
||||||
|
|
@ -473,7 +476,7 @@ export function Profile() {
|
||||||
<ProfileAvatar />
|
<ProfileAvatar />
|
||||||
<ProfileTextField field="displayname" label="Display Name" />
|
<ProfileTextField field="displayname" label="Display Name" />
|
||||||
<ProfileTimezone />
|
<ProfileTimezone />
|
||||||
<Box gap="300">
|
<Box gap="300" alignItems='Center'>
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="submit"
|
||||||
size="300"
|
size="300"
|
||||||
|
|
@ -484,7 +487,6 @@ export function Profile() {
|
||||||
disabled={!hasChanges || busy}
|
disabled={!hasChanges || busy}
|
||||||
onClick={save}
|
onClick={save}
|
||||||
>
|
>
|
||||||
{saving && <Spinner variant="Success" fill="Solid" size="300" />}
|
|
||||||
<Text size="B300">Save</Text>
|
<Text size="B300">Save</Text>
|
||||||
</Button>
|
</Button>
|
||||||
<Button
|
<Button
|
||||||
|
|
@ -496,9 +498,10 @@ export function Profile() {
|
||||||
radii="300"
|
radii="300"
|
||||||
onClick={reset}
|
onClick={reset}
|
||||||
disabled={!hasChanges || busy}
|
disabled={!hasChanges || busy}
|
||||||
>
|
>
|
||||||
<Text size="B300">Cancel</Text>
|
<Text size="B300">Cancel</Text>
|
||||||
</Button>
|
</Button>
|
||||||
|
{saving && <Spinner size="300" />}
|
||||||
</Box>
|
</Box>
|
||||||
</SequenceCard>
|
</SequenceCard>
|
||||||
</>
|
</>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue