comparison src/thread.html.luan @ 18:94e26bffd4fb

UI work
author Franklin Schmidt <fschmidt@gmail.com>
date Mon, 11 Jul 2022 12:14:05 -0600
parents bff178656073
children da006d1c1eba
comparison
equal deleted inserted replaced
17:a602a5735a37 18:94e26bffd4fb
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 Time = require "luan:Time.luan"
5 local time_now = Time.now or error()
4 local Io = require "luan:Io.luan" 6 local Io = require "luan:Io.luan"
5 local Http = require "luan:http/Http.luan" 7 local Http = require "luan:http/Http.luan"
6 local Shared = require "site:/lib/Shared.luan" 8 local Shared = require "site:/lib/Shared.luan"
7 local head = Shared.head or error() 9 local head = Shared.head or error()
8 local header = Shared.header or error() 10 local header = Shared.header or error()
25 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"}) 27 local docs, total_hits = Db.search("post_root_id:"..root_id,1,1000,{sort="id"})
26 local posts = Post.from_docs(docs) 28 local posts = Post.from_docs(docs)
27 local subject_html = posts[1].subject_html 29 local subject_html = posts[1].subject_html
28 local user = User.current() 30 local user = User.current()
29 local user_name = user and user.name 31 local user_name = user and user.name
32 local now = time_now()
30 Io.stdout = Http.response.text_writer() 33 Io.stdout = Http.response.text_writer()
31 %> 34 %>
32 <!doctype html> 35 <!doctype html>
33 <html> 36 <html>
34 <head> 37 <head>
35 <% head() %> 38 <% head() %>
36 <title><%=forum_title%>: <%=subject_html%></title> 39 <title><%=forum_title%>: <%=subject_html%></title>
37 <style> 40 <style>
41 div[author] {
42 margin-bottom: 6px;
43 font-size: 10px;
44 }
45 div[author] img {
46 width: 28px;
47 vertical-align: middle;
48 border-radius: 50%;
49 }
50 div[author] a {
51 font-weight: bold;
52 }
53 span[ago] {
54 color: #888;
55 }
38 [message] { 56 [message] {
39 white-space: pre-wrap; 57 white-space: pre-wrap;
58 }
59 textarea {
60 width: 100%;
61 max-width: 450px;
62 height: 100px;
40 } 63 }
41 </style> 64 </style>
42 <script> 65 <script>
43 function cancelEdit(post) { 66 function cancelEdit(post) {
44 let postDiv = document.querySelector('[post="'+post+'"]'); 67 let postDiv = document.querySelector('[post="'+post+'"]');
60 } 83 }
61 function deleteYes(span) { 84 function deleteYes(span) {
62 let post = span.getAttribute('delete'); 85 let post = span.getAttribute('delete');
63 ajax( '/delete.js?post=' + post ); 86 ajax( '/delete.js?post=' + post );
64 } 87 }
88
89 function init() {
90 let spans = document.querySelectorAll('span[ago]');
91 for( let i=0; i<spans.length; i++ ) {
92 let span = spans[i];
93 let date = span.getAttribute('date');
94 date = parseInt(date);
95 span.title = new Date(date).toLocaleString();
96 }
97 }
65 </script> 98 </script>
66 </head> 99 </head>
67 <body> 100 <body onload="init()">
68 <% header() %> 101 <% header() %>
69 <div content> 102 <div content>
70 <h1><%=subject_html%></h1> 103 <h1><%=subject_html%></h1>
71 <% for _, post in ipairs(posts) do 104 <% for _, post in ipairs(posts) do
72 if post.is_deleted then 105 if post.is_deleted then
73 continue 106 continue
74 end 107 end
75 %> 108 %>
76 <hr> 109 <hr>
77 <div post="<%=post.id%>"> 110 <div post="<%=post.id%>">
111 <div author>
112 <img src="/images/profile.png">
113 <a href="/whatever"><%= post.author_name %></a>
114 <span ago date="<%=post.date%>"><% post.ago(now) %> ago</span>
115 </div>
78 <div output> 116 <div output>
79 <% bbcode_to_html(post.content) %> 117 <% bbcode_to_html(post.content) %>
80 <p> 118 <p>
81 <a href="/reply.html?parent=<%=post.id%>">reply</a> 119 <a href="/reply.html?parent=<%=post.id%>">reply</a>
82 <% if post.author_name == user_name then %> 120 <% if post.author_name == user_name then %>