aboutsummaryrefslogtreecommitdiff
path: root/apps/web/components/new/add-document/note.tsx
blob: 465e295a243fc8df22aac91fcb72ef22162b4a86 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"use client"

import { useState, useEffect } from "react"
import { useHotkeys } from "react-hotkeys-hook"

interface NoteContentProps {
	onSubmit?: (content: string) => void
	onContentChange?: (content: string) => void
	isSubmitting?: boolean
	isOpen?: boolean
}

export function NoteContent({
	onSubmit,
	onContentChange,
	isSubmitting,
	isOpen,
}: NoteContentProps) {
	const [content, setContent] = useState("")

	const canSubmit = content.trim().length > 0 && !isSubmitting

	const handleSubmit = () => {
		if (canSubmit && onSubmit) {
			onSubmit(content)
		}
	}

	const handleContentChange = (newContent: string) => {
		setContent(newContent)
		onContentChange?.(newContent)
	}

	useHotkeys("mod+enter", handleSubmit, {
		enabled: isOpen && canSubmit,
		enableOnFormTags: ["TEXTAREA"],
	})

	// Reset content when modal closes
	useEffect(() => {
		if (!isOpen) {
			setContent("")
			onContentChange?.("")
		}
	}, [isOpen, onContentChange])

	return (
		<textarea
			value={content}
			onChange={(e) => handleContentChange(e.target.value)}
			placeholder="Write your note here..."
			disabled={isSubmitting}
			className="w-full h-full p-4 mb-4! rounded-[14px] bg-[#14161A] shadow-inside-out resize-none disabled:opacity-50 outline-none"
		/>
	)
}