Mercurial Hosting > lang
comparison 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 |
comparison
equal
deleted
inserted
replaced
3:eee6d4f59811 | 4:b1adec083e44 |
---|---|
3 local Io = require "luan:Io.luan" | 3 local Io = require "luan:Io.luan" |
4 local Http = require "luan:http/Http.luan" | 4 local Http = require "luan:http/Http.luan" |
5 local Shared = require "site:/lib/Shared.luan" | 5 local Shared = require "site:/lib/Shared.luan" |
6 local head = Shared.head or error() | 6 local head = Shared.head or error() |
7 local header = Shared.header or error() | 7 local header = Shared.header or error() |
8 local started = Shared.started or error() | |
9 local User = require "site:/lib/User.luan" | |
10 local current_user = User.current or error() | |
11 local Chat = require "site:/lib/Chat.luan" | |
12 local get_chat_by_id = Chat.get_by_id or error() | |
8 | 13 |
9 | 14 |
10 local function get_ai_thread(ai_key) | |
11 return "thread" | |
12 end | |
13 | |
14 return function() | 15 return function() |
15 local ai_key = "whatever" | 16 local user = current_user() |
16 local thread = get_ai_thread(ai_key) | 17 if user == nil then |
18 Http.response.send_redirect("/login.html") | |
19 return | |
20 end | |
21 local chat_id = Http.request.parameters.chat | |
22 local chat | |
23 if chat_id ~= nil then | |
24 chat = get_chat_by_id(chat_id) or error() | |
25 else | |
26 chat = Chat.new{ | |
27 user_id = user.id | |
28 name = "whatever" | |
29 } | |
30 chat.save() | |
31 end | |
17 Io.stdout = Http.response.text_writer() | 32 Io.stdout = Http.response.text_writer() |
18 %> | 33 %> |
19 <!doctype html> | 34 <!doctype html> |
20 <html lang="en"> | 35 <html lang="en"> |
21 <head> | 36 <head> |
22 <% head() %> | 37 <% head() %> |
38 <style> | |
39 @import "/chat.css?s=<%=started%>"; | |
40 </style> | |
41 <script> | |
42 let chatId = <%=chat_id%>; | |
43 </script> | |
44 <script src="/chat.js?s=<%=started%>"></script> | |
23 </head> | 45 </head> |
24 <body> | 46 <body> |
25 <% header() %> | 47 <% header() %> |
26 <div content> | 48 <div content ai_container> |
27 <h1>Chat</h1> | 49 <div top> |
28 <div ai_container="<%=ai_key%>" > | 50 <h3 name><%= chat.name_html() %></h3> |
29 <div flex> | 51 <span pulldown> |
30 <div scroll> | 52 <img onclick="clickMenu(this)" src="/images/menu.svg"> |
31 <h2>Let's chat</h2> | 53 <div> |
32 <div messages> | 54 <span onclick="renameChat()">Rename Chat</span> |
33 </div> | 55 <span onclick="deleteChat()">Delete Chat</span> |
34 </div> | 56 </div> |
35 <div ask> | 57 </span> |
36 <textarea autofocus oninput="fixTextarea(event)" onkeydown="textareaKey('<%=ai_key%>',event)"></textarea> | 58 </div> |
37 <button onclick="askAi('<%=ai_key%>')" title="Send"><img src="/images/send.svg"></button> | 59 <div scroll> |
38 </div> | 60 <div messages> |
39 </div> | 61 </div> |
40 <img waiting-ai-icon src="/images/spinner_green.gif"> | |
41 </div> | 62 </div> |
63 <div ask> | |
64 <textarea autofocus oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea> | |
65 <button onclick="askAi()" title="Send"><img src="/images/send.svg"></button> | |
66 </div> | |
67 <img waiting-ai-icon src="/images/spinner_green.gif"> | |
42 </div> | 68 </div> |
69 <dialog rename> | |
70 <h2>Rename Chat</h2> | |
71 <form action="javascript:saveRenameChat()"> | |
72 <p> | |
73 <label>Chat name</label><br> | |
74 <input name=name required><br> | |
75 <span error></span> | |
76 </p> | |
77 <div buttons> | |
78 <button type=button onclick="closeModal(this)">Cancel</button> | |
79 <button type=submit>Rename</button> | |
80 </div> | |
81 </form> | |
82 </dialog> | |
83 <dialog delete> | |
84 <h2>Delete Chat</h2> | |
85 <p>Are you sure that you want to delete this chat?</p> | |
86 <div buttons> | |
87 <button onclick="closeModal(this)">Cancel</button> | |
88 <button onclick="doDeleteChat(this)">Delete</button> | |
89 </div> | |
90 </dialog> | |
43 </body> | 91 </body> |
44 </html> | 92 </html> |
45 <% | 93 <% |
46 end | 94 end |