Skip to content

Commit 304d354

Browse files
committed
feat: add delete item info
1 parent 176bd1f commit 304d354

File tree

5 files changed

+37
-16
lines changed

5 files changed

+37
-16
lines changed

packages/markdown-editor/src/components/modal/delete-sortable-item-modal.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ import cn from 'clsx'
33
import { useModal } from '@/contexts/modal'
44
import { ModalWrapper } from './modal-wrapper'
55
import { X } from 'lucide-react'
6+
import { DeleteActionInfo, useSidebar } from '@/contexts/sidebar'
67

78
export const DeleteSortableItemModal: React.FC = () => {
89
const { onClose, mode, isOpen, setIsConfirm } = useModal()
10+
const { actionInfo } = useSidebar()
911

1012
const onCloseModal = () => {
1113
onClose()
@@ -15,13 +17,16 @@ export const DeleteSortableItemModal: React.FC = () => {
1517
setIsConfirm(true)
1618
}
1719

20+
if (!actionInfo) return null
21+
22+
const action = actionInfo as DeleteActionInfo
1823
const isVisible = isOpen && mode === 'deleteSortableItem'
1924
return (
2025
<ModalWrapper isVisible={isVisible} onOverlayClick={onClose}>
2126
<div
2227
className={cn(
23-
'nx-flex nx-w-[320px] nx-max-w-sm nx-flex-col nx-rounded-lg nx-bg-white nx-p-6 dark:nx-bg-gray-800',
24-
'nx-text-gray-900 dark:nx-text-gray-100',
28+
'nx-flex nx-w-[320px] nx-max-w-sm nx-select-none nx-flex-col nx-rounded-lg',
29+
'nx-bg-white nx-p-6 nx-text-gray-900 dark:nx-bg-gray-800 dark:nx-text-gray-100',
2530
isVisible ? 'popInFromBottom' : 'popOutToBottom',
2631
)}
2732
>
@@ -34,10 +39,13 @@ export const DeleteSortableItemModal: React.FC = () => {
3439
<X size={24} />
3540
</button>
3641
</div>
37-
<p className="nx-mb-6 nx-text-gray-600 dark:nx-text-gray-300">
38-
이 항목을 삭제하시겠습니까?
39-
</p>
40-
<div className="nx-flex nx-justify-end nx-space-x-4">
42+
<p className="nx-text-gray-600 dark:nx-text-gray-300">{`${action.title ?? '이'} 항목을 삭제하시겠습니까?`}</p>
43+
{action.childrenCount > 0 && (
44+
<p className="nx-mt-1 nx-text-sm nx-text-gray-600 dark:nx-text-gray-300">
45+
하위 항목도 모두 함께 삭제됩니다.
46+
</p>
47+
)}
48+
<div className="nx-mt-6 nx-flex nx-justify-end nx-space-x-4">
4149
<button
4250
onClick={onCloseModal}
4351
className="nx-rounded nx-bg-gray-200 nx-px-4 nx-py-2 nx-text-gray-600 hover:nx-bg-gray-300 dark:nx-bg-gray-700 dark:nx-text-gray-300 dark:hover:nx-bg-gray-600"

packages/markdown-editor/src/components/sidebar/sidebar-header/control-input.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export function ControlInput({ type }: Props): ReactElement {
2929
const forbiddenCharsRegex = /[<>#%"{}|\^~\[\]`\/:@=&+$,;!*()\\']/
3030
const typeName = nameMapper[type]
3131

32+
// validate title
3233
useEffect(() => {
3334
if (title === null || title === '') return
3435
if (forbiddenCharsRegex.test(title)) {
@@ -69,12 +70,14 @@ export function ControlInput({ type }: Props): ReactElement {
6970

7071
const dispatchEvent = useDebouncedCallback(
7172
useCallback(() => {
73+
if (type === '') return
74+
if (title === null) return
75+
if (title.trim() === '') return
76+
if (error) return
7277
if (sidebar.actionInfo === null) return
78+
7379
if (isAddAction(sidebar.actionInfo)) {
7480
const { parentUrlSlug, bookUrlSlug, index, type } = sidebar.actionInfo
75-
if (type === '') return
76-
if (!title) return
77-
if (error) return
7881
const event = new CustomEvent<CustomEventDetail['createItemEvent']>(
7982
nextraCustomEventName.createItemEvent,
8083
{
@@ -85,9 +88,6 @@ export function ControlInput({ type }: Props): ReactElement {
8588
}
8689

8790
if (isEditAction(sidebar.actionInfo)) {
88-
if (type === '') return
89-
if (title === null) return
90-
if (error) return
9191
const { pageUrlSlug } = sidebar.actionInfo
9292
const event = new CustomEvent<CustomEventDetail['updateItemEvent']>(
9393
nextraCustomEventName.updateItemEvent,
@@ -97,7 +97,7 @@ export function ControlInput({ type }: Props): ReactElement {
9797
)
9898
window.dispatchEvent(event)
9999
}
100-
}, [title, error, sidebar.actionInfo]),
100+
}, [title, error, sidebar.actionInfo, type]),
101101
1000,
102102
{ leading: true },
103103
)

packages/markdown-editor/src/components/sidebar/sortable-tree/sortable-item.tsx

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
8686
return
8787
}
8888

89-
// Check if the editing item is different
89+
// 이름 변경할 대상이 다른 아이템으로 변경 된 경우
9090
const editActionInfo = actionInfo as EditActionInfo
9191
if (editActionInfo.pageUrlSlug === item.urlSlug) return
9292
setIsEdit(false)
@@ -112,6 +112,11 @@ export const SortableItem = forwardRef<HTMLDivElement, SortableItemProps>((props
112112
onCloseMenu()
113113
setIsDeleteTarget(true)
114114
onOpenModal('deleteSortableItem')
115+
setActionInfo<'delete'>({
116+
action: 'delete',
117+
title: item.title,
118+
childrenCount: item.children.length,
119+
})
115120
}
116121

117122
const onEdit = () => {

packages/markdown-editor/src/contexts/sidebar.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ type ActionInfo<T = string> = T extends 'add'
55
? AddActionInfo
66
: T extends 'edit'
77
? EditActionInfo
8-
: null
8+
: T extends 'delete'
9+
? DeleteActionInfo
10+
: null
911

1012
export type AddActionInfo = {
1113
action: 'add'
@@ -21,6 +23,12 @@ export type EditActionInfo = {
2123
pageUrlSlug?: string
2224
}
2325

26+
export type DeleteActionInfo = {
27+
action: 'delete'
28+
title: string
29+
childrenCount: number
30+
}
31+
2432
export type PageType = 'folder' | 'page' | 'separator' | ''
2533

2634
type Sidebar = {

packages/markdown-editor/style.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)