- i18next 23->26 + react-i18next 15->17 - prettier 2->3, reformat all files - replace @fontsource/inter with @fontsource-variable/inter 5, update import path - domhandler 5->6 (aligns with transitive deps) - lint-staged 16->17
33 lines
1.0 KiB
TypeScript
33 lines
1.0 KiB
TypeScript
import React, { ReactNode, useCallback, useMemo } from 'react';
|
|
import { AutoDiscoveryInfoProvider } from '../../hooks/useAutoDiscoveryInfo';
|
|
import { AsyncStatus, useAsyncCallbackValue } from '../../hooks/useAsyncCallback';
|
|
import { autoDiscovery, AutoDiscoveryInfo } from '../../cs-api';
|
|
import { getMxIdServer } from '../../utils/matrix';
|
|
|
|
type AutoDiscoveryProps = {
|
|
userId: string;
|
|
baseUrl: string;
|
|
children: ReactNode;
|
|
};
|
|
export function AutoDiscovery({ userId, baseUrl, children }: AutoDiscoveryProps) {
|
|
const [state] = useAsyncCallbackValue(
|
|
useCallback(async () => {
|
|
const server = getMxIdServer(userId);
|
|
return autoDiscovery(fetch, server ?? userId);
|
|
}, [userId]),
|
|
);
|
|
|
|
const [, info] = state.status === AsyncStatus.Success ? state.data : [];
|
|
|
|
const fallback: AutoDiscoveryInfo = useMemo(
|
|
() => ({
|
|
'm.homeserver': {
|
|
base_url: baseUrl,
|
|
},
|
|
}),
|
|
[baseUrl],
|
|
);
|
|
|
|
return <AutoDiscoveryInfoProvider value={info ?? fallback}>{children}</AutoDiscoveryInfoProvider>;
|
|
}
|