优化体验
This commit is contained in:
parent
c3456dea16
commit
1ac8f26334
@ -161,6 +161,9 @@ export function EditorToolbar({
|
||||
{isDraft && (
|
||||
<span className="text-sm text-muted-foreground">未保存</span>
|
||||
)}
|
||||
{!isDraft && (
|
||||
<span className="text-sm text-muted-foreground">已保存</span>
|
||||
)}
|
||||
<button
|
||||
onClick={onSave}
|
||||
className={cn(
|
||||
|
@ -1,9 +1,7 @@
|
||||
import { useCallback, useEffect, useRef } from 'react'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { AUTO_SAVE_DELAY } from '../constants'
|
||||
|
||||
export function useAutoSave(value: string, setIsDraft: (isDraft: boolean) => void) {
|
||||
const { toast } = useToast()
|
||||
const autoSaveTimerRef = useRef<NodeJS.Timeout>()
|
||||
|
||||
const handleEditorChange = useCallback((v: string) => {
|
||||
@ -17,12 +15,9 @@ export function useAutoSave(value: string, setIsDraft: (isDraft: boolean) => voi
|
||||
// 设置新的自动保存定时器
|
||||
autoSaveTimerRef.current = setTimeout(() => {
|
||||
localStorage.setItem('wechat_editor_draft', v)
|
||||
toast({
|
||||
description: "内容已自动保存",
|
||||
duration: 2000
|
||||
})
|
||||
setIsDraft(false)
|
||||
}, AUTO_SAVE_DELAY)
|
||||
}, [toast, setIsDraft])
|
||||
}, [setIsDraft])
|
||||
|
||||
// 清理自动保存定时器
|
||||
useEffect(() => {
|
||||
|
Loading…
Reference in New Issue
Block a user