changeset 56:323ddacc1593

start invite
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 04 Mar 2025 07:00:42 -0700
parents d21ae4920aac
children c420f39eb474
files src/chat.css src/chat.js src/delete_chat.js.luan src/index.html.luan src/invite.js.luan
diffstat 5 files changed, 68 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/chat.css	Mon Mar 03 21:42:38 2025 -0700
+++ b/src/chat.css	Tue Mar 04 07:00:42 2025 -0700
@@ -68,7 +68,13 @@
 }
 
 [intro] {
-	text-align: center;
+	display: flex;
+	flex-direction: column;
+	align-items: center;
+}
+
+[intro] input[type=email] {
+	width: 250px;
 }
 
 div[who] {
--- a/src/chat.js	Mon Mar 03 21:42:38 2025 -0700
+++ b/src/chat.js	Tue Mar 04 07:00:42 2025 -0700
@@ -268,3 +268,15 @@
 	span.setAttribute('unread',n);
 	span.textContent = n;
 }
+
+function invite() {
+	let email = document.querySelector('input[type=email]').value;
+	ajax(`invite.js?email=${encodeURIComponent(email)}`);
+}
+
+function openInvite(email) {
+	let dialog = document.querySelector('dialog[invite]');
+	let span = dialog.querySelector('span[email]');
+	span.textContent = email;
+	openModal(dialog);
+}
--- a/src/delete_chat.js.luan	Mon Mar 03 21:42:38 2025 -0700
+++ b/src/delete_chat.js.luan	Tue Mar 04 07:00:42 2025 -0700
@@ -1,5 +1,6 @@
 local Luan = require "luan:Luan.luan"
 local error = Luan.error
+local Io = require "luan:Io.luan"
 local Http = require "luan:http/Http.luan"
 local User = require "site:/lib/User.luan"
 local current_user = User.current or error()
@@ -20,4 +21,8 @@
 	chat.delete()
 	local js = "getChats(null)"
 	http_push_to_users( user_ids, js )
+	Io.stdout = Http.response.text_writer()
+%>
+	location = '/';
+<%
 end
--- a/src/index.html.luan	Mon Mar 03 21:42:38 2025 -0700
+++ b/src/index.html.luan	Tue Mar 04 07:00:42 2025 -0700
@@ -107,7 +107,20 @@
 <%				chats_html() %>
 			</div>
 			<div posts>
-				<h3 intro>Choose a chat on the left</h3>
+				<div intro>
+					<h3>Choose a chat on the left</h3>
+					<p>or</p>
+					<h3>Chat with another person</h3>
+					<form action="javascript:invite()">
+						<p>
+							<label>Person's email</label><br> 
+							<input type=email name=email required><br>
+						</p>
+						<p>
+							<input type=submit>
+						</p>
+					</form>
+				</div>
 			</div>
 		</div>
 		<div hidden>
@@ -143,6 +156,13 @@
 				<button go onclick="savePost(this)">Save</button>
 			</div>
 		</dialog>
+		<dialog invite>
+			<h2>Chat with another person</h2>
+			<p>We have sent an invite to <span email></span></p>
+			<div buttons>
+				<button cancel onclick="closeModal(this)">Close</button>
+			</div>
+		</dialog>
 		<script>
 			'use strict';
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/invite.js.luan	Tue Mar 04 07:00:42 2025 -0700
@@ -0,0 +1,23 @@
+local Luan = require "luan:Luan.luan"
+local error = Luan.error
+local Parsers = require "luan:Parsers.luan"
+local json_string = Parsers.json_string or error()
+local Http = require "luan:http/Http.luan"
+local Io = require "luan:Io.luan"
+local User = require "site:/lib/User.luan"
+local get_user_by_email = User.get_by_email or error()
+
+
+return function()
+	local email = Http.request.parameters.email or error()
+	Io.stdout = Http.response.text_writer()
+	if get_user_by_email(email) ~= nil then
+%>
+		location = '?with=<%=email%>';
+<%
+		return
+	end
+%>
+	openInvite(<%=json_string(email)%>);
+<%
+end