annotate src/get_chat.js.luan @ 34:62d04ca486dd

UI
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 12 Nov 2024 16:08:24 -0700
parents e2b7f6393dab
children 818697418dbe
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
1 local Luan = require "luan:Luan.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
2 local error = Luan.error
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
3 local ipairs = Luan.ipairs or error()
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
4 local Parsers = require "luan:Parsers.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
5 local json_string = Parsers.json_string or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
6 local Io = require "luan:Io.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
7 local Http = require "luan:http/Http.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
8 local User = require "site:/lib/User.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
9 local current_user = User.current or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
10 local Chat = require "site:/lib/Chat.luan"
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
11 local get_chat_by_id = Chat.get_by_id or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
12 local Post = require "site:/lib/Post.luan"
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
13 local post_search = Post.search or error()
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
14 local Shared = require "site:/lib/Shared.luan"
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
15 local post_html = Shared.post_html or error()
33
e2b7f6393dab add online
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
16 local chat_other_users_html = Shared.chat_other_users_html or error()
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
17 local Logging = require "luan:logging/Logging.luan"
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
18 local logger = Logging.logger "get_chat.js"
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
19
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
20
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
21 local function html()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
22 local user = current_user() or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
23 local chat = Http.request.parameters.chat or error()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
24 chat = get_chat_by_id(chat) or error()
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
25 local posts = post_search( "post_chat_id:"..chat.id, "id" )
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
26 %>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
27 <div top>
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
28 <h3>
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
29 <img back onclick="back()" src="/images/arrow_back.svg">
33
e2b7f6393dab add online
Franklin Schmidt <fschmidt@gmail.com>
parents: 27
diff changeset
30 <span><% chat_other_users_html(chat,user) %></span>
27
809193524522 responsive
Franklin Schmidt <fschmidt@gmail.com>
parents: 12
diff changeset
31 </h3>
34
Franklin Schmidt <fschmidt@gmail.com>
parents: 33
diff changeset
32 <button onclick='deleteChat()'>Delete</button>
10
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
33 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
34 <div main>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
35 <%
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
36 for _, post in ipairs(posts) do
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
37 post_html(post)
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
38 end
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
39 %>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
40 <div input>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
41 <textarea oninput="fixTextarea(event)" onkeydown="textareaKey(event)"></textarea>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
42 <button onclick="addPost()" title="Send"><img src="/images/send.svg"></button>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
43 </div>
f9e6a4cc4f7d add Post
Franklin Schmidt <fschmidt@gmail.com>
parents: 7
diff changeset
44 </div>
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
45 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
46 end
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
47
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
48 return function()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
49 Io.stdout = Http.response.text_writer()
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
50 %>
12
9f45d32670ae server push
Franklin Schmidt <fschmidt@gmail.com>
parents: 11
diff changeset
51 gotChat(<%=json_string(`html()`)%>);
7
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
52 <%
41d35b72c774 chat page
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff changeset
53 end