mirror of
https://github.com/CompassConnections/Compass.git
synced 2026-03-25 10:02:27 -04:00
* Test * Add pretty formatting * Fix Tests * Fix Tests * Fix Tests * Fix * Add pretty formatting fix * Fix * Test * Fix tests * Clean typeckech * Add prettier check * Fix api tsconfig * Fix api tsconfig * Fix tsconfig * Fix * Fix * Prettier
34 lines
961 B
TypeScript
34 lines
961 B
TypeScript
import {Editor, Extension} from '@tiptap/core'
|
|
import toast from 'react-hot-toast'
|
|
import {useMutation} from 'web/hooks/use-mutation'
|
|
import {uploadImage} from 'web/lib/firebase/storage'
|
|
|
|
export const Upload = Extension.create({
|
|
name: 'upload',
|
|
|
|
addStorage: () => ({mutation: {}}),
|
|
})
|
|
|
|
export const useUploadMutation = (editor: Editor | null) =>
|
|
useMutation(
|
|
(files: File[]) =>
|
|
// TODO: Images should be uploaded under a particular username
|
|
Promise.all(files.map((file) => uploadImage('default', file))),
|
|
{
|
|
onSuccess(urls) {
|
|
if (!editor || !urls.length) return
|
|
let trans = editor.chain().focus()
|
|
urls.forEach((src) => {
|
|
trans = trans.setImage({src})
|
|
trans = trans.createParagraphNear()
|
|
})
|
|
trans.run()
|
|
},
|
|
onError(error: any) {
|
|
toast.error(error.message ?? error)
|
|
},
|
|
},
|
|
)
|
|
|
|
export type UploadMutation = ReturnType<typeof useUploadMutation>
|