7fd89678b7
# Introduction Avoid having multiple `isDefined` definition across our pacakges Also avoid importing `isDefined` from `twenty-ui` which exposes a huge barrel for a such little util function ## In a nutshell Removed own `isDefined.ts` definition from `twenty-ui` `twenty-front` and `twenty-server` to move it to `twenty-shared`. Updated imports for each packages, and added explicit dependencies to `twenty-shared` if not already in place Related PR https://github.com/twentyhq/twenty/pull/9941
88 lines
2.5 KiB
TypeScript
88 lines
2.5 KiB
TypeScript
import { useRecoilCallback } from 'recoil';
|
|
|
|
import { bottomBarHotkeyComponentState } from '@/ui/layout/bottom-bar/states/bottomBarHotkeyComponentState';
|
|
import { isBottomBarOpenedComponentState } from '@/ui/layout/bottom-bar/states/isBottomBarOpenedComponentState';
|
|
import { usePreviousHotkeyScope } from '@/ui/utilities/hotkey/hooks/usePreviousHotkeyScope';
|
|
import { HotkeyScope } from '@/ui/utilities/hotkey/types/HotkeyScope';
|
|
import { isDefined } from 'twenty-shared';
|
|
|
|
export const useBottomBar = () => {
|
|
const {
|
|
setHotkeyScopeAndMemorizePreviousScope,
|
|
goBackToPreviousHotkeyScope,
|
|
} = usePreviousHotkeyScope();
|
|
|
|
const closeBottomBar = useRecoilCallback(
|
|
({ set }) =>
|
|
(specificComponentId: string) => {
|
|
goBackToPreviousHotkeyScope();
|
|
set(
|
|
isBottomBarOpenedComponentState.atomFamily({
|
|
instanceId: specificComponentId,
|
|
}),
|
|
false,
|
|
);
|
|
},
|
|
[goBackToPreviousHotkeyScope],
|
|
);
|
|
|
|
const openBottomBar = useRecoilCallback(
|
|
({ set, snapshot }) =>
|
|
(specificComponentId: string, customHotkeyScope?: HotkeyScope) => {
|
|
const bottomBarHotkeyScope = snapshot
|
|
.getLoadable(
|
|
bottomBarHotkeyComponentState.atomFamily({
|
|
instanceId: specificComponentId,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
set(
|
|
isBottomBarOpenedComponentState.atomFamily({
|
|
instanceId: specificComponentId,
|
|
}),
|
|
true,
|
|
);
|
|
|
|
if (isDefined(customHotkeyScope)) {
|
|
setHotkeyScopeAndMemorizePreviousScope(
|
|
customHotkeyScope.scope,
|
|
customHotkeyScope.customScopes,
|
|
);
|
|
} else if (isDefined(bottomBarHotkeyScope)) {
|
|
setHotkeyScopeAndMemorizePreviousScope(
|
|
bottomBarHotkeyScope.scope,
|
|
bottomBarHotkeyScope.customScopes,
|
|
);
|
|
}
|
|
},
|
|
[setHotkeyScopeAndMemorizePreviousScope],
|
|
);
|
|
|
|
const toggleBottomBar = useRecoilCallback(
|
|
({ snapshot }) =>
|
|
(specificComponentId: string) => {
|
|
const isBottomBarOpen = snapshot
|
|
.getLoadable(
|
|
isBottomBarOpenedComponentState.atomFamily({
|
|
instanceId: specificComponentId,
|
|
}),
|
|
)
|
|
.getValue();
|
|
|
|
if (isBottomBarOpen) {
|
|
closeBottomBar(specificComponentId);
|
|
} else {
|
|
openBottomBar(specificComponentId);
|
|
}
|
|
},
|
|
[closeBottomBar, openBottomBar],
|
|
);
|
|
|
|
return {
|
|
closeBottomBar,
|
|
openBottomBar,
|
|
toggleBottomBar,
|
|
};
|
|
};
|