From 62535e1e100adec1f77dc8f603b7d6db3c95b223 Mon Sep 17 00:00:00 2001 From: Eugene Kim Date: Wed, 25 Nov 2026 10:30:01 -0500 Subject: [PATCH] feat: add delete dialog to chat history --- .../locales/ar/playground/sidebar.json | 6 + .../locales/en/playground/sidebar.json | 6 + .../locales/es/playground/sidebar.json | 6 + .../locales/fr/playground/sidebar.json | 6 + .../locales/hi/playground/sidebar.json | 6 + .../locales/ja/playground/sidebar.json | 6 + .../locales/nl/playground/sidebar.json | 6 + .../src/components/common/global-nav.tsx | 136 +++++++++--------- 8 files changed, 113 insertions(+), 65 deletions(-) diff --git a/libs/i18n/src/resources/locales/ar/playground/sidebar.json b/libs/i18n/src/resources/locales/ar/playground/sidebar.json index bc6a731783..d4928bbd67 100644 --- a/libs/i18n/src/resources/locales/ar/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/ar/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "إغلاق", "roomActions": "إجراءات المحادثة" }, + "deleteConfirm": { + "title": "حذف المحادثة", + "description": "هل أنت متأكد أنك تريد حذف \"{{name}}\"؟ لا يمكن التراجع عن هذا الإجراء.", + "cancel": "إلغاء", + "confirm": "حذف" + }, "toasts": { "failedToPin": "فشل تثبيت الغرفة", "failedToUnpin": "فشل إلغاء تثبيت الغرفة", diff --git a/libs/i18n/src/resources/locales/en/playground/sidebar.json b/libs/i18n/src/resources/locales/en/playground/sidebar.json index 7b42b40062..5ba7343f50 100644 --- a/libs/i18n/src/resources/locales/en/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/en/playground/sidebar.json @@ -53,6 +53,12 @@ "close": "Close", "roomActions": "Room actions" }, + "deleteConfirm": { + "title": "Delete chat", + "description": "Are you sure you want to delete \"{{name}}\"? This action cannot be undone.", + "cancel": "Cancel", + "confirm": "Delete" + }, "toasts": { "failedToPin": "Could not add the room to favorites", "failedToUnpin": "Could not remove the room from favorites", diff --git a/libs/i18n/src/resources/locales/es/playground/sidebar.json b/libs/i18n/src/resources/locales/es/playground/sidebar.json index 0abbd4b945..cf2d844488 100644 --- a/libs/i18n/src/resources/locales/es/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/es/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "Cerrar", "roomActions": "Acciones del chat" }, + "deleteConfirm": { + "title": "Eliminar chat", + "description": "¿Estás seguro de que quieres eliminar \"{{name}}\"? Esta acción no se puede deshacer.", + "cancel": "Cancelar", + "confirm": "Eliminar" + }, "toasts": { "failedToPin": "Error al fijar la sala", "failedToUnpin": "Error al desfijar la sala", diff --git a/libs/i18n/src/resources/locales/fr/playground/sidebar.json b/libs/i18n/src/resources/locales/fr/playground/sidebar.json index 1a3310dcfe..851f787f2a 100644 --- a/libs/i18n/src/resources/locales/fr/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/fr/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "Fermer", "roomActions": "Actions de la discussion" }, + "deleteConfirm": { + "title": "Supprimer le chat", + "description": "Êtes-vous sûr de vouloir supprimer \"{{name}}\" ? Cette action est irréversible.", + "cancel": "Annuler", + "confirm": "Supprimer" + }, "toasts": { "failedToPin": "Échec de l'épinglage de la salle", "failedToUnpin": "Échec du désépinglage de la salle", diff --git a/libs/i18n/src/resources/locales/hi/playground/sidebar.json b/libs/i18n/src/resources/locales/hi/playground/sidebar.json index a319c87215..f7ef2a8713 100644 --- a/libs/i18n/src/resources/locales/hi/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/hi/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "बंद करें", "roomActions": "चैट कार्रवाइयाँ" }, + "deleteConfirm": { + "title": "चैट हटाएं", + "description": "क्या आप वाकई \"{{name}}\" को हटाना चाहते हैं? यह क्रिया पूर्ववत नहीं की जा सकती।", + "cancel": "रद्द करें", + "confirm": "हटाएं" + }, "toasts": { "failedToPin": "रूम पिन करने में विफल", "failedToUnpin": "रूम अनपिन करने में विफल", diff --git a/libs/i18n/src/resources/locales/ja/playground/sidebar.json b/libs/i18n/src/resources/locales/ja/playground/sidebar.json index 40cf5fe316..496537a0e5 100644 --- a/libs/i18n/src/resources/locales/ja/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/ja/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "閉じる", "roomActions": "チャットの操作" }, + "deleteConfirm": { + "title": "チャットを削除", + "description": "「{{name}}」を削除してもよろしいですか?この操作は元に戻せません。", + "cancel": "キャンセル", + "confirm": "削除" + }, "toasts": { "failedToPin": "ルームの固定に失敗しました", "failedToUnpin": "ルームの固定解除に失敗しました", diff --git a/libs/i18n/src/resources/locales/nl/playground/sidebar.json b/libs/i18n/src/resources/locales/nl/playground/sidebar.json index a8f0d0ce31..2cd955f1ae 100644 --- a/libs/i18n/src/resources/locales/nl/playground/sidebar.json +++ b/libs/i18n/src/resources/locales/nl/playground/sidebar.json @@ -52,6 +52,12 @@ "close": "Sluiten", "roomActions": "Chatacties" }, + "deleteConfirm": { + "title": "Chat verwijderen", + "description": "Weet je zeker dat je \"{{name}}\" wilt verwijderen? Deze actie kan niet ongedaan worden gemaakt.", + "cancel": "Annuleren", + "confirm": "Verwijderen" + }, "toasts": { "failedToPin": "Vastmaken van ruimte mislukt", "failedToUnpin": "Losmaken van ruimte mislukt", diff --git a/packages/playground/src/components/common/global-nav.tsx b/packages/playground/src/components/common/global-nav.tsx index 1607322af9..119af6dc16 100644 --- a/packages/playground/src/components/common/global-nav.tsx +++ b/packages/playground/src/components/common/global-nav.tsx @@ -27,6 +27,12 @@ import { CollapsibleContent, CollapsibleTrigger, cn, + Dialog, + DialogContent, + DialogDescription, + DialogFooter, + DialogHeader, + DialogTitle, DropdownMenu, DropdownMenuContent, DropdownMenuItem, @@ -154,6 +160,7 @@ export const GlobalNav = observer(() => { const [editingRoomId, setEditingRoomId] = useState(null); const [deletedSet, setDeletedSet] = useState(new Set()); + const [deleteRoomId, setDeleteRoomId] = useState(null); const navigate = useNavigate(); @@ -871,74 +878,13 @@ export const GlobalNav = observer(() => { )} { e.stopPropagation(); - - try { - // optimistically add to deleted set to remove from UI immediately - setDeletedSet( - ( - prev, - ) => - new Set( - [ - ...prev, - roomId, - ], - ), - ); - - await chat.closeRoom( - roomId, - ); - - toast.success( - t( - "toasts.roomDeletedSuccess", - ), - ); - if ( - activeRoomId === - roomId - ) { - navigate( - "/", - ); - } - - // Refetch rooms after deletion - getRooms.reset(); - } catch (e) { - if ( - e instanceof - Error - ) { - toast.error( - e.message, - ); - } - // Deletion failed — restore the room in the list. - // On the success path we intentionally leave the - // roomId in deletedSet until the refetch lands, so - // the room doesn't briefly reappear between the - // reset() call and the new data arriving. - setDeletedSet( - ( - prev, - ) => { - const newSet = - new Set( - prev, - ); - newSet.delete( - roomId, - ); - return newSet; - }, - ); - } + setDeleteRoomId( + roomId, + ); }} className="text-destructive focus:text-destructive" > @@ -1028,6 +974,66 @@ export const GlobalNav = observer(() => { if (!open) setDownloadRoomId(null); }} /> + { + if (!open) setDeleteRoomId(null); + }} + > + + + {t("deleteConfirm.title")} + + {t("deleteConfirm.description", { + name: + getRooms.data.find( + (r) => r.ROOM_ID === deleteRoomId, + )?.ROOM_NAME ?? t("messages.untitled"), + })} + + + + + + + + ); });