Add session delete button

This commit is contained in:
Alexej Wolff
2026-02-11 21:12:58 +01:00
parent c1fe0eaeba
commit 1a3f9af9c3
2 changed files with 46 additions and 0 deletions
+31
View File
@@ -8,6 +8,7 @@ import {
getSession,
createSession,
saveSession as apiSaveSession,
deleteSession,
getPlayerCharacter,
type SessionListItem,
} from "../services/api";
@@ -661,6 +662,24 @@ export default function GamePage() {
setIsInitialLoading(false);
};
const handleDeleteSession = async (sessionId: string, sessionName: string) => {
if (!id) return;
const confirmed = confirm(`Удалить сессию "${sessionName}"?`);
if (!confirmed) return;
const success = await deleteSession(id, sessionId);
if (success) {
const newList = sessionsList.filter((s) => s.id !== sessionId);
setSessionsList(newList);
// Если удалили текущую сессию — переключаемся на первую оставшуюся
if (sessionId === currentSessionId && newList.length > 0) {
handleSwitchSession(newList[0].id);
}
}
};
const currentSessionName =
sessionsList.find((s) => s.id === currentSessionId)?.name || "Сессия";
@@ -729,6 +748,18 @@ export default function GamePage() {
{s.messagesCount} сообщ.
</span>
</button>
{sessionsList.length > 1 && (
<button
className="session-delete-btn"
onClick={(e) => {
e.stopPropagation();
handleDeleteSession(s.id, s.name);
}}
title="Удалить сессию"
>
🗑
</button>
)}
</div>
))}
</div>