11import { motion } from 'motion/react'
2- import { useRef } from 'react'
2+ import { useRef , useState } from 'react'
33import { toast } from 'sonner'
44import { useRouter } from 'next/navigation'
55import { useWriteStore } from '../stores/write-store'
@@ -12,6 +12,7 @@ export function WriteActions() {
1212 const { openPreview } = usePreviewStore ( )
1313 const { isAuth, onPublish, onDelete } = usePublish ( )
1414 const mdInputRef = useRef < HTMLInputElement > ( null )
15+ const [ confirmingDelete , setConfirmingDelete ] = useState ( false )
1516 const router = useRouter ( )
1617
1718 const handleImportOrPublish = ( ) => {
@@ -23,9 +24,6 @@ export function WriteActions() {
2324 }
2425
2526 const handleCancel = ( ) => {
26- if ( ! window . confirm ( '放弃本次修改吗?' ) ) {
27- return
28- }
2927 const target = mode === 'edit' && originalSlug ? `/blog/${ originalSlug } ` : '/'
3028 router . push ( target )
3129 window . setTimeout ( ( ) => {
@@ -40,10 +38,7 @@ export function WriteActions() {
4038 toast . info ( '请先登录管理员密码' )
4139 return
4240 }
43- const confirmMsg = form ?. title ? `确定删除《${ form . title } 》吗?该操作不可恢复。` : '确定删除当前文章吗?该操作不可恢复。'
44- if ( window . confirm ( confirmMsg ) ) {
45- onDelete ( )
46- }
41+ setConfirmingDelete ( true )
4742 }
4843
4944 const handleImportMd = ( ) => {
@@ -79,27 +74,35 @@ export function WriteActions() {
7974 < div className = 'rounded-lg border bg-blue-50 px-4 py-2 text-sm text-blue-700' > 编辑模式</ div >
8075 </ motion . div >
8176
82- < motion . button
77+ < button
8378 type = 'button'
84- initial = { { opacity : 0 , scale : 0.6 } }
85- animate = { { opacity : 1 , scale : 1 } }
86- whileHover = { { scale : 1.05 } }
87- whileTap = { { scale : 0.95 } }
88- className = 'rounded-xl border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-600 transition-colors hover:bg-red-100'
79+ className = 'rounded-xl border border-red-200 bg-red-50 px-4 py-2 text-sm text-red-600 transition-colors hover:bg-red-100 disabled:opacity-60'
8980 disabled = { loading }
81+ onPointerDown = { e => e . stopPropagation ( ) }
9082 onClick = { handleDelete } >
9183 删除
92- </ motion . button >
84+ </ button >
9385
94- < motion . button
86+ < button
9587 type = 'button'
96- whileHover = { { scale : 1.05 } }
97- whileTap = { { scale : 0.95 } }
9888 onClick = { handleCancel }
9989 disabled = { loading }
100- className = 'bg-card rounded-xl border px-4 py-2 text-sm' >
90+ onPointerDown = { e => e . stopPropagation ( ) }
91+ className = 'bg-card rounded-xl border px-4 py-2 text-sm disabled:opacity-60' >
10192 取消
102- </ motion . button >
93+ </ button >
94+
95+ { confirmingDelete && (
96+ < div className = 'flex items-center gap-2 rounded-xl border border-red-200 bg-white/95 px-3 py-2 text-sm shadow-sm backdrop-blur' >
97+ < span className = 'text-red-600' > { form ?. title ? `确认删除《${ form . title } 》?` : '确认删除?' } </ span >
98+ < button type = 'button' className = 'rounded-lg bg-red-500 px-3 py-1 text-white' disabled = { loading } onClick = { onDelete } >
99+ 确认
100+ </ button >
101+ < button type = 'button' className = 'rounded-lg border px-3 py-1' disabled = { loading } onClick = { ( ) => setConfirmingDelete ( false ) } >
102+ 取消
103+ </ button >
104+ </ div >
105+ ) }
103106 </ >
104107 ) }
105108
0 commit comments