diff --git a/apps/web/components/dashboard/UploadDropzone.tsx b/apps/web/components/dashboard/UploadDropzone.tsx index 60398ede..2807b892 100644 --- a/apps/web/components/dashboard/UploadDropzone.tsx +++ b/apps/web/components/dashboard/UploadDropzone.tsx @@ -17,7 +17,7 @@ import LoadingSpinner from "../ui/spinner"; import { toast } from "../ui/use-toast"; import BookmarkAlreadyExistsToast from "../utils/BookmarkAlreadyExistsToast"; -function useUploadAsset() { +export function useUploadAsset() { const { mutateAsync: createBookmark } = useCreateBookmarkWithPostHook({ onSuccess: (resp) => { if (resp.alreadyExists) { diff --git a/apps/web/components/dashboard/bookmarks/EditorCard.tsx b/apps/web/components/dashboard/bookmarks/EditorCard.tsx index badf6002..ed262d65 100644 --- a/apps/web/components/dashboard/bookmarks/EditorCard.tsx +++ b/apps/web/components/dashboard/bookmarks/EditorCard.tsx @@ -17,6 +17,8 @@ import { z } from "zod"; import { useCreateBookmarkWithPostHook } from "@hoarder/shared-react/hooks/bookmarks"; +import { useUploadAsset } from "../UploadDropzone"; + function useFocusOnKeyPress(inputRef: React.RefObject) { useEffect(() => { function handleKeyPress(e: KeyboardEvent) { @@ -74,6 +76,8 @@ export default function EditorCard({ className }: { className?: string }) { }, }); + const uploadAsset = useUploadAsset(); + function tryToImportUrls(text: string): void { const lines = text.split("\n"); const urls: URL[] = []; @@ -118,6 +122,23 @@ export default function EditorCard({ className }: { className?: string }) { list: undefined, }); + const handlePaste = async ( + event: React.ClipboardEvent, + ) => { + if (event?.clipboardData?.items) { + await Promise.all( + Array.from(event.clipboardData.items) + .filter((item) => item?.type?.startsWith("image")) + .map((item) => { + const blob = item.getAsFile(); + if (blob) { + return uploadAsset(blob); + } + }), + ); + } + }; + return (
{ if (demoMode) { @@ -154,6 +175,13 @@ export default function EditorCard({ className }: { className?: string }) { form.handleSubmit(onSubmit, onError)(); } }} + onPaste={(e) => { + e.preventDefault(); + if (demoMode) { + return; + } + handlePaste(e); + }} {...textFieldProps} />