diff src/chat.html.luan @ 4:b1adec083e44

chat work
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 08 Jul 2025 22:15:41 -0600
parents 78708fa556a0
children a970b7a01a74
line wrap: on
line diff
--- a/src/chat.html.luan	Tue Jul 08 16:02:29 2025 -0600
+++ b/src/chat.html.luan	Tue Jul 08 22:15:41 2025 -0600
@@ -5,41 +5,89 @@
 local Shared = require "site:/lib/Shared.luan"
 local head = Shared.head or error()
 local header = Shared.header or error()
+local started = Shared.started or error()
+local User = require "site:/lib/User.luan"
+local current_user = User.current or error()
+local Chat = require "site:/lib/Chat.luan"
+local get_chat_by_id = Chat.get_by_id or error()
 
 
-local function get_ai_thread(ai_key)
-	return "thread"
-end
-
 return function()
-	local ai_key = "whatever"
-	local thread = get_ai_thread(ai_key)
+	local user = current_user()
+	if user == nil then
+		Http.response.send_redirect("/login.html")
+		return
+	end
+	local chat_id = Http.request.parameters.chat
+	local chat
+	if chat_id ~= nil then
+		chat = get_chat_by_id(chat_id) or error()
+	else
+		chat = Chat.new{
+			user_id = user.id
+			name = "whatever"
+		}
+		chat.save()
+	end
 	Io.stdout = Http.response.text_writer()
 %>
 <!doctype html>
 <html lang="en">
 	<head>
 <%		head() %>
+		<style>
+			@import "/chat.css?s=<%=started%>";
+		</style>
+		<script>
+			let chatId = <%=chat_id%>;
+		</script>
+		<script src="/chat.js?s=<%=started%>"></script>
 	</head>
 	<body>
 <%		header() %>
-		<div content>
-			<h1>Chat</h1>
-			<div ai_container="<%=ai_key%>" >
-				<div flex>
-					<div scroll>
-						<h2>Let's chat</h2>
-						<div messages>
-						</div>
+		<div content ai_container>
+			<div top>
+				<h3 name><%= chat.name_html() %></h3>
+				<span pulldown>
+					<img onclick="clickMenu(this)" src="/images/menu.svg">
+					<div>
+						<span onclick="renameChat()">Rename Chat</span>
+						<span onclick="deleteChat()">Delete Chat</span>
 					</div>
-					<div ask>
-						<textarea autofocus oninput="fixTextarea(event)" onkeydown="textareaKey('<%=ai_key%>',event)"></textarea>
-						<button onclick="askAi('<%=ai_key%>')" title="Send"><img src="/images/send.svg"></button>
-					</div>
+				</span>
+			</div>
+			<div scroll>
+				<div messages>
 				</div>
-				<img waiting-ai-icon src="/images/spinner_green.gif">
+			</div>
+			<div ask>
+				<textarea autofocus oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
+				<button onclick="askAi()" title="Send"><img src="/images/send.svg"></button>
 			</div>
+			<img waiting-ai-icon src="/images/spinner_green.gif">
 		</div>
+		<dialog rename>
+			<h2>Rename Chat</h2>
+			<form action="javascript:saveRenameChat()">
+				<p>
+					<label>Chat name</label><br> 
+					<input name=name required><br>
+					<span error></span>
+				</p>
+				<div buttons>
+					<button type=button onclick="closeModal(this)">Cancel</button>
+					<button type=submit>Rename</button>
+				</div>
+			</form>
+		</dialog>
+		<dialog delete>
+			<h2>Delete Chat</h2>
+			<p>Are you sure that you want to delete this chat?</p>
+			<div buttons>
+				<button onclick="closeModal(this)">Cancel</button>
+				<button onclick="doDeleteChat(this)">Delete</button>
+			</div>
+		</dialog>
 	</body>
 </html>
 <%