# 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
35 lines
1.1 KiB
TypeScript
35 lines
1.1 KiB
TypeScript
import { BLOCK_SCHEMA } from '@/activities/blocks/constants/Schema';
|
|
import { recordStoreFamilyState } from '@/object-record/record-store/states/recordStoreFamilyState';
|
|
import { isNonEmptyString } from '@sniptt/guards';
|
|
import { useRecoilCallback } from 'recoil';
|
|
import { isDefined } from 'twenty-shared';
|
|
import { isDeeplyEqual } from '~/utils/isDeeplyEqual';
|
|
|
|
export const useReplaceActivityBlockEditorContent = (
|
|
editor: typeof BLOCK_SCHEMA.BlockNoteEditor,
|
|
) => {
|
|
const replaceBlockEditorContent = useRecoilCallback(
|
|
({ snapshot }) =>
|
|
(activityId: string) => {
|
|
if (isDefined(editor)) {
|
|
const activityInStore = snapshot
|
|
.getLoadable(recordStoreFamilyState(activityId))
|
|
.getValue();
|
|
|
|
const content = isNonEmptyString(activityInStore?.body)
|
|
? JSON.parse(activityInStore?.body)
|
|
: [{ type: 'paragraph', content: '' }];
|
|
|
|
if (!isDeeplyEqual(editor.document, content)) {
|
|
editor.replaceBlocks(editor.document, content);
|
|
}
|
|
}
|
|
},
|
|
[editor],
|
|
);
|
|
|
|
return {
|
|
replaceBlockEditorContent,
|
|
};
|
|
};
|