diff --git a/src/pages/GamePage.css b/src/pages/GamePage.css index 79f9145..ce97a1f 100644 --- a/src/pages/GamePage.css +++ b/src/pages/GamePage.css @@ -190,6 +190,21 @@ 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 { font-size: 0.8rem; color: #666; diff --git a/src/pages/GamePage.tsx b/src/pages/GamePage.tsx index 9f711f3..b5b1bc9 100644 --- a/src/pages/GamePage.tsx +++ b/src/pages/GamePage.tsx @@ -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} сообщ. + {sessionsList.length > 1 && ( + + )} ))}