First Major Clean Up Done
This commit is contained in:
parent
949e5a259a
commit
afd79e334c
29 changed files with 46 additions and 118 deletions
|
|
@ -2,18 +2,18 @@ import './chat.css';
|
|||
import { addRoute, setTitle, type RouteHandlerParams, type RouteHandlerReturn } from "@app/routing";
|
||||
import { showError } from "@app/toast";
|
||||
import authHtml from './chat.html?raw';
|
||||
import client from '@app/api'
|
||||
import { getUser, updateUser } from "@app/auth";
|
||||
import io, { Socket } from 'socket.io-client';
|
||||
import { listBuddies } from './listBuddies';
|
||||
import { getProfil } from './getProfil';
|
||||
import { addMessage } from './addMessage';
|
||||
import { broadcastMsg } from './broadcastMsg';
|
||||
import { isLoggedIn } from './isLoggedIn';
|
||||
import { listBuddies } from './chatHelperFunctions/listBuddies';
|
||||
import { getProfil } from './chatHelperFunctions/getProfil';
|
||||
import { addMessage } from './chatHelperFunctions/addMessage';
|
||||
import { broadcastMsg } from './chatHelperFunctions/broadcastMsg';
|
||||
import { isLoggedIn } from './chatHelperFunctions/isLoggedIn';
|
||||
import type { ClientMessage, ClientProfil } from './types_front';
|
||||
import { openProfilePopup } from './openProfilePopup';
|
||||
import { actionBtnPopUpBlock } from './actionBtnPopUpBlock';
|
||||
import { windowStateHidden } from './windowStateHidden';
|
||||
import { openProfilePopup } from './chatHelperFunctions/openProfilePopup';
|
||||
import { actionBtnPopUpBlock } from './chatHelperFunctions/actionBtnPopUpBlock';
|
||||
import { windowStateHidden } from './chatHelperFunctions/windowStateHidden';
|
||||
import type { blockedUnBlocked, obj } from './types_front';
|
||||
|
||||
export const color = {
|
||||
red: 'color: red;',
|
||||
|
|
@ -24,28 +24,6 @@ export const color = {
|
|||
};
|
||||
|
||||
|
||||
export type blockedUnBlocked =
|
||||
{
|
||||
userState: string,
|
||||
userTarget: string,
|
||||
by: string,
|
||||
};
|
||||
|
||||
export type obj =
|
||||
{
|
||||
command: string,
|
||||
destination: string,
|
||||
type: string,
|
||||
user: string,
|
||||
frontendUserName: string,
|
||||
frontendUser: string,
|
||||
token: string,
|
||||
text: string,
|
||||
timestamp: number,
|
||||
SenderWindowID: string,
|
||||
Sendertext: string,
|
||||
};
|
||||
|
||||
const MAX_SYSTEM_MESSAGES = 10;
|
||||
let inviteMsgFlag: boolean = false;
|
||||
|
||||
|
|
@ -513,10 +491,7 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
SenderID: userID,
|
||||
|
||||
};
|
||||
//socket.emit('MsgObjectServer', message);
|
||||
// addMessage(message.command);
|
||||
socket.emit('privMessage', JSON.stringify(message));
|
||||
// addMessage(JSON.stringify(message));
|
||||
break;
|
||||
}
|
||||
// Clear the input in all cases
|
||||
|
|
@ -530,7 +505,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
if (chatWindow) {
|
||||
chatWindow.innerHTML = '';
|
||||
}
|
||||
//clearChatWindow(socket); //DEV testing broadcastGames
|
||||
});
|
||||
|
||||
// Dev Game message button
|
||||
|
|
@ -550,12 +524,6 @@ function handleChat(_url: string, _args: RouteHandlerParams): RouteHandlerReturn
|
|||
sendButton?.click();
|
||||
}
|
||||
});
|
||||
|
||||
// Whoami button to display user name addMessage(msgCommand[0]);
|
||||
|
||||
// bwhoami?.addEventListener('click', async () => {
|
||||
// whoami(socket);
|
||||
// });
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { Socket } from 'socket.io-client';
|
||||
import type { ClientProfil } from './types_front';
|
||||
import type { ClientProfil } from '../types_front';
|
||||
import { blockUser } from './blockUser';
|
||||
|
||||
export function actionBtnPopUpBlock(block: ClientProfil, senderSocket: Socket) {
|
||||
|
|
@ -1,5 +1,3 @@
|
|||
import { color } from './chat';
|
||||
|
||||
/**
|
||||
* function adds a message to the frontend chatWindow
|
||||
* @param text
|
||||
|
|
@ -13,6 +11,5 @@ export function addMessage(text: string) {
|
|||
messageElement.textContent = text;
|
||||
chatWindow.appendChild(messageElement);
|
||||
chatWindow.scrollTop = chatWindow.scrollHeight;
|
||||
console.log(`%c DEBUG LOG: Added new message:%c ${text}`, color.red, color.reset);
|
||||
return ;
|
||||
};
|
||||
|
|
@ -1,11 +1,9 @@
|
|||
import { Socket } from 'socket.io-client';
|
||||
import type { ClientProfil } from './types_front';
|
||||
import type { ClientProfil } from '../types_front';
|
||||
import { getUser } from "@app/auth";
|
||||
|
||||
|
||||
export function blockUser(profil: ClientProfil, senderSocket: Socket) {
|
||||
profil.SenderName = getUser()?.name ?? '';
|
||||
if (profil.SenderName === profil.user) return;
|
||||
// addMessage(`${profil.Sendertext}: ${profil.user}⛔`)
|
||||
senderSocket.emit('blockUser', JSON.stringify(profil));
|
||||
};
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { addMessage } from "./addMessage";
|
||||
import { Socket } from 'socket.io-client';
|
||||
import { getUser } from "@app/auth";
|
||||
import type { ClientMessage } from "./types_front";
|
||||
import type { ClientMessage } from "../types_front";
|
||||
/**
|
||||
* function sends socket.emit to the backend to active and broadcast a message to all sockets
|
||||
* echos the message with addMessage to the sender
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import io, { Socket } from 'socket.io-client';
|
||||
import { Socket } from 'socket.io-client';
|
||||
|
||||
/**
|
||||
* function clears all messages in the chat window
|
||||
|
|
@ -9,5 +9,4 @@ export function clearChatWindow(senderSocket: Socket) {
|
|||
const chatWindow = document.getElementById("t-chatbox") as HTMLDivElement;
|
||||
if (!chatWindow) return;
|
||||
chatWindow.innerHTML = "";
|
||||
// senderSocket.emit('nextGame');
|
||||
}
|
||||
|
|
@ -19,6 +19,5 @@ export function getProfil(socket: Socket, user: string) {
|
|||
timestamp: Date.now(),
|
||||
SenderWindowID: socket.id,
|
||||
};
|
||||
// addMessage(JSON.stringify(profil));
|
||||
socket.emit('profilMessage', JSON.stringify(profil));
|
||||
}
|
||||
|
|
@ -27,20 +27,16 @@ export async function listBuddies(socket: Socket, buddies: HTMLDivElement, listB
|
|||
const user = getUser()?.name ?? "";
|
||||
buddies.appendChild(buddiesElement);
|
||||
buddies.scrollTop = buddies.scrollHeight;
|
||||
console.log(`Added buddies: ${bud}`);
|
||||
|
||||
buddiesElement.style.cursor = "pointer";
|
||||
buddiesElement.addEventListener("click", () => {
|
||||
navigator.clipboard.writeText(bud);
|
||||
if (bud !== user && user !== "") {
|
||||
sendtextbox.value = `@${bud}: `;
|
||||
console.log("Copied to clipboard:", bud);
|
||||
sendtextbox.focus();
|
||||
}
|
||||
});
|
||||
|
||||
buddiesElement.addEventListener("dblclick", () => {
|
||||
console.log("Open profile:", bud);
|
||||
getProfil(socket, bud);
|
||||
sendtextbox.value = "";
|
||||
});
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import type { ClientProfil } from './types_front';
|
||||
import type { ClientProfil } from '../types_front';
|
||||
|
||||
export async function openProfilePopup(profil: ClientProfil) {
|
||||
const modalname = document.getElementById("modal-name") ?? null;
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
import { __socket } from './chat';
|
||||
import { __socket } from '../chat';
|
||||
import { updateUser } from "@app/auth";
|
||||
|
||||
export async function windowStateHidden() {
|
||||
|
|
@ -34,6 +34,13 @@ export type ClientProfil = {
|
|||
};
|
||||
|
||||
|
||||
export type blockedUnBlocked =
|
||||
{
|
||||
userState: string,
|
||||
userTarget: string,
|
||||
by: string,
|
||||
};
|
||||
|
||||
export type obj =
|
||||
{
|
||||
command: string,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue