Archived
1
0
Disbranĉigi 0

Split 'send message' input into its own frame

This commit is contained in:
Jaidyn Ann 2023-05-31 14:29:11 -05:00
parent a4da1b6da9
commit 340b9feee1
4 changed files with 35 additions and 17 deletions

View File

@ -126,6 +126,10 @@
("ROOM_ID" . ,(uri:uri-encode-string channel)))))
(define (room-send-html)
(html-from-template "templates/room-send.html" '()))
;; Generate the HTML listing a room's chat messages.
(define (room-messages-html irc-dir channel)
(html-from-template
@ -189,23 +193,22 @@
[(equal? sub-path "messages")
(spiffy:send-response status: 'ok
body: (room-messages-html irc-dir channel))]
[(equal? sub-path "send")
(spiffy:send-response status: 'ok
body: (room-send-html))]
[(or (not sub-path) (string=? sub-path ""))
(spiffy:send-response status: 'ok
body: (room-index-html irc-dir channel))])))
(define (http-send-room-message irc-dir #!optional request path)
(let ([request-data (intarweb:read-urlencoded-request-data request 50000)]
[channel (third path)])
(define (http-post-room-dir irc-dir #!optional request path)
(let* ([channel (third path)]
[request-data (intarweb:read-urlencoded-request-data request 50000)])
(if (alist-ref 'message request-data)
(begin
(send-message irc-dir channel (alist-ref 'message request-data))
;; We don't want the page to render before the message has been sent!
;; Then the user might think, “uhh my message not sent¿?”
(sleep 1)))
(http-get-room-dir irc-dir request path)))
(send-message irc-dir channel (alist-ref 'message request-data))
(sleep 1)))
(http-get-room-dir irc-dir request (list '/ "room" channel "messages"))))
;; Send response for the / index.
@ -239,7 +242,7 @@
;; An associative list of POST handlers, to be used by assoc-by-path.
(define http-post-handlers
`(((/ "room" "*") . ,http-send-room-message)))
`(((/ "room" "*") . ,http-post-room-dir)))
;; Get a pair from an associative list based on the closest match to the

View File

@ -7,7 +7,10 @@
</head>
<frameset cols="300px,*,200px">
<frame name="rooms" src="/room#{{ROOM_ID}}">
<frame name="messages" src="messages">
<frameset rows="*,50px">
<frame name="messages" src="messages">
<frame name="send" src="send">
</frameset>
<frame name="users" src="users">
</frameset>
</html>

View File

@ -5,15 +5,11 @@
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css" type="text/css">
<meta http-equiv="refresh" content="20">
<meta http-equiv="refresh" content="5">
</head>
<body>
<table>
{{LIST_ITEMS}}
</table>
<form id="send" method="post">
<input name="message" />
<button>Send</button>
</form>
</body>
</html>

16
templates/room-send.html Normal file
View File

@ -0,0 +1,16 @@
<!DOCTYPE HTML>
<html lang="en">
<head>
<title>{{ROOM_TITLE}}</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/style.css" type="text/css">
<meta http-equiv="refresh" content="20">
</head>
<body>
<form id="send" method="post" target="messages" action="messages">
<input name="message" />
<button>Send</button>
</form>
</body>
</html>