diff src/chat.js @ 24:af41be2dcdec

add edit_post
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 05 Nov 2024 19:45:08 -0700
parents c54c806fcc6e
children 809193524522
line wrap: on
line diff
--- a/src/chat.js	Tue Nov 05 16:09:10 2024 -0700
+++ b/src/chat.js	Tue Nov 05 19:45:08 2024 -0700
@@ -50,7 +50,7 @@
 	let text = textarea.value;
 	if( text.trim() === '' )
 		return;
-	ajax(`add_post.js?chat=${currentChatId}&content=${encodeURIComponent(text)}`);
+	ajax(`add_post.js?chat=${currentChatId}`,`content=${encodeURIComponent(text)}`);
 	textarea.value = '';
 }
 
@@ -103,6 +103,32 @@
 		div.outerHTML = '';
 }
 
+function editPost(postId) {
+	ajax(`edit_post.js?post=${postId}`);
+}
+
+function openEditPost(postId,text) {
+	currentPostId = postId;
+	let dialog = document.querySelector('dialog[edit_post]');
+	let textarea = dialog.querySelector('textarea');
+	textarea.value = text;
+	openModal(dialog);
+}
+
+function savePost(el) {
+	let text = document.querySelector('dialog[edit_post] textarea').value;
+	closeModal(el);
+	ajax(`save_post.js?post=${currentPostId}`,`content=${encodeURIComponent(text)}`);
+}
+
+function edited(postId,html) {
+	let div = document.querySelector(`div[post="${postId}"]`);
+	if( div ) {
+		div.outerHTML = html;
+		fixPosts();
+	}
+}
+
 function added(html) {
 	let input = document.querySelector('div[input]');
 	input.insertAdjacentHTML('beforebegin',html);