diff --git a/apps/meteor/app/nextcloud/client/lib.ts b/apps/meteor/app/nextcloud/client/lib.ts index fb7f5391bc3a9..22151c7ff8c29 100644 --- a/apps/meteor/app/nextcloud/client/lib.ts +++ b/apps/meteor/app/nextcloud/client/lib.ts @@ -1,10 +1,8 @@ import type { OauthConfig } from '@rocket.chat/core-typings'; -import { Meteor } from 'meteor/meteor'; -import { Tracker } from 'meteor/tracker'; -import _ from 'underscore'; +import { useSetting } from '@rocket.chat/ui-contexts'; +import { useEffect } from 'react'; import { CustomOAuth } from '../../custom-oauth/client/CustomOAuth'; -import { settings } from '../../settings/client'; const config: OauthConfig = { serverURL: '', @@ -21,20 +19,13 @@ const config: OauthConfig = { const Nextcloud = new CustomOAuth('nextcloud', config); -const fillServerURL = _.debounce((): void => { - const nextcloudURL = settings.get('Accounts_OAuth_Nextcloud_URL'); - if (!nextcloudURL) { - if (nextcloudURL === undefined) { - return fillServerURL(); - } - return; - } - config.serverURL = nextcloudURL.trim().replace(/\/*$/, ''); - return Nextcloud.configure(config); -}, 100); +export const useNextcloud = (): void => { + const nextcloudURL = useSetting('Accounts_OAuth_Nextcloud_URL') as string; -Meteor.startup(() => { - Tracker.autorun(() => { - return fillServerURL(); - }); -}); + useEffect(() => { + if (nextcloudURL) { + config.serverURL = nextcloudURL.trim().replace(/\/*$/, ''); + Nextcloud.configure(config); + } + }, [nextcloudURL]); +}; diff --git a/apps/meteor/client/views/root/AppLayout.tsx b/apps/meteor/client/views/root/AppLayout.tsx index 8a4485ceef7b3..789cff5083a7f 100644 --- a/apps/meteor/client/views/root/AppLayout.tsx +++ b/apps/meteor/client/views/root/AppLayout.tsx @@ -7,6 +7,7 @@ import { useEscapeKeyStroke } from './hooks/useEscapeKeyStroke'; import { useGoogleTagManager } from './hooks/useGoogleTagManager'; import { useMessageLinkClicks } from './hooks/useMessageLinkClicks'; import { useAnalytics } from '../../../app/analytics/client/loadScript'; +import { useNextcloud } from '../../../app/nextcloud/client/lib'; import { useAnalyticsEventTracking } from '../../hooks/useAnalyticsEventTracking'; import { useLoadRoomForAllowedAnonymousRead } from '../../hooks/useLoadRoomForAllowedAnonymousRead'; import { useNotifyUser } from '../../hooks/useNotifyUser'; @@ -29,6 +30,8 @@ const AppLayout = () => { useLoadRoomForAllowedAnonymousRead(); useNotifyUser(); + useNextcloud(); + const layout = useSyncExternalStore(appLayout.subscribe, appLayout.getSnapshot); return (