Mercurial Hosting > lang
comparison src/chats.html.luan @ 23:0c17c233c45a
start courses
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 30 Jul 2025 23:29:33 -0600 |
parents | f551d19da80d |
children | 87fe70201aa8 |
comparison
equal
deleted
inserted
replaced
22:7b35fb1e6603 | 23:0c17c233c45a |
---|---|
1 local Luan = require "luan:Luan.luan" | 1 local Luan = require "luan:Luan.luan" |
2 local error = Luan.error | 2 local error = Luan.error |
3 local ipairs = Luan.ipairs or error() | 3 local ipairs = Luan.ipairs or error() |
4 local pairs = Luan.pairs or error() | |
4 local Io = require "luan:Io.luan" | 5 local Io = require "luan:Io.luan" |
5 local Http = require "luan:http/Http.luan" | 6 local Http = require "luan:http/Http.luan" |
6 local Shared = require "site:/lib/Shared.luan" | 7 local Shared = require "site:/lib/Shared.luan" |
7 local head = Shared.head or error() | 8 local head = Shared.head or error() |
8 local header = Shared.header or error() | 9 local header = Shared.header or error() |
9 local User = require "site:/lib/User.luan" | 10 local User = require "site:/lib/User.luan" |
10 local current_user = User.current or error() | 11 local current_user = User.current or error() |
11 local Chat = require "site:/lib/Chat.luan" | 12 local Chat = require "site:/lib/Chat.luan" |
12 local chat_search = Chat.search or error() | 13 local chat_search = Chat.search or error() |
14 local languages = require "site:/lib/languages.luan" | |
15 local Logging = require "luan:logging/Logging.luan" | |
16 local logger = Logging.logger "chats.html" | |
13 | 17 |
14 | 18 |
15 return function() | 19 return function() |
16 local user = current_user() | 20 local user = current_user() |
17 if user == nil then | 21 if user == nil then |
18 Http.response.send_redirect("/login.html") | 22 Http.response.send_redirect("/login.html") |
19 return | 23 return |
20 end | 24 end |
21 local chats = chat_search( "chat_user_id:"..user.id, "chat_updated desc" ) | 25 local chats = chat_search( "chat_user_id:"..user.id, "chat_updated desc" ) |
26 local select_language = #chats > 0 and chats[1].language or nil | |
22 Io.stdout = Http.response.text_writer() | 27 Io.stdout = Http.response.text_writer() |
23 %> | 28 %> |
24 <!doctype html> | 29 <!doctype html> |
25 <html lang="en"> | 30 <html lang="en"> |
26 <head> | 31 <head> |
27 <% head() %> | 32 <% head() %> |
28 <style> | 33 <style> |
34 form { | |
35 margin-bottom: 20px; | |
36 } | |
29 td { | 37 td { |
30 padding: 8px 8px; | 38 padding: 8px 8px; |
31 } | 39 } |
32 </style> | 40 </style> |
33 </head> | 41 </head> |
34 <body> | 42 <body> |
35 <% header() %> | 43 <% header() %> |
36 <div content> | 44 <div content> |
37 <h1>Your Chats</h1> | 45 <h1>Your Chats</h1> |
38 <p><a href="new_chat.red">new chat</a></p> | 46 <form action="new_chat.red"> |
47 <select name=language> | |
48 <% for _, lang in pairs(languages) do | |
49 local code = lang.code | |
50 local selected = code==select_language and "selected" or "" | |
51 %> | |
52 <option value="<%=code%>" <%=selected%> ><%=lang.name%></option> | |
53 <% end %> | |
54 </select> | |
55 <input type=submit value="new chat"> | |
56 </form> | |
39 <table> | 57 <table> |
40 <% for _, chat in ipairs(chats) do %> | 58 <% for _, chat in ipairs(chats) do %> |
41 <tr> | 59 <tr> |
42 <td><%= chat.language_name() %></td> | 60 <td><%= chat.language_name() %></td> |
43 <td><a href="chat.html?chat=<%=chat.id%>"><%= chat.name_html() %></a></td> | 61 <td><a href="chat.html?chat=<%=chat.id%>"><%= chat.name_html() %></a></td> |