Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/ar/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"close": "إغلاق",
"roomActions": "إجراءات المحادثة"
},
"deleteConfirm": {
"title": "حذف المحادثة",
"description": "هل أنت متأكد أنك تريد حذف \"{{name}}\"؟ لا يمكن التراجع عن هذا الإجراء.",
"cancel": "إلغاء",
"confirm": "حذف"
},
"toasts": {
"failedToPin": "فشل تثبيت الغرفة",
"failedToUnpin": "فشل إلغاء تثبيت الغرفة",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/en/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/es/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/fr/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/hi/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"close": "बंद करें",
"roomActions": "चैट कार्रवाइयाँ"
},
"deleteConfirm": {
"title": "चैट हटाएं",
"description": "क्या आप वाकई \"{{name}}\" को हटाना चाहते हैं? यह क्रिया पूर्ववत नहीं की जा सकती।",
"cancel": "रद्द करें",
"confirm": "हटाएं"
},
"toasts": {
"failedToPin": "रूम पिन करने में विफल",
"failedToUnpin": "रूम अनपिन करने में विफल",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/ja/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@
"close": "閉じる",
"roomActions": "チャットの操作"
},
"deleteConfirm": {
"title": "チャットを削除",
"description": "「{{name}}」を削除してもよろしいですか?この操作は元に戻せません。",
"cancel": "キャンセル",
"confirm": "削除"
},
"toasts": {
"failedToPin": "ルームの固定に失敗しました",
"failedToUnpin": "ルームの固定解除に失敗しました",
Expand Down
6 changes: 6 additions & 0 deletions libs/i18n/src/resources/locales/nl/playground/sidebar.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
136 changes: 71 additions & 65 deletions packages/playground/src/components/common/global-nav.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ import {
CollapsibleContent,
CollapsibleTrigger,
cn,
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
Expand Down Expand Up @@ -154,6 +160,7 @@ export const GlobalNav = observer(() => {
const [editingRoomId, setEditingRoomId] = useState<string | null>(null);

const [deletedSet, setDeletedSet] = useState(new Set<string>());
const [deleteRoomId, setDeleteRoomId] = useState<string | null>(null);

const navigate = useNavigate();

Expand Down Expand Up @@ -871,74 +878,13 @@ export const GlobalNav = observer(() => {
)}
</DropdownMenuItem>
<DropdownMenuItem
onClick={async (
onClick={(
e,
) => {
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"
>
Expand Down Expand Up @@ -1028,6 +974,66 @@ export const GlobalNav = observer(() => {
if (!open) setDownloadRoomId(null);
}}
/>
<Dialog
open={deleteRoomId !== null}
onOpenChange={(open) => {
if (!open) setDeleteRoomId(null);
}}
>
<DialogContent>
<DialogHeader>
<DialogTitle>{t("deleteConfirm.title")}</DialogTitle>
<DialogDescription>
{t("deleteConfirm.description", {
name:
getRooms.data.find(
(r) => r.ROOM_ID === deleteRoomId,
)?.ROOM_NAME ?? t("messages.untitled"),
})}
</DialogDescription>
</DialogHeader>
<DialogFooter>
<Button
variant="outline"
onClick={() => setDeleteRoomId(null)}
>
{t("deleteConfirm.cancel")}
</Button>
<Button
variant="destructive"
onClick={async () => {
const roomId = deleteRoomId;
if (!roomId) return;
setDeleteRoomId(null);
try {
setDeletedSet(
(prev) => new Set([...prev, roomId]),
);
await chat.closeRoom(roomId);
toast.success(
t("toasts.roomDeletedSuccess"),
);
if (activeRoomId === roomId) {
navigate("/");
}
getRooms.reset();
} catch (e) {
if (e instanceof Error) {
toast.error(e.message);
}
setDeletedSet((prev) => {
const newSet = new Set(prev);
newSet.delete(roomId);
return newSet;
});
}
}}
>
{t("deleteConfirm.confirm")}
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</>
);
});
Loading