Skip to content

Commit

Permalink
Compare to prev value
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinSchoeler committed Jun 11, 2024
1 parent 6a1f5f0 commit 32226b8
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions apps/meteor/client/providers/UserProvider/UserProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { SubscriptionWithRoom } from '@rocket.chat/ui-contexts';
import { UserContext, useEndpoint } from '@rocket.chat/ui-contexts';
import { Meteor } from 'meteor/meteor';
import type { ContextType, ReactElement, ReactNode } from 'react';
import React, { useEffect, useMemo } from 'react';
import React, { useEffect, useMemo, useRef } from 'react';

import { Subscriptions, ChatRoom } from '../../../app/models/client';
import { getUserPreference } from '../../../app/utils/client';
Expand Down Expand Up @@ -34,7 +34,6 @@ const logout = (): Promise<void> =>
Meteor.logout(async () => {
await afterLogoutCleanUpCallback.run(user);
sdk.call('logoutCleanUp', user).then(resolve, reject);
queryClient.clear();
});
});

Expand All @@ -44,6 +43,7 @@ type UserProviderProps = {

const UserProvider = ({ children }: UserProviderProps): ReactElement => {
const userId = useReactiveValue(getUserId);
const previousUserId = useRef(userId);
const user = useReactiveValue(getUser);
const [userLanguage, setUserLanguage] = useLocalStorage('userLanguage', '');
const [preferedLanguage, setPreferedLanguage] = useLocalStorage('preferedLanguage', '');
Expand Down Expand Up @@ -94,6 +94,14 @@ const UserProvider = ({ children }: UserProviderProps): ReactElement => {
}
}, [preferedLanguage, setPreferedLanguage, setUserLanguage, user?.language, userLanguage, userId, setUserPreferences]);

useEffect(() => {
if (previousUserId.current && previousUserId.current !== userId) {
queryClient.clear();
}

previousUserId.current = userId;
}, [userId]);

return <UserContext.Provider children={children} value={contextValue} />;
};

Expand Down

0 comments on commit 32226b8

Please sign in to comment.