Upload image for use in blocknote editor (#3044)

* - upload image to use in blocknote editor
- fix local-storage not in gitignore

* fix lint

* fix runtime config
add tests for body parsing notes and tasks

* lint
This commit is contained in:
brendanlaschke
2023-12-20 15:16:19 +01:00
committed by GitHub
parent 351dc6488c
commit c4fecb0a1a
11 changed files with 282 additions and 24 deletions

View File

@ -9,6 +9,8 @@ import { Activity } from '@/activities/types/Activity';
import { useUpdateOneRecord } from '@/object-record/hooks/useUpdateOneRecord';
import { BlockEditor } from '@/ui/input/editor/components/BlockEditor';
import { useIsFeatureEnabled } from '@/workspace/hooks/useIsFeatureEnabled';
import { REACT_APP_SERVER_BASE_URL } from '~/config';
import { FileFolder, useUploadFileMutation } from '~/generated/graphql';
const StyledBlockNoteStyledContainer = styled.div`
width: 100%;
@ -56,6 +58,26 @@ export const ActivityBodyEditor = ({
slashMenuItems = slashMenuItems.filter((x) => x.name != 'Image');
}
const [uploadFile] = useUploadFileMutation();
const handleUploadAttachment = async (file: File): Promise<string> => {
if (!file) {
return '';
}
const result = await uploadFile({
variables: {
file,
fileFolder: FileFolder.Attachment,
},
});
if (!result?.data?.uploadFile) {
throw new Error("Couldn't upload Image");
}
const imageUrl =
REACT_APP_SERVER_BASE_URL + '/files/' + result?.data?.uploadFile;
return imageUrl;
};
const editor: BlockNoteEditor | null = useBlockNote({
initialContent:
isNonEmptyString(activity.body) && activity.body !== '{}'
@ -66,6 +88,7 @@ export const ActivityBodyEditor = ({
debounceOnChange(JSON.stringify(editor.topLevelBlocks) ?? '');
},
slashMenuItems,
uploadFile: imagesActivated ? handleUploadAttachment : undefined,
});
return (