Skip to content

Commit 2107843

Browse files
authored
feat: Delete Page Confirmation (#809)
1 parent e1fced9 commit 2107843

11 files changed

Lines changed: 111 additions & 20 deletions

File tree

ui/components/Navigator.tsx

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ import { useHotkeys } from 'react-hotkeys-hook'
88
import { useTranslation } from 'react-i18next'
99

1010
import { PageManagerDialog } from '@/components/PageManagerDialog'
11+
import {
12+
AlertDialog,
13+
AlertDialogAction,
14+
AlertDialogCancel,
15+
AlertDialogContent,
16+
AlertDialogDescription,
17+
AlertDialogTitle,
18+
} from '@/components/ui/alert-dialog'
1119
import { Button } from '@/components/ui/button'
1220
import { ScrollArea } from '@/components/ui/scroll-area'
1321
import { useScene } from '@/hooks/useScene'
@@ -36,6 +44,12 @@ export function Navigator() {
3644
const viewportRef = useRef<HTMLDivElement | null>(null)
3745
const { t } = useTranslation()
3846
const [pageManagerOpen, setPageManagerOpen] = useState(false)
47+
const [pageToDeleteId, setPageToDeleteId] = useState<string | null>(null)
48+
49+
const pageToDeleteIndex = useMemo(() => {
50+
if (!pageToDeleteId) return -1
51+
return pages.findIndex((p) => p.id === pageToDeleteId)
52+
}, [pageToDeleteId, pages])
3953

4054
const handleSelect = useCallback(
4155
(id: string, event: React.MouseEvent | React.KeyboardEvent) => {
@@ -122,12 +136,9 @@ export function Navigator() {
122136
[pages, pagesMap, pageId, setPage, totalPages, t, setSelectedPageIds],
123137
)
124138

125-
const handleDeletePage = useCallback(
126-
(id: string) => {
127-
void handleDeletePages(new Set([id]))
128-
},
129-
[handleDeletePages],
130-
)
139+
const handleDeletePage = useCallback((id: string) => {
140+
setPageToDeleteId(id)
141+
}, [])
131142

132143
const handleBatchDelete = useCallback(() => {
133144
void handleDeletePages(selectedPageIds)
@@ -221,6 +232,36 @@ export function Navigator() {
221232
</ScrollArea>
222233

223234
<PageManagerDialog open={pageManagerOpen} onOpenChange={setPageManagerOpen} />
235+
236+
<AlertDialog
237+
open={!!pageToDeleteId}
238+
onOpenChange={(open) => !open && setPageToDeleteId(null)}
239+
>
240+
<AlertDialogContent>
241+
<div className='flex flex-col gap-1.5 text-center sm:text-left'>
242+
<AlertDialogTitle>{t('navigator.deleteConfirmTitle')}</AlertDialogTitle>
243+
<AlertDialogDescription>
244+
{t('navigator.deleteConfirmDescription', {
245+
index: pageToDeleteIndex + 1,
246+
})}
247+
</AlertDialogDescription>
248+
</div>
249+
<div className='flex flex-col-reverse gap-2 sm:flex-row sm:justify-end'>
250+
<AlertDialogCancel>{t('common.cancel', 'Cancel')}</AlertDialogCancel>
251+
<AlertDialogAction
252+
onClick={() => {
253+
if (pageToDeleteId) {
254+
void handleDeletePages(new Set([pageToDeleteId]))
255+
setPageToDeleteId(null)
256+
}
257+
}}
258+
className='text-destructive-foreground bg-destructive hover:bg-destructive/90'
259+
>
260+
{t('common.delete', 'Delete')}
261+
</AlertDialogAction>
262+
</div>
263+
</AlertDialogContent>
264+
</AlertDialog>
224265
</div>
225266
)
226267
}

ui/public/locales/en-US/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
"pages_other": "{{count}} pages",
101101
"empty": "No documents",
102102
"prompt": "Select or import a page to begin",
103+
"deleteConfirmTitle": "Delete Page",
104+
"deleteConfirmDescription": "Are you sure you want to delete page {{index}}? This action cannot be undone.",
103105
"pageManager": {
104106
"title": "Page Manager",
105107
"description": "Drag and drop pages to reorder them."

ui/public/locales/es-ES/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} páginas",
8484
"empty": "No hay documentos",
8585
"prompt": "Selecciona o importa una página para comenzar",
86+
"deleteConfirmTitle": "Eliminar página",
87+
"deleteConfirmDescription": "¿Está seguro de que desea eliminar la página {{index}}? Esta acción no se puede deshacer.",
8688
"pageManager": {
8789
"title": "Gestor de páginas",
8890
"description": "Arrastra y suelta las páginas para reordenarlas."

ui/public/locales/ja-JP/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} ページ",
8484
"empty": "ドキュメントがありません",
8585
"prompt": "ページを選択または読み込んで開始してください",
86+
"deleteConfirmTitle": "ページの削除",
87+
"deleteConfirmDescription": "ページ {{index}} を削除してもよろしいですか?この操作は取り消せません。",
8688
"pageManager": {
8789
"title": "ページ管理",
8890
"description": "ドラッグ&ドロップでページの順番を変更します。"

ui/public/locales/ko-KR/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@
8888
"pages_other": "{{count}} 페이지",
8989
"empty": "문서 없음",
9090
"prompt": "시작하려면 페이지를 선택하거나 가져오세요",
91+
"deleteConfirmTitle": "페이지 삭제",
92+
"deleteConfirmDescription": "페이지 {{index}}을(를) 삭제하시겠습니까? 이 작업은 되돌릴 수 없습니다.",
9193
"pageManager": {
9294
"title": "페이지 관리",
9395
"description": "드래그 앤 드롭으로 페이지 순서를 변경하세요."

ui/public/locales/pt-BR/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@
8484
"pages_other": "{{count}} páginas",
8585
"empty": "Nenhum documento",
8686
"prompt": "Selecione ou importe uma página para começar",
87+
"deleteConfirmTitle": "Excluir página",
88+
"deleteConfirmDescription": "Tem certeza de que deseja excluir a página {{index}}? Esta ação não pode ser desfeita.",
8789
"pageManager": {
8890
"title": "Gerenciador de páginas",
8991
"description": "Arraste e solte as páginas para reordená-las."

ui/public/locales/ru-RU/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} стр.",
8484
"empty": "Нет документов",
8585
"prompt": "Выберите или импортируйте страницу для начала",
86+
"deleteConfirmTitle": "Удалить страницу",
87+
"deleteConfirmDescription": "Вы уверены, что хотите удалить страницу {{index}}? Это действие невозможно отменить.",
8688
"pageManager": {
8789
"title": "Управление страницами",
8890
"description": "Перетащите страницы для изменения порядка."

ui/public/locales/tr-TR/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} sayfa",
8484
"empty": "Belge yok",
8585
"prompt": "Başlamak için bir sayfa seçin veya içe aktarın",
86+
"deleteConfirmTitle": "Sayfayı Sil",
87+
"deleteConfirmDescription": "Sayfa {{index}}'yi silmek istediğinizden emin misiniz? Bu işlem geri alınamaz.",
8688
"pageManager": {
8789
"title": "Sayfa Yöneticisi",
8890
"description": "Sayfaları yeniden sıralamak için sürükleyip bırakın."

ui/public/locales/zh-CN/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} 页",
8484
"empty": "没有文档",
8585
"prompt": "选择或导入页面开始",
86+
"deleteConfirmTitle": "删除页面",
87+
"deleteConfirmDescription": "您确定要删除第 {{index}} 页吗?此操作无法撤销。",
8688
"pageManager": {
8789
"title": "页面管理",
8890
"description": "拖放页面以重新排列顺序。"

ui/public/locales/zh-TW/translation.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,8 @@
8383
"pages_other": "{{count}} 頁",
8484
"empty": "沒有文件",
8585
"prompt": "選擇或匯入頁面以開始",
86+
"deleteConfirmTitle": "刪除頁面",
87+
"deleteConfirmDescription": "您確定要刪除第 {{index}} 頁嗎?此動作無法復原。",
8688
"pageManager": {
8789
"title": "頁面管理",
8890
"description": "拖放頁面以重新排列順序。"

0 commit comments

Comments
 (0)