diff --git a/src/views/notifications/components/notification-item.tsx b/src/views/notifications/components/notification-item.tsx index a8503b1b0..5d8dbe7eb 100644 --- a/src/views/notifications/components/notification-item.tsx +++ b/src/views/notifications/components/notification-item.tsx @@ -80,7 +80,7 @@ const ReactionNotification = forwardRef(( return ( }> - + @@ -123,7 +123,7 @@ const ZapNotification = forwardRef(({ eve return ( }> - + diff --git a/src/views/streams/stream/stream-chat/stream-chat-form.tsx b/src/views/streams/stream/stream-chat/stream-chat-form.tsx index 8496809bd..91aac1f01 100644 --- a/src/views/streams/stream/stream-chat/stream-chat-form.tsx +++ b/src/views/streams/stream/stream-chat/stream-chat-form.tsx @@ -1,19 +1,18 @@ -import { useCallback, useMemo, useRef } from "react"; +import { useMemo, useRef } from "react"; import { Box, Button, Flex, useToast } from "@chakra-ui/react"; import { useForm } from "react-hook-form"; import { ParsedStream, buildChatMessage } from "../../../../helpers/nostr/stream"; import { unique } from "../../../../helpers/array"; -import { useSigningContext } from "../../../../providers/global/signing-provider"; import { createEmojiTags, ensureNotifyContentMentions } from "../../../../helpers/nostr/post"; import { useContextEmojis } from "../../../../providers/global/emoji-provider"; import { MagicInput, RefType } from "../../../../components/magic-textarea"; import StreamZapButton from "../../components/stream-zap-button"; -import { nostrBuildUploadImage } from "../../../../helpers/media-upload/nostr-build"; import { useUserInbox } from "../../../../hooks/use-user-mailboxes"; import { usePublishEvent } from "../../../../providers/global/publish-provider"; import { useReadRelays } from "../../../../hooks/use-client-relays"; import { useAdditionalRelayContext } from "../../../../providers/local/additional-relay-context"; +import { useTextAreaUploadFileWithForm } from "../../../../hooks/use-textarea-upload-file"; export default function ChatMessageForm({ stream, hideZapButton }: { stream: ParsedStream; hideZapButton?: boolean }) { const toast = useToast(); @@ -24,7 +23,6 @@ export default function ChatMessageForm({ stream, hideZapButton }: { stream: Par const relays = useMemo(() => unique([...streamRelays, ...hostReadRelays]), [hostReadRelays, streamRelays]); - const { requestSignature } = useSigningContext(); const { setValue, handleSubmit, formState, reset, getValues, watch } = useForm({ defaultValues: { content: "" }, }); @@ -37,25 +35,7 @@ export default function ChatMessageForm({ stream, hideZapButton }: { stream: Par }); const textAreaRef = useRef(null); - const uploadImage = useCallback( - async (imageFile: File) => { - try { - if (!imageFile.type.includes("image")) throw new Error("Only images are supported"); - - const response = await nostrBuildUploadImage(imageFile, requestSignature); - const imageUrl = response.url; - - const content = getValues().content; - const position = textAreaRef.current?.getCaretPosition(); - if (position !== undefined) { - setValue("content", content.slice(0, position) + imageUrl + content.slice(position), { shouldDirty: true }); - } else setValue("content", content + imageUrl, { shouldDirty: true }); - } catch (e) { - if (e instanceof Error) toast({ description: e.message, status: "error" }); - } - }, - [setValue, getValues], - ); + const { onPaste } = useTextAreaUploadFileWithForm(textAreaRef, getValues, setValue); watch("content"); @@ -70,10 +50,8 @@ export default function ChatMessageForm({ stream, hideZapButton }: { stream: Par isRequired value={getValues().content} onChange={(e) => setValue("content", e.target.value, { shouldDirty: true })} - onPaste={(e) => { - const file = Array.from(e.clipboardData.files).find((f) => f.type.includes("image")); - if (file) uploadImage(file); - }} + // @ts-expect-error + onPaste={onPaste} />