-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #894 from equinor/feat/rich-text-imgs
✨ Added new image callbacks to RichText components to make it easier to use images
- Loading branch information
Showing
15 changed files
with
360 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
import { ImageExtensionFnProps } from 'src/molecules/RichTextEditor/RichTextEditor.types'; | ||
|
||
export function useRichTextImage( | ||
image: string, | ||
onImageRead: ImageExtensionFnProps['onImageRead'] | undefined | ||
) { | ||
return useQuery({ | ||
queryKey: [image], | ||
queryFn: async () => { | ||
if (onImageRead) { | ||
const response = await onImageRead(image); | ||
const extension = image.split('.').at(-1); | ||
return `data:image/${extension};base64,${response}`; | ||
} | ||
|
||
return image; | ||
}, | ||
staleTime: Infinity, | ||
gcTime: Infinity, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.