Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
Refactor to using a hook
Browse files Browse the repository at this point in the history
And automatically refresh the timezone every minute.
  • Loading branch information
Half-Shot committed Sep 8, 2024
1 parent e78dfc2 commit 6989162
Show file tree
Hide file tree
Showing 2 changed files with 86 additions and 24 deletions.
28 changes: 4 additions & 24 deletions src/components/views/right_panel/UserInfo.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
User,
Device,
EventType,
MatrixError,

Check failure on line 32 in src/components/views/right_panel/UserInfo.tsx

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

'MatrixError' is declared but its value is never read.

Check failure on line 32 in src/components/views/right_panel/UserInfo.tsx

View workflow job for this annotation

GitHub Actions / ESLint

'MatrixError' is defined but never used
} from "matrix-js-sdk/src/matrix";
import { KnownMembership } from "matrix-js-sdk/src/types";
import { UserVerificationStatus, VerificationRequest } from "matrix-js-sdk/src/crypto-api";
Expand Down Expand Up @@ -93,7 +94,7 @@ import { SdkContextClass } from "../../../contexts/SDKContext";
import { asyncSome } from "../../../utils/arrays";
import { Flex } from "../../utils/Flex";
import CopyableText from "../elements/CopyableText";

import { useUserTimezone } from "../../../hooks/useUserTimezone";
export interface IDevice extends Device {
ambiguous?: boolean;
}
Expand Down Expand Up @@ -1703,28 +1704,7 @@ export const UserInfoHeader: React.FC<{
}


// TODO: Check for support for this property.
const [timezone, setTimezone] = useState<{friendly: string, tz: string}>();
useEffect(() => {
cli.getExtendedProfileProperty(member.userId, 'us.cloke.msc4175.tz').then((value) => {
if (typeof value !== "string") {
// Err, definitely not a tz.
return;
}
try {
setTimezone(
{
friendly: new Date().toLocaleString(undefined, { timeZone: value, hour12: true, hour: "2-digit", minute: "2-digit", timeZoneName: "shortOffset"}),
tz: value
}
);
} catch (ex) {
console.error('Could not render current time for user', ex);
}
}).catch((ex) => {
console.error('Unable to load user timezone', ex);
});
}, [member.userId]);
const timezoneInfo = useUserTimezone(member.userId);

const e2eIcon = e2eStatus ? <E2EIcon size={18} status={e2eStatus} isUser={true} /> : null;
const userIdentifier = UserIdentifierCustomisations.getDisplayUserIdentifier?.(member.userId, {
Expand Down Expand Up @@ -1758,7 +1738,7 @@ export const UserInfoHeader: React.FC<{
{e2eIcon}
</Flex>
</Heading>
{presenceLabel} {timezone && <Tooltip label={timezone.tz}><span>{timezone.friendly}</span></Tooltip>}
{presenceLabel} {timezoneInfo && <Tooltip label={timezoneInfo.timezone}><span>{timezoneInfo.friendly}</span></Tooltip>}
<Text size="sm" weight="semibold" className="mx_UserInfo_profile_mxid">
<CopyableText getTextToCopy={() => userIdentifier} border={false}>
{userIdentifier}
Expand Down
82 changes: 82 additions & 0 deletions src/hooks/useUserTimezone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import { useEffect, useState } from "react";

Check failure on line 1 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

Copyright heading is required

Check failure on line 1 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

There should be at least one empty line between import groups
import { MatrixClientPeg } from "../MatrixClientPeg";

Check failure on line 2 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

There should be at least one empty line between import groups
import { MatrixError } from "matrix-js-sdk/src/matrix";

Check failure on line 3 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

`matrix-js-sdk/src/matrix` import should occur before import of `../MatrixClientPeg`

/**
* Fetch a user's delclared timezone through their profile, and return
* a friendly string of the current time for that user. This will keep
* in sync with the current time, and will be refreshed once a minute.
*
* @param userId The userID to fetch the timezone for.
* @returns A timezone name and friendly string for the user's timezone, or
* null if the user has no timezone or the timezone was not recognised
* by the browser.
*/
export const useUserTimezone = (userId: string): { timezone: string, friendly: string }|null => {
const [timezone, setTimezone] = useState<string>();
const [updateInterval, setUpdateInterval] = useState<number>();
const [friendly, setFriendly] = useState<string>();
const [supported, setSupported] = useState<boolean>();
const cli = MatrixClientPeg.safeGet();

useEffect(() => {
if (supported !== undefined) {
return;
}
cli.doesServerSupportExtendedProfiles().then(setSupported).catch((ex) => {

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Property 'doesServerSupportExtendedProfiles' does not exist on type 'MatrixClient'.

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Parameter 'ex' implicitly has an 'any' type.

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › closes on close button click

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:222:9)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › does not render space header

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:231:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › renders user info

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:236:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › renders encryption info panel without pending verification

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:241:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › renders encryption verification panel with pending verification

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:246:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › should show error modal when the verification request is cancelled with a mismatch

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:255:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › should not show error modal when the verification request is changed for some other reason

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:270:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › without a room › renders close button correctly when encryption panel with a pending verification request

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:291:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › with a room › renders user info

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:299:13)

Check failure on line 26 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Jest (1)

<UserInfo /> › with a room › does not render space header when room is not a space room

TypeError: cli.doesServerSupportExtendedProfiles is not a function at doesServerSupportExtendedProfiles (src/hooks/useUserTimezone.ts:26:13) at invokePassiveEffectCreate (node_modules/react-dom/cjs/react-dom.development.js:23487:20) at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14) at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30) at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:350:25) at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:286:3) at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:233:9) at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:104:17) at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34) at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16) at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31) at flushPassiveEffectsImpl (node_modules/react-dom/cjs/react-dom.development.js:23574:9) at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushPassiveEffects (node_modules/react-dom/cjs/react-dom.development.js:23447:14) at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22269:3) at node_modules/react-dom/cjs/react-dom.development.js:11327:26 at unstable_runWithPriority (node_modules/scheduler/cjs/scheduler.development.js:468:12) at runWithPriority$1 (node_modules/react-dom/cjs/react-dom.development.js:11276:10) at flushSyncCallbackQueueImpl (node_modules/react-dom/cjs/react-dom.development.js:11322:9) at flushSyncCallbackQueue (node_modules/react-dom/cjs/react-dom.development.js:11309:3) at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22387:7) at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14) at render (node_modules/@testing-library/react/dist/pure.js:97:26) at renderComponent (test/components/views/right_panel/UserInfo-test.tsx:207:22) at Object.renderComponent (test/components/views/right_panel/UserInfo-test.tsx:304:13)
console.warn("Unable to determine if extended profiles are supported", ex);
});
}, [supported]);

Check failure on line 29 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'cli'. Either include it or remove the dependency array

useEffect(() => {
return () => {
if (updateInterval) {
clearInterval(updateInterval);
}
}
}, [updateInterval]);

useEffect(() => {
if (supported !== true) {
return;
}
(async () => {
try {
const tz = await cli.getExtendedProfileProperty(userId, 'us.cloke.msc4175.tz');

Check failure on line 45 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / Typescript Syntax Check

Property 'getExtendedProfileProperty' does not exist on type 'MatrixClient'.
if (typeof tz !== "string") {
// Err, definitely not a tz.
throw Error('Timezone value was not a string');
}
// This will validate the timezone for us.
Intl.DateTimeFormat(undefined, {timeZone: tz});

Check failure on line 51 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

A function with a name starting with an uppercase letter should only be used as a constructor

const updateTime = () => {

Check failure on line 53 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

Missing return type on function
const currentTime = new Date();
const friendly = currentTime.toLocaleString(undefined, { timeZone: tz, hour12: true, hour: "2-digit", minute: "2-digit", timeZoneName: "shortOffset"});
setTimezone(tz);
setFriendly(friendly);
setUpdateInterval(setTimeout(updateTime, (60 - currentTime.getSeconds()) * 1000));
}
updateTime();
} catch (ex) {
setTimezone(undefined);
setFriendly(undefined);
setUpdateInterval(undefined);
if (ex instanceof MatrixError && ex.errcode === "M_NOT_FOUND") {
// No timezone set, ignore.
return;
}
console.error('Could not render current timezone for user', ex);
}
})();
}, [supported, userId]);

Check failure on line 72 in src/hooks/useUserTimezone.ts

View workflow job for this annotation

GitHub Actions / ESLint

React Hook useEffect has a missing dependency: 'cli'. Either include it or remove the dependency array

if (!timezone || !friendly) {
return null;
}

return {
friendly,
timezone
};
}

0 comments on commit 6989162

Please sign in to comment.