Improve Jotai work (#18205)
This commit is contained in:
+6
-2
@@ -20,8 +20,12 @@ export const ObjectMetadataProviderInitialEffect = () => {
|
||||
const { updateDraft, applyChanges } = useMetadataStore();
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialized) return;
|
||||
if (!isCurrentUserLoaded) return;
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
if (!isCurrentUserLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
const shouldLoadReal = isWorkspaceActiveOrSuspended(currentWorkspace);
|
||||
|
||||
|
||||
+8
-14
@@ -15,20 +15,17 @@ import { type ColorScheme } from '@/workspace-member/types/WorkspaceMember';
|
||||
import { enUS } from 'date-fns/locale';
|
||||
import { useStore } from 'jotai';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import { useLocation } from 'react-router-dom';
|
||||
import { type APP_LOCALES, SOURCE_LOCALE } from 'twenty-shared/translations';
|
||||
import { AppPath, type ObjectPermissions } from 'twenty-shared/types';
|
||||
import { type ObjectPermissions } from 'twenty-shared/types';
|
||||
import { isDefined } from 'twenty-shared/utils';
|
||||
import {
|
||||
useGetCurrentUserQuery,
|
||||
type WorkspaceMember,
|
||||
} from '~/generated-metadata/graphql';
|
||||
import { dateLocaleStateV2 } from '~/localization/states/dateLocaleStateV2';
|
||||
import { dateLocaleState } from '~/localization/states/dateLocaleState';
|
||||
import { dynamicActivate } from '~/utils/i18n/dynamicActivate';
|
||||
import { isMatchingLocation } from '~/utils/isMatchingLocation';
|
||||
|
||||
export const UserMetadataProviderInitialEffect = () => {
|
||||
const location = useLocation();
|
||||
const isLoggedIn = useIsLogged();
|
||||
const currentUser = useRecoilValueV2(currentUserState);
|
||||
const store = useStore();
|
||||
@@ -53,28 +50,23 @@ export const UserMetadataProviderInitialEffect = () => {
|
||||
|
||||
const { initializeFormatPreferences } = useInitializeFormatPreferences();
|
||||
|
||||
const isOnAuthPath =
|
||||
isMatchingLocation(location, AppPath.Verify) ||
|
||||
isMatchingLocation(location, AppPath.VerifyEmail);
|
||||
|
||||
const updateLocaleCatalog = useCallback(
|
||||
async (newLocale: keyof typeof APP_LOCALES) => {
|
||||
const localeValue = store.get(dateLocaleStateV2.atom);
|
||||
const localeValue = store.get(dateLocaleState.atom);
|
||||
if (localeValue.locale !== newLocale) {
|
||||
getDateFnsLocale(newLocale).then((localeCatalog) => {
|
||||
const newValue = {
|
||||
locale: newLocale,
|
||||
localeCatalog: localeCatalog || enUS,
|
||||
};
|
||||
store.set(dateLocaleStateV2.atom, newValue);
|
||||
store.set(dateLocaleState.atom, newValue);
|
||||
});
|
||||
}
|
||||
},
|
||||
[store],
|
||||
);
|
||||
|
||||
const shouldSkipUserQuery =
|
||||
!isLoggedIn || isDefined(currentUser) || isOnAuthPath;
|
||||
const shouldSkipUserQuery = !isLoggedIn || isDefined(currentUser);
|
||||
|
||||
const { data: userQueryData, loading: userQueryLoading } =
|
||||
useGetCurrentUserQuery({
|
||||
@@ -82,7 +74,9 @@ export const UserMetadataProviderInitialEffect = () => {
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialized) return;
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isLoggedIn) {
|
||||
setIsCurrentUserLoaded(true);
|
||||
|
||||
+6
-2
@@ -48,8 +48,12 @@ export const ViewMetadataProviderInitialEffect = () => {
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (isInitialized) return;
|
||||
if (!isCurrentUserLoaded) return;
|
||||
if (isInitialized) {
|
||||
return;
|
||||
}
|
||||
if (!isCurrentUserLoaded) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!isLoggedIn || !isWorkspaceActiveOrSuspended(currentWorkspace)) {
|
||||
setIsInitialized(true);
|
||||
|
||||
Reference in New Issue
Block a user