Fix richiesta apertura sessione

This commit is contained in:
Samuele E. Locatelli
2025-09-03 12:26:32 +00:00
parent 676ece22a1
commit ab4c490e86
3 changed files with 37 additions and 1 deletions
+7 -1
View File
@@ -4,6 +4,7 @@ import ChatHeader from "./ChatHeader";
import ChatWindow from "./ChatWindow";
import ChatInput from "./ChatInput";
import SessionTable from "./SessionTable";
import NoSessionBox from './NoSessionBox';
export default function ChatLayout({
theme,
@@ -75,7 +76,12 @@ export default function ChatLayout({
</div>
)}
<ChatInput onSend={onSend} loading={loading} />
{/* Se non c'è sessionId, mostra il box per crearne una */}
{sessionId ? (
<ChatInput onSend={onSend} onStop={onStop} loading={loading} />
) : (
<NoSessionBox onCreateSession={onCreateSession} />
)}
</div>
<div
+25
View File
@@ -0,0 +1,25 @@
// srv/NoSessionBox.jsx
import React from "react";
export default function NoSessionBox({ onCreateSession }) {
return (
<div
className="d-flex flex-column align-items-center justify-content-center text-center p-4"
style={{ height: "100%", minHeight: "200px" }}
>
<h5 className="mb-3">Nessuna sessione attiva</h5>
<p className="text-muted mb-4" style={{ maxWidth: "400px" }}>
Per iniziare una nuova conversazione, crea una sessione.
Potrai poi inviare messaggi e salvare la cronologia.
</p>
<button
className="btn btn-success"
onClick={onCreateSession}
title="Crea una nuova sessione"
>
Crea nuova sessione
</button>
</div>
);
}
+5
View File
@@ -9,6 +9,11 @@ export function getUserId() {
}
export function getSessionId() {
// Legge sempre da localStorage
return localStorage.getItem("sessionId") || null;
}
export function getSessionIdForced() {
// Always reread localStorage so latest value is returned
let id = localStorage.getItem("sessionId");
if (!id) {