Working tree is now the canonical repo. Off-chain play-money + trustless on-chain (FPMM AMM + CLOB via UMA settlement), AI market factory, creator/social/distribution, mobile shell + push, one-command demo + deploy-kit. Secrets excluded (see ENV-AND-KEYS.md). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
34 lines
982 B
TypeScript
34 lines
982 B
TypeScript
import { Editor, Extension } from '@tiptap/core'
|
|
import toast from 'react-hot-toast'
|
|
import { useMutation } from 'web/hooks/use-mutation'
|
|
import { uploadPublicImage } 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) => uploadPublicImage('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>
|