diff --git a/src/app/components/user-profile/UserChips.tsx b/src/app/components/user-profile/UserChips.tsx index d06750dd..a40c93cd 100644 --- a/src/app/components/user-profile/UserChips.tsx +++ b/src/app/components/user-profile/UserChips.tsx @@ -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 FocusTrap from 'focus-trap-react'; import { isKeyHotkey } from 'is-hotkey'; @@ -538,11 +538,16 @@ export function TimezoneChip({ timezone }: { timezone: string }) { ); const [shortTime, setShortTime] = useState(shortFormat.format()); const [longTime, setLongTime] = useState(longFormat.format()); - - useInterval(() => { + const updateTime = useCallback(() => { setShortTime(shortFormat.format()); setLongTime(longFormat.format()); - }, 1000); + }, [setShortTime, setLongTime, shortFormat, longFormat]); + + useEffect(() => { + updateTime(); + }, [timezone, updateTime]); + + useInterval(updateTime, 1000); return ( ( - () => - extendedProfile !== undefined - ? { - ...extendedProfile, - displayname: extendedProfile.displayname ?? getMxIdLocalPart(userId) ?? userId, - } - : {}, - [userId, extendedProfile] - ); + + const [fieldDefaults, setFieldDefaults] = useState({}) + useLayoutEffect(() => { + if (extendedProfile !== undefined) { + setFieldDefaults( + { + ...extendedProfile, + displayname: extendedProfile.displayname ?? getMxIdLocalPart(userId) ?? userId, + } + ); + } + }, [userId, setFieldDefaults, extendedProfile]); const useAuthentication = useMediaAuthentication(); @@ -473,7 +476,7 @@ export function Profile() { - + + {saving && }