From 0c6b6c546b9b0ae7d834541cf880353df0c5562b Mon Sep 17 00:00:00 2001 From: Mark Date: Thu, 29 Feb 2024 12:59:38 +0300 Subject: [PATCH] add createChat func on frontend --- frontend/src/components.jsx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/frontend/src/components.jsx b/frontend/src/components.jsx index c35fae8..d9fcc05 100644 --- a/frontend/src/components.jsx +++ b/frontend/src/components.jsx @@ -22,4 +22,23 @@ async function user_is_logged_in() { } } -export {Footer, user_is_logged_in, get_user} \ No newline at end of file +async function createChat(event) { + let user = await get_user() + + let response = await fetch("http://localhost:8000/create-chat?username=" + `${user.name}`, { + method: 'POST', + headers: { + "Content-type": "application/json" + } + }).then(response => response.json()); + console.log(response) + + + if (response.status === 201) { + localStorage.chat = response.chat + window.location.pathname = `/chat/${response.name}`; + } +} + + +export {Footer, user_is_logged_in, get_user, createChat} \ No newline at end of file