убрал console.log,, фикс реги, фикк отображение чатов при создании

This commit is contained in:
uniknow 2024-08-28 21:38:37 +04:00
parent 9569071a2a
commit 206d850f03
10 changed files with 43 additions and 1390 deletions

View file

@ -15,7 +15,7 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){ if(response.ok){
let data = await response.json() let data = await response.json()
let msgMassive = data.messages let msgMassive = data.messages
console.log(msgMassive, " аа сообщения", chatId, " - айди") //console.log(msgMassive, " аа сообщения", chatId, " - айди")
if(msgMassive === null){ if(msgMassive === null){
return [] return []
@ -73,7 +73,7 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){ if(response.ok){
const data = await response.json(); const data = await response.json();
console.log("картинка принята") //console.log("картинка принята")
return data.image_url; return data.image_url;
} }
@ -91,7 +91,7 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){ if(response.ok){
let data = await response.json(); let data = await response.json();
data = data.allowed_chats data = data.allowed_chats
console.log(data) //console.log(data)
if(data == null) if(data == null)
return [] return []
@ -209,7 +209,9 @@ export async function getLastMessages(chatId,msgLoaded){
if(response.ok){ if(response.ok){
let data = await response.json() let data = await response.json()
let id = data.chat_id let id = data.chat_id
return id let chats = await getAllChats(token)
window.location.href = `/c#id=${id}`
return chats
} }
else{ else{
console.log(response) console.log(response)

View file

@ -23,7 +23,7 @@ export async function handleLogin(username, password) {
const data = await response.json() const data = await response.json()
const token = data.authorization const token = data.authorization
localStorage.setItem('BPChat', token) localStorage.setItem('BPChat', token)
window.location.href = '/' window.location.href = '/c'
return "" // чтобы ничего не выводилось в качестве ошибки return "" // чтобы ничего не выводилось в качестве ошибки
} }
else if(response.status === 401) else if(response.status === 401)

View file

@ -21,7 +21,7 @@ export async function checkExsistingUser(username, email) {
} }
else if(response.status === 422){ else if(response.status === 422){
let data = await response.json(); let data = await response.json();
return data return "не похоже на почту"
} }
else{ else{
console.log(response.status) console.log(response.status)

View file

@ -19,7 +19,6 @@ export async function getAvatarHistory(token){
} }
export async function getConfirmationCode(token, email){ export async function getConfirmationCode(token, email){
console.log(token, email, "<-- лох")
const response = await fetch(`${PUBLIC_URL}/api/users/send_confirmation_code`,{ const response = await fetch(`${PUBLIC_URL}/api/users/send_confirmation_code`,{
method: 'POST', method: 'POST',
credentials:'include', credentials:'include',

View file

@ -14,9 +14,8 @@ export default function createWebSocket(url, token, onMessageCallback) {
}); });
socket.onopen = () => { socket.onopen = () => {
console.log('WebSocket is open now.') //console.log('WebSocket is open .')
console.log(socket) //console.log(socket)
retries = 0 //сброс попыток
while (messageQueue.length > 0) { while (messageQueue.length > 0) {
socket.send(messageQueue.shift()); socket.send(messageQueue.shift());
@ -24,11 +23,11 @@ export default function createWebSocket(url, token, onMessageCallback) {
}; };
socket.onclose = (event) => { socket.onclose = (event) => {
console.log('WebSocket is closed now.', event) //console.log('WebSocket is closed .', event)
}; };
socket.onerror = (error) => { socket.onerror = (error) => {
console.error('WebSocket error observed:', error) //console.error('WebSocket error observed:', error)
}; };

7
src/routes/+error.svelte Normal file
View file

@ -0,0 +1,7 @@
<script>
import { onMount } from "svelte";
onMount(() => {
window.location.assign('/c');
})
</script>

File diff suppressed because it is too large Load diff

View file

@ -8,7 +8,6 @@
let Nickname; let Nickname;
let userImage; let userImage;
let jopa = 0;
onMount(async () => { onMount(async () => {
const UserData = await UserCheck(); const UserData = await UserCheck();
@ -24,8 +23,8 @@
</script> </script>
<header> <header>
<a href="/" class="avatarDiv"> <a href="/c" class="avatarDiv">
<img class="siteAvatar" src="./image/BP-NEON.png" alt="лого" /> <img class="siteAvatar" src="./image/BP-NEON.png" alt="лого"/>
<h2>BP Chat</h2> <h2>BP Chat</h2>
</a> </a>

View file

@ -188,7 +188,6 @@
const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; const emailPattern = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
let isValidEmail = emailPattern.test(newEmail) let isValidEmail = emailPattern.test(newEmail)
console.log(isValidEmail)
if((newEmail != "") && (isValidEmail == true)){ if((newEmail != "") && (isValidEmail == true)){
emailError = await checkExsistingUser(null, newEmail) emailError = await checkExsistingUser(null, newEmail)

View file

@ -56,7 +56,7 @@
window.addEventListener('keydown', onEnterPress); window.addEventListener('keydown', onEnterPress);
chats = await getAllChats(token) chats = await getAllChats(token)
console.log([] == false) //console.log([] == false) // true
if(chats === false){ if(chats === false){
chats = [] chats = []
warningMessage = "чтобы пользоваться чатом, подтверди почту" warningMessage = "чтобы пользоваться чатом, подтверди почту"
@ -66,16 +66,16 @@
async function handleChatUrlChange() { async function handleChatUrlChange() {
if (window.location.hash.startsWith('#id=')) { if (window.location.hash.startsWith('#id=')) {
console.log(location.hash.substring(1), "FFFFFFFFFFFFFFFFFFFFFFFFFFFF")
chatId = window.location.hash.slice(4); chatId = window.location.hash.slice(4);
msgLoaded = 0
//console.log(chatId, " chatId") //console.log(chatId, " chatId")
msgLoaded = 0
currentChat = chats.find(chat => chat.chat_id == chatId) currentChat = chats.find(chat => chat.chat_id == chatId)
if(currentChat == undefined){ //if(currentChat == undefined){
window.location.href = '/' // window.location.href = '/c'
} //}
//console.log(currentChat, " текущий чат") //console.log(currentChat, " текущий чат")
pickedChatName = currentChat.chat_name pickedChatName = currentChat.chat_name
pickedChatImg = currentChat.avatar_image pickedChatImg = currentChat.avatar_image
@ -87,7 +87,7 @@
const websocketUrl = `${PUBLIC_WSS}/api/chat/ws/${chatId}` const websocketUrl = `${PUBLIC_WSS}/api/chat/ws/${chatId}`
if (socket){ if (socket){
console.log("Сокет есть") //console.log("Сокет есть")
socket.close(); socket.close();
socket = null socket = null
} }
@ -122,6 +122,8 @@
messages = messages messages = messages
}) })
} else {
messages = []
} }
} }
handleChatUrlChange(); handleChatUrlChange();
@ -182,6 +184,7 @@
if(!isLoaded) if(!isLoaded)
sendMessage() sendMessage()
} }
} }
let rows = 1 let rows = 1
@ -191,9 +194,9 @@
const textarea = document.getElementById("msg"); const textarea = document.getElementById("msg");
//console.log(textarea.scrollHeight) //console.log(textarea.scrollHeight)
if (textarea) { if (textarea) {
textarea.style.height = '1em'; //?? textarea.style.height = '20px'; //??
textarea.style.height = (textarea.scrollHeight > maxRows * 18) ? `${maxRows * 18}px` : `${textarea.scrollHeight}px`; textarea.style.height = (textarea.scrollHeight > maxRows * 18) ? `${maxRows * 18}px` : `${textarea.scrollHeight}px`;
console.log(textarea.scrollHeight) //console.log(textarea.scrollHeight)
} }
} }
@ -380,15 +383,8 @@ let pinOrNot = false
} }
async function submtiCreateNewChat(){ async function submtiCreateNewChat(){
token = localStorage.getItem('BPChat') chats = await createNewChat(newChatName, selectedUserId, token)
let newChatId = await createNewChat(newChatName, selectedUserId, token) createNewChatShow = false
window.location.href = `/#id=${newChatId}`
//createNewChatShow = false
//history.pushState(null, null, `/#id=${newChatId}`);
//handleRouteChange();
//chats = await getAllChats()
} }
function cancelCreateNewChat(){ function cancelCreateNewChat(){
@ -426,11 +422,11 @@ let pinOrNot = false
async function deleteChatButt(chatId){ async function deleteChatButt(chatId){
let result = await deleteChat(chatId,token) let result = await deleteChat(chatId,token)
const index = chats.findIndex(chat => chat.chat_id === chatId); //const index = chats.findIndex(chat => chat.chat_id === chatId);
chats.splice(index, 1); //chats.splice(index, 1);
//console.log(index) //console.log(index)
//console.log(result) //console.log(result)
chats = await getAllChats() //chats = await getAllChats(token)
} }
</script> </script>
@ -494,7 +490,7 @@ let pinOrNot = false
{#each chats as chat} {#each chats as chat}
<div class="chatDivLeft" class:chatDivLeftSelected="{chat.chat_id == chatId}" <div class="chatDivLeft" class:chatDivLeftSelected="{chat.chat_id == chatId}"
transition:fade={{ duration: 800 }}> transition:fade={{ duration: 800 }}>
<a class="aChatDivLeft" href={`/chat#id=${chat.chat_id}`}> <a class="aChatDivLeft" href={`/c#id=${chat.chat_id}`}>
<img class="chatImage" src="{chat.avatar_image}" alt="аватарка"> <img class="chatImage" src="{chat.avatar_image}" alt="аватарка">
<h2 class="chatName">{chat.chat_name}</h2> <h2 class="chatName">{chat.chat_name}</h2>
{#if chat.created_by == userId} {#if chat.created_by == userId}
@ -958,9 +954,12 @@ let pinOrNot = false
} }
.textMsg{ .textMsg{
//min-height: calc(48px);
//max-height: 180px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: center; justify-content: center;
} }
.imageFile{ .imageFile{