mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-08-28 05:25:33 +00:00
fix vorflux comments
This commit is contained in:
parent
4873082d7c
commit
2828978dff
6 changed files with 58 additions and 38 deletions
|
|
@ -20,11 +20,9 @@ export function NoteContent({
|
|||
const [content, setContent] = useState(initialContent ?? "")
|
||||
const [seededContent] = useState(initialContent || undefined)
|
||||
|
||||
const canSubmit = content.trim().length > 0 && !isSubmitting
|
||||
|
||||
const handleSubmit = () => {
|
||||
if (canSubmit && onSubmit) {
|
||||
onSubmit(content)
|
||||
const handleSubmit = (submittedContent = content) => {
|
||||
if (submittedContent.trim() && !isSubmitting && onSubmit) {
|
||||
onSubmit(submittedContent)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ export interface TextEditorProps {
|
|||
hasUnsavedChanges: boolean
|
||||
isSaving: boolean
|
||||
onContentChange: (content: string) => void
|
||||
onSave: () => void
|
||||
onSave: (content?: string) => void
|
||||
onReset: () => void
|
||||
}
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ export function TextEditorContent({
|
|||
<Button
|
||||
variant="insideOut"
|
||||
size="sm"
|
||||
onClick={onSave}
|
||||
onClick={() => onSave()}
|
||||
disabled={isSaving}
|
||||
className="hover:text-white rounded-full px-4"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -236,10 +236,11 @@ export function DocumentModal({
|
|||
draftContentString !== initialEditorString &&
|
||||
draftContentString !== lastSavedContent
|
||||
|
||||
const handleSave = useCallback(() => {
|
||||
const handleSave = useCallback((submittedContent?: string) => {
|
||||
if (!_document?.id) return
|
||||
const content = submittedContent ?? draftContentString
|
||||
updateMutation.mutate(
|
||||
{ documentId: _document.id, content: draftContentString },
|
||||
{ documentId: _document.id, content },
|
||||
{
|
||||
onSuccess: (_data, variables) => setLastSavedContent(variables.content),
|
||||
},
|
||||
|
|
|
|||
|
|
@ -52,12 +52,15 @@ export function FullscreenNoteModal({
|
|||
""
|
||||
const userName = displayName ? `${displayName.split(" ")[0]}'s` : "My"
|
||||
|
||||
const handleSave = useCallback(() => {
|
||||
const currentContent = contentRef.current
|
||||
if (currentContent.trim() && !isSaving) {
|
||||
onSave(currentContent)
|
||||
}
|
||||
}, [isSaving, onSave])
|
||||
const handleSave = useCallback(
|
||||
(submittedContent?: string) => {
|
||||
const currentContent = submittedContent ?? contentRef.current
|
||||
if (currentContent.trim() && !isSaving) {
|
||||
onSave(currentContent)
|
||||
}
|
||||
},
|
||||
[isSaving, onSave],
|
||||
)
|
||||
|
||||
const handleContentChange = useCallback(
|
||||
(newContent: string) => {
|
||||
|
|
@ -165,7 +168,7 @@ export function FullscreenNoteModal({
|
|||
>
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleSave}
|
||||
onClick={() => handleSave()}
|
||||
disabled={!canSave}
|
||||
className={cn(
|
||||
"bg-[#1B1F24] rounded-[8px] px-4 py-2.5 flex items-center justify-center gap-1.5 cursor-pointer disabled:cursor-not-allowed disabled:opacity-50",
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
"use client"
|
||||
|
||||
import { useRef, useCallback, useEffect, useState } from "react"
|
||||
import { useCallback, useEffect, useState } from "react"
|
||||
import { cn } from "@lib/utils"
|
||||
import { dmSansClassName } from "@/lib/fonts"
|
||||
import { Maximize2, Plus, Loader2 } from "lucide-react"
|
||||
|
|
@ -22,20 +22,20 @@ export function QuickNoteCard({
|
|||
const [isExpanded, setIsExpanded] = useState(false)
|
||||
const { selectedProject } = useProject()
|
||||
const { draft, setDraft } = useQuickNoteDraft(selectedProject)
|
||||
const draftRef = useRef(draft)
|
||||
draftRef.current = draft
|
||||
|
||||
const handleContentChange = useCallback(
|
||||
(content: string) => setDraft(content),
|
||||
[setDraft],
|
||||
)
|
||||
|
||||
const handleEditorSubmit = useCallback(() => {
|
||||
const currentDraft = draftRef.current
|
||||
if (currentDraft.trim() && !isSaving) {
|
||||
onSave(currentDraft)
|
||||
}
|
||||
}, [isSaving, onSave])
|
||||
const handleEditorSubmit = useCallback(
|
||||
(content: string) => {
|
||||
if (content.trim() && !isSaving) {
|
||||
onSave(content)
|
||||
}
|
||||
},
|
||||
[isSaving, onSave],
|
||||
)
|
||||
|
||||
const handleSaveClick = useCallback(() => {
|
||||
if (draft.trim() && !isSaving) {
|
||||
|
|
|
|||
|
|
@ -13,6 +13,11 @@ import { cn } from "@lib/utils"
|
|||
|
||||
const extensions = [...defaultExtensions, slashCommand, Markdown]
|
||||
|
||||
function getEditorMarkdown(editor: Editor) {
|
||||
const json = editor.getJSON()
|
||||
return editor.storage.markdown?.manager?.serialize(json) ?? ""
|
||||
}
|
||||
|
||||
export function TextEditor({
|
||||
content: initialContent,
|
||||
onContentChange,
|
||||
|
|
@ -22,7 +27,7 @@ export function TextEditor({
|
|||
}: {
|
||||
content: string | undefined
|
||||
onContentChange: (content: string) => void
|
||||
onSubmit: () => void
|
||||
onSubmit: (content: string) => void
|
||||
debounceMs?: number
|
||||
editable?: boolean
|
||||
}) {
|
||||
|
|
@ -30,6 +35,8 @@ export function TextEditor({
|
|||
const editorRef = useRef<Editor | null>(null)
|
||||
const onSubmitRef = useRef(onSubmit)
|
||||
const hasUserEditedRef = useRef(false)
|
||||
const lastAppliedContentRef = useRef(initialContent)
|
||||
const lastEmittedContentRef = useRef<string | undefined>(undefined)
|
||||
|
||||
useEffect(() => {
|
||||
onSubmitRef.current = onSubmit
|
||||
|
|
@ -37,8 +44,8 @@ export function TextEditor({
|
|||
|
||||
const debouncedUpdates = useDebouncedCallback((editor: Editor) => {
|
||||
if (!hasUserEditedRef.current) return
|
||||
const json = editor.getJSON()
|
||||
const markdown = editor.storage.markdown?.manager?.serialize(json) ?? ""
|
||||
const markdown = getEditorMarkdown(editor)
|
||||
lastEmittedContentRef.current = markdown
|
||||
onContentChange?.(markdown)
|
||||
}, debounceMs)
|
||||
|
||||
|
|
@ -55,8 +62,8 @@ export function TextEditor({
|
|||
editorRef.current = editor
|
||||
if (!hasUserEditedRef.current) return
|
||||
if (debounceMs === 0) {
|
||||
const json = editor.getJSON()
|
||||
const markdown = editor.storage.markdown?.manager?.serialize(json) ?? ""
|
||||
const markdown = getEditorMarkdown(editor)
|
||||
lastEmittedContentRef.current = markdown
|
||||
onContentChange?.(markdown)
|
||||
return
|
||||
}
|
||||
|
|
@ -67,7 +74,10 @@ export function TextEditor({
|
|||
if ((event.metaKey || event.ctrlKey) && event.key === "Enter") {
|
||||
event.preventDefault()
|
||||
debouncedUpdates.flush()
|
||||
onSubmitRef.current?.()
|
||||
const currentEditor = editorRef.current
|
||||
const markdown = currentEditor ? getEditorMarkdown(currentEditor) : ""
|
||||
lastEmittedContentRef.current = markdown
|
||||
onSubmitRef.current?.(markdown)
|
||||
return true
|
||||
}
|
||||
hasUserEditedRef.current = true
|
||||
|
|
@ -89,15 +99,23 @@ export function TextEditor({
|
|||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (editor && initialContent !== undefined) {
|
||||
const json = editor.getJSON()
|
||||
const currentContent =
|
||||
editor.storage.markdown?.manager?.serialize(json) ?? ""
|
||||
if (currentContent === initialContent) return
|
||||
if (!editor || initialContent === undefined) return
|
||||
if (initialContent === lastAppliedContentRef.current) return
|
||||
|
||||
hasUserEditedRef.current = false
|
||||
editor.commands.setContent(initialContent, { contentType: "markdown" })
|
||||
if (initialContent === lastEmittedContentRef.current) {
|
||||
lastAppliedContentRef.current = initialContent
|
||||
return
|
||||
}
|
||||
|
||||
const currentContent = getEditorMarkdown(editor)
|
||||
if (currentContent === initialContent) {
|
||||
lastAppliedContentRef.current = initialContent
|
||||
return
|
||||
}
|
||||
|
||||
hasUserEditedRef.current = false
|
||||
lastAppliedContentRef.current = initialContent
|
||||
editor.commands.setContent(initialContent, { contentType: "markdown" })
|
||||
}, [editor, initialContent])
|
||||
|
||||
useEffect(() => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue