Add session delete button
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user