initial commit
[browser-rts.git] / src / render / mail.ts
1 import { DateTime } from "luxon";
2 import { MessageWithNames } from "../repository/mail";
3
4 export function renderMailroom(mail: MessageWithNames[]): string {
5     return `
6     <table>
7     <tr>
8         <th>From</th>
9         <th>Subject</th>
10         <th>Sent At</th>
11     </tr>
12     ${mail.map(msg => {
13         return `
14         <tr class="${msg.read_at === 0 ? 'unread': 'read'}" >
15             <td>${msg.username}</td>
16             <td>
17             <a href="#" hx-trigger="click" hx-get="/messages/${msg.id}" hx-target="#individual-message">
18                 ${msg.subject}
19             </a>
20             </td>
21             <td>${DateTime.fromMillis(msg.sent_at)}</td>
22         </tr>
23         `;
24     }).join("\n")}
25     </table>
26     <div id="individual-message"></div>
27     `;
28 }
29
30 export function renderMessage(msg: MessageWithNames): string {
31     return `
32     <table>
33     <tr>
34         <th>From</th>
35         <td>${msg.username}</td>
36     </tr>
37     <tr>
38         <th>Sent</th>
39         <td>${DateTime.fromMillis(msg.sent_at)}</td>
40     </tr>
41     <tr>
42         <th>Subject</th>
43         <td>${msg.subject}</td>
44     </tr>
45     <tr>
46         <th valign="top">Message</th>
47         <td>${msg.message}</td>
48     </tr>
49     </table>
50     `;
51     console.log(msg);
52     return '';
53 }