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