Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
molvqingtai committed Oct 31, 2024
2 parents 78e1cd7 + ebd22bc commit 94c927c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/app/content/components/MessageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { forwardRef, type ChangeEvent, CompositionEvent, type KeyboardEvent } from 'react'
import { forwardRef, type ChangeEvent, CompositionEvent, type KeyboardEvent, ClipboardEvent } from 'react'

import { cn } from '@/utils'
import { Textarea } from '@/components/ui/Textarea'
Expand All @@ -14,6 +14,7 @@ export interface MessageInputProps {
disabled?: boolean
loading?: boolean
onInput?: (e: ChangeEvent<HTMLTextAreaElement>) => void
onPaste?: (e: ClipboardEvent<HTMLTextAreaElement>) => void
onKeyDown?: (e: KeyboardEvent<HTMLTextAreaElement>) => void
onCompositionStart?: (e: CompositionEvent<HTMLTextAreaElement>) => void
onCompositionEnd?: (e: CompositionEvent<HTMLTextAreaElement>) => void
Expand All @@ -31,6 +32,7 @@ const MessageInput = forwardRef<HTMLTextAreaElement, MessageInputProps>(
className,
maxLength = 500,
onInput,
onPaste,
onKeyDown,
onCompositionStart,
onCompositionEnd,
Expand All @@ -45,6 +47,7 @@ const MessageInput = forwardRef<HTMLTextAreaElement, MessageInputProps>(
<ScrollArea className="box-border max-h-28 w-full rounded-lg border border-input bg-background ring-offset-background focus-within:ring-1 focus-within:ring-ring 2xl:max-h-40">
<Textarea
ref={ref}
onPaste={onPaste}
onKeyDown={onKeyDown}
autoFocus={autoFocus}
maxLength={maxLength}
Expand Down
10 changes: 9 additions & 1 deletion src/app/content/views/Footer/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeEvent, useMemo, useRef, useState, KeyboardEvent, type FC } from 'react'
import { ChangeEvent, useMemo, useRef, useState, KeyboardEvent, type FC, ClipboardEvent } from 'react'
import { CornerDownLeftIcon } from 'lucide-react'
import { useRemeshDomain, useRemeshQuery, useRemeshSend } from 'remesh-react'
import MessageInput from '../../components/MessageInput'
Expand Down Expand Up @@ -216,6 +216,13 @@ const Footer: FC = () => {
send(messageInputDomain.command.InputCommand(currentMessage))
}

const handlePaste = async (e: ClipboardEvent<HTMLTextAreaElement>) => {
const file = e.nativeEvent.clipboardData?.files[0]
if (['image/png', 'image/jpeg', 'image/webp'].includes(file?.type ?? '')) {
handleInjectImage(file!)
}
}

const handleInjectEmoji = (emoji: string) => {
const newMessage = `${message.slice(0, selectionEnd)}${emoji}${message.slice(selectionEnd)}`

Expand Down Expand Up @@ -335,6 +342,7 @@ const Footer: FC = () => {
value={message}
onInput={handleInput}
loading={inputLoading}
onPaste={handlePaste}
onKeyDown={handleKeyDown}
maxLength={MESSAGE_MAX_LENGTH}
></MessageInput>
Expand Down

0 comments on commit 94c927c

Please sign in to comment.