diff --git a/apps/meteor/client/omnichannel/securityPrivacy/SecurityPrivacyRoute.tsx b/apps/meteor/client/omnichannel/securityPrivacy/SecurityPrivacyRoute.tsx index cef7a6200f4fe..412d7e7e631e7 100644 --- a/apps/meteor/client/omnichannel/securityPrivacy/SecurityPrivacyRoute.tsx +++ b/apps/meteor/client/omnichannel/securityPrivacy/SecurityPrivacyRoute.tsx @@ -4,7 +4,7 @@ import EditableSettingsProvider from '../../views/admin/settings/EditableSetting const SecurityPrivacyRoute = () => { return ( - + diff --git a/apps/meteor/client/providers/SettingsProvider.tsx b/apps/meteor/client/providers/SettingsProvider.tsx index b426b283c74aa..06bce25bc7481 100644 --- a/apps/meteor/client/providers/SettingsProvider.tsx +++ b/apps/meteor/client/providers/SettingsProvider.tsx @@ -4,52 +4,30 @@ import { SettingsContext, useAtLeastOnePermission, useMethod } from '@rocket.cha import { useQueryClient } from '@tanstack/react-query'; import { Tracker } from 'meteor/tracker'; import type { ReactNode } from 'react'; -import { useCallback, useEffect, useMemo, useState } from 'react'; +import { useCallback, useMemo } from 'react'; import { createReactiveSubscriptionFactory } from '../lib/createReactiveSubscriptionFactory'; import { PrivateSettingsCachedCollection } from '../lib/settings/PrivateSettingsCachedCollection'; import { PublicSettingsCachedCollection } from '../lib/settings/PublicSettingsCachedCollection'; +const settingsManagementPermissions = ['view-privileged-setting', 'edit-privileged-setting', 'manage-selected-settings']; + type SettingsProviderProps = { children?: ReactNode; - privileged?: boolean; }; -const SettingsProvider = ({ children, privileged = false }: SettingsProviderProps) => { - const hasPrivilegedPermission = useAtLeastOnePermission( - useMemo(() => ['view-privileged-setting', 'edit-privileged-setting', 'manage-selected-settings'], []), - ); - - const hasPrivateAccess = privileged && hasPrivilegedPermission; - - const cachedCollection = useMemo( - () => (hasPrivateAccess ? PrivateSettingsCachedCollection : PublicSettingsCachedCollection), - [hasPrivateAccess], - ); - - const [isLoading, setLoading] = useState(() => Tracker.nonreactive(() => !cachedCollection.ready.get())); - - useEffect(() => { - let mounted = true; - - const initialize = async (): Promise => { - if (!Tracker.nonreactive(() => cachedCollection.ready.get())) { - await cachedCollection.init(); - } +const SettingsProvider = ({ children }: SettingsProviderProps) => { + const canManageSettings = useAtLeastOnePermission(settingsManagementPermissions); - if (!mounted) { - return; - } + const cachedCollection = canManageSettings ? PrivateSettingsCachedCollection : PublicSettingsCachedCollection; - setLoading(false); - }; + const isLoading = Tracker.nonreactive(() => !cachedCollection.ready.get()); - initialize(); - - return (): void => { - mounted = false; - }; - }, [cachedCollection]); + if (isLoading) { + throw (async () => { + await cachedCollection.init(); + })(); + } const querySetting = useMemo( () => @@ -108,19 +86,15 @@ const SettingsProvider = ({ children, privileged = false }: SettingsProviderProp const contextValue = useMemo( () => ({ - hasPrivateAccess, - isLoading, + hasPrivateAccess: canManageSettings, querySetting, querySettings, dispatch, }), - [hasPrivateAccess, isLoading, querySetting, querySettings, dispatch], + [canManageSettings, querySetting, querySettings, dispatch], ); return ; }; export default SettingsProvider; - -// '[subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => {}]' -// '[subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => ISetting | undefined]' diff --git a/apps/meteor/client/sidebar/Sidebar.stories.tsx b/apps/meteor/client/sidebar/Sidebar.stories.tsx index 944bd45943bb3..61b173a754ad1 100644 --- a/apps/meteor/client/sidebar/Sidebar.stories.tsx +++ b/apps/meteor/client/sidebar/Sidebar.stories.tsx @@ -31,7 +31,6 @@ const settings: Record = { const settingContextValue: ContextType = { hasPrivateAccess: true, - isLoading: false, querySetting: (_id) => [() => () => undefined, () => settings[_id]], querySettings: () => [() => () => undefined, () => []], dispatch: async () => undefined, diff --git a/apps/meteor/client/sidebarv2/Sidebar.stories.tsx b/apps/meteor/client/sidebarv2/Sidebar.stories.tsx index 561ca0aba8ac1..fcf7037c518cb 100644 --- a/apps/meteor/client/sidebarv2/Sidebar.stories.tsx +++ b/apps/meteor/client/sidebarv2/Sidebar.stories.tsx @@ -31,7 +31,6 @@ const settings: Record = { const settingContextValue: ContextType = { hasPrivateAccess: true, - isLoading: false, querySetting: (_id) => [() => () => undefined, () => settings[_id]], querySettings: () => [() => () => undefined, () => []], dispatch: async () => undefined, diff --git a/apps/meteor/client/views/account/AccountSidebar.tsx b/apps/meteor/client/views/account/AccountSidebar.tsx index b6d065fe3683b..a651061f7a41f 100644 --- a/apps/meteor/client/views/account/AccountSidebar.tsx +++ b/apps/meteor/client/views/account/AccountSidebar.tsx @@ -16,7 +16,7 @@ const AccountSidebar = () => { // TODO: uplift this provider return ( - + diff --git a/apps/meteor/client/views/admin/AdministrationRouter.tsx b/apps/meteor/client/views/admin/AdministrationRouter.tsx index 90a93b74fefb0..d1adf66c8cb7f 100644 --- a/apps/meteor/client/views/admin/AdministrationRouter.tsx +++ b/apps/meteor/client/views/admin/AdministrationRouter.tsx @@ -49,9 +49,7 @@ const AdministrationRouter = ({ children }: AdministrationRouterProps): ReactEle return ( - - {children ? }>{children} : } - + {children ? }>{children} : } ); }; diff --git a/apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewRoute.tsx b/apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewRoute.tsx index 70db47fcd1e12..3dcecb0c72bb6 100644 --- a/apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewRoute.tsx +++ b/apps/meteor/client/views/admin/featurePreview/AdminFeaturePreviewRoute.tsx @@ -15,7 +15,7 @@ const AdminFeaturePreviewRoute = (): ReactElement => { } return ( - + diff --git a/apps/meteor/client/views/admin/settings/SettingsPage.tsx b/apps/meteor/client/views/admin/settings/SettingsPage.tsx index 5bc6acb7160de..abcf72e76bff4 100644 --- a/apps/meteor/client/views/admin/settings/SettingsPage.tsx +++ b/apps/meteor/client/views/admin/settings/SettingsPage.tsx @@ -1,7 +1,6 @@ -import { Icon, SearchInput, Skeleton, CardGrid } from '@rocket.chat/fuselage'; +import { Icon, SearchInput, CardGrid } from '@rocket.chat/fuselage'; import { useDebouncedValue } from '@rocket.chat/fuselage-hooks'; import type { TranslationKey } from '@rocket.chat/ui-contexts'; -import { useIsSettingsContextLoading } from '@rocket.chat/ui-contexts'; import type { ChangeEvent, ReactElement } from 'react'; import { useCallback, useState } from 'react'; import { useTranslation } from 'react-i18next'; @@ -18,7 +17,6 @@ const SettingsPage = (): ReactElement => { const handleChange = useCallback((e: ChangeEvent) => setFilter(e.currentTarget.value), []); const groups = useSettingsGroups(useDebouncedValue(filter, 400)); - const isLoadingGroups = useIsSettingsContextLoading(); return ( @@ -28,7 +26,6 @@ const SettingsPage = (): ReactElement => { - {isLoadingGroups && } { p: 8, }} > - {!isLoadingGroups && - !!groups.length && + {!!groups.length && groups.map((group) => ( { ))} - {!isLoadingGroups && !groups.length && } + {!groups.length && } ); diff --git a/apps/meteor/client/views/admin/sidebar/AdminSidebar.tsx b/apps/meteor/client/views/admin/sidebar/AdminSidebar.tsx index 59b3c611f1af3..1bcc7161c067a 100644 --- a/apps/meteor/client/views/admin/sidebar/AdminSidebar.tsx +++ b/apps/meteor/client/views/admin/sidebar/AdminSidebar.tsx @@ -15,7 +15,7 @@ const AdminSidebar = () => { // TODO: uplift this provider return ( - + { const currentPath = useCurrentRoutePath(); return ( - + diff --git a/apps/meteor/client/views/omnichannel/sidebar/OmnichannelSidebar.tsx b/apps/meteor/client/views/omnichannel/sidebar/OmnichannelSidebar.tsx index 51c3448b616b0..cae285427cac5 100644 --- a/apps/meteor/client/views/omnichannel/sidebar/OmnichannelSidebar.tsx +++ b/apps/meteor/client/views/omnichannel/sidebar/OmnichannelSidebar.tsx @@ -15,7 +15,7 @@ const OmnichannelSidebar = () => { const currentPath = useCurrentRoutePath(); return ( - + diff --git a/packages/mock-providers/src/MockedAppRootBuilder.tsx b/packages/mock-providers/src/MockedAppRootBuilder.tsx index 508f3a285e1d2..5cf4cf59164e7 100644 --- a/packages/mock-providers/src/MockedAppRootBuilder.tsx +++ b/packages/mock-providers/src/MockedAppRootBuilder.tsx @@ -92,7 +92,6 @@ export class MockedAppRootBuilder { private settings: Mutable> = { hasPrivateAccess: true, - isLoading: false, querySetting: (_id: string) => [() => () => undefined, () => undefined], querySettings: () => [() => () => undefined, () => []], dispatch: async () => undefined, diff --git a/packages/mock-providers/src/MockedSettingsContext.tsx b/packages/mock-providers/src/MockedSettingsContext.tsx index 86414992e9e75..eb1181ce5dbc7 100644 --- a/packages/mock-providers/src/MockedSettingsContext.tsx +++ b/packages/mock-providers/src/MockedSettingsContext.tsx @@ -4,7 +4,6 @@ import type { ContextType, ReactNode } from 'react'; const settingContextValue: ContextType = { hasPrivateAccess: true, - isLoading: false, querySetting: (_id: string) => [() => () => undefined, () => undefined], querySettings: () => [() => () => undefined, () => []], dispatch: async () => undefined, diff --git a/packages/ui-client/src/components/Header/Header.stories.tsx b/packages/ui-client/src/components/Header/Header.stories.tsx index e811675b68c9b..cc129f191601a 100644 --- a/packages/ui-client/src/components/Header/Header.stories.tsx +++ b/packages/ui-client/src/components/Header/Header.stories.tsx @@ -40,7 +40,6 @@ export default { [ () => () => undefined, () => ({ diff --git a/packages/ui-client/src/components/HeaderV2/Header.stories.tsx b/packages/ui-client/src/components/HeaderV2/Header.stories.tsx index bf91e16a7be4b..6121f306ea103 100644 --- a/packages/ui-client/src/components/HeaderV2/Header.stories.tsx +++ b/packages/ui-client/src/components/HeaderV2/Header.stories.tsx @@ -41,7 +41,6 @@ export default { [ () => () => undefined, () => ({ diff --git a/packages/ui-contexts/src/SettingsContext.ts b/packages/ui-contexts/src/SettingsContext.ts index f0a005344d468..a4f11b3235f6a 100644 --- a/packages/ui-contexts/src/SettingsContext.ts +++ b/packages/ui-contexts/src/SettingsContext.ts @@ -10,7 +10,6 @@ export type SettingsContextQuery = { export type SettingsContextValue = { readonly hasPrivateAccess: boolean; - readonly isLoading: boolean; readonly querySetting: ( _id: ISetting['_id'], ) => [subscribe: (onStoreChange: () => void) => () => void, getSnapshot: () => ISetting | undefined]; @@ -22,7 +21,6 @@ export type SettingsContextValue = { export const SettingsContext = createContext({ hasPrivateAccess: false, - isLoading: false, querySetting: () => [(): (() => void) => (): void => undefined, (): undefined => undefined], querySettings: () => [(): (() => void) => (): void => undefined, (): ISetting[] => []], dispatch: async () => undefined, diff --git a/packages/ui-contexts/src/hooks/useIsSettingsContextLoading.ts b/packages/ui-contexts/src/hooks/useIsSettingsContextLoading.ts deleted file mode 100644 index fe5155e5abbfb..0000000000000 --- a/packages/ui-contexts/src/hooks/useIsSettingsContextLoading.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { useContext } from 'react'; - -import { SettingsContext } from '../SettingsContext'; - -export const useIsSettingsContextLoading = (): boolean => useContext(SettingsContext).isLoading; diff --git a/packages/ui-contexts/src/index.ts b/packages/ui-contexts/src/index.ts index 313710bbfd4ef..dfcd7ca301455 100644 --- a/packages/ui-contexts/src/index.ts +++ b/packages/ui-contexts/src/index.ts @@ -33,7 +33,6 @@ export { useEndpoint } from './hooks/useEndpoint'; export { useGoToRoom } from './hooks/useGoToRoom'; export type { EndpointFunction } from './hooks/useEndpoint'; export { useIsPrivilegedSettingsContext } from './hooks/useIsPrivilegedSettingsContext'; -export { useIsSettingsContextLoading } from './hooks/useIsSettingsContextLoading'; export { useLanguage } from './hooks/useLanguage'; export { useLanguages } from './hooks/useLanguages'; export { useLayout } from './hooks/useLayout';