Simplify last visited (#10259)
In this PR, I'm simplifying the lastVisitedView / Object logic: - removing fallback logic as it's not useful - splitting hooks into smaller hooks (to avoir re-renders) - removing componentState on those states that are global
This commit is contained in:
@ -1,10 +1,7 @@
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
import { createState } from 'twenty-ui';
|
||||
import { localStorageEffect } from '~/utils/recoil-effects';
|
||||
|
||||
export const lastVisitedObjectMetadataItemIdState = createComponentState<Record<
|
||||
string,
|
||||
string
|
||||
> | null>({
|
||||
export const lastVisitedObjectMetadataItemIdState = createState<string | null>({
|
||||
key: 'lastVisitedObjectMetadataItemIdState',
|
||||
defaultValue: null,
|
||||
effects: [localStorageEffect()],
|
||||
|
||||
@ -1,9 +1,11 @@
|
||||
import { createComponentState } from '@/ui/utilities/state/component-state/utils/createComponentState';
|
||||
import { createState } from 'twenty-ui';
|
||||
import { localStorageEffect } from '~/utils/recoil-effects';
|
||||
|
||||
export const lastVisitedViewPerObjectMetadataItemState =
|
||||
createComponentState<Record<string, string> | null>({
|
||||
key: 'lastVisitedViewPerObjectMetadataItemState',
|
||||
defaultValue: null,
|
||||
effects: [localStorageEffect()],
|
||||
});
|
||||
export const lastVisitedViewPerObjectMetadataItemState = createState<Record<
|
||||
string,
|
||||
string
|
||||
> | null>({
|
||||
key: 'lastVisitedViewPerObjectMetadataItemState',
|
||||
defaultValue: null,
|
||||
effects: [localStorageEffect()],
|
||||
});
|
||||
|
||||
@ -1,24 +0,0 @@
|
||||
import { lastVisitedObjectMetadataItemIdState } from '@/navigation/states/lastVisitedObjectMetadataItemIdState';
|
||||
import { createComponentSelector } from '@/ui/utilities/state/component-state/utils/createComponentSelector';
|
||||
|
||||
export const lastVisitedObjectMetadataItemIdStateSelector =
|
||||
createComponentSelector<string | null>({
|
||||
key: 'lastVisitedObjectMetadataItemIdStateSelector',
|
||||
get:
|
||||
({ scopeId }: { scopeId: string }) =>
|
||||
({ get }) => {
|
||||
const state = get(lastVisitedObjectMetadataItemIdState({ scopeId }));
|
||||
return state?.['last_visited_object']
|
||||
? state['last_visited_object']
|
||||
: null;
|
||||
},
|
||||
set:
|
||||
({ scopeId }: { scopeId: string }) =>
|
||||
({ set }, newValue) => {
|
||||
set(lastVisitedObjectMetadataItemIdState({ scopeId }), {
|
||||
...(typeof newValue === 'string' && {
|
||||
last_visited_object: newValue,
|
||||
}),
|
||||
});
|
||||
},
|
||||
});
|
||||
@ -1,34 +0,0 @@
|
||||
import { lastVisitedViewPerObjectMetadataItemState } from '@/navigation/states/lastVisitedViewPerObjectMetadataItemState';
|
||||
import { createComponentSelector } from '@/ui/utilities/state/component-state/utils/createComponentSelector';
|
||||
import { isDefined } from 'twenty-shared';
|
||||
|
||||
export const lastVisitedViewPerObjectMetadataItemStateSelector =
|
||||
createComponentSelector<Record<string, string> | null>({
|
||||
key: 'lastVisitedViewPerObjectMetadataItemStateSelector',
|
||||
get:
|
||||
({ scopeId }: { scopeId: string }) =>
|
||||
({ get }) => {
|
||||
const state = get(
|
||||
lastVisitedViewPerObjectMetadataItemState({ scopeId }),
|
||||
);
|
||||
|
||||
if (isDefined(state?.['last_visited_object'])) {
|
||||
const { last_visited_object: _last_visited_object, ...rest } = state;
|
||||
return rest;
|
||||
}
|
||||
|
||||
return state;
|
||||
},
|
||||
set:
|
||||
({ scopeId }: { scopeId: string }) =>
|
||||
({ set, get }, newValue) => {
|
||||
const currentLastVisitedViewPerObjectMetadataItems = get(
|
||||
lastVisitedViewPerObjectMetadataItemStateSelector({ scopeId }),
|
||||
);
|
||||
|
||||
set(lastVisitedViewPerObjectMetadataItemState({ scopeId }), {
|
||||
...currentLastVisitedViewPerObjectMetadataItems,
|
||||
...newValue,
|
||||
});
|
||||
},
|
||||
});
|
||||
Reference in New Issue
Block a user