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
+15
View File
@@ -190,6 +190,21 @@
opacity: 1; opacity: 1;
} }
.session-delete-btn {
background: none;
border: none;
padding: 0.5rem;
margin-right: 0.5rem;
font-size: 0.85rem;
cursor: pointer;
opacity: 0.4;
transition: opacity 0.2s;
}
.session-delete-btn:hover {
opacity: 1;
}
.header-protagonist { .header-protagonist {
font-size: 0.8rem; font-size: 0.8rem;
color: #666; color: #666;
+31
View File
@@ -8,6 +8,7 @@ import {
getSession, getSession,
createSession, createSession,
saveSession as apiSaveSession, saveSession as apiSaveSession,
deleteSession,
getPlayerCharacter, getPlayerCharacter,
type SessionListItem, type SessionListItem,
} from "../services/api"; } from "../services/api";
@@ -661,6 +662,24 @@ export default function GamePage() {
setIsInitialLoading(false); 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 = const currentSessionName =
sessionsList.find((s) => s.id === currentSessionId)?.name || "Сессия"; sessionsList.find((s) => s.id === currentSessionId)?.name || "Сессия";
@@ -729,6 +748,18 @@ export default function GamePage() {
{s.messagesCount} сообщ. {s.messagesCount} сообщ.
</span> </span>
</button> </button>
{sessionsList.length > 1 && (
<button
className="session-delete-btn"
onClick={(e) => {
e.stopPropagation();
handleDeleteSession(s.id, s.name);
}}
title="Удалить сессию"
>
🗑
</button>
)}
</div> </div>
))} ))}
</div> </div>