From 6c47454e28f476db7df4ec34433b4cc3292796bf Mon Sep 17 00:00:00 2001 From: Kum1ta Date: Mon, 5 Aug 2024 00:26:27 +0200 Subject: [PATCH] Websocket (client) - add variable for know if websocket is connected and used it for don t send something if not connected Notification system (client) - created new class notification who can use with exported variable "createNotification" - available methods : info, success, warning, error - add "todo" in main file Site - add new stylesheet "notification.css" --- site/interface/site/index.html | 3 + site/interface/site/main.js | 14 +++- site/interface/site/notification/main.js | 78 ++++++++++++++++++++++ site/interface/site/style/notification.css | 57 ++++++++++++++++ site/interface/site/style/style.css | 5 +- site/interface/site/websocket.js | 17 +++-- 6 files changed, 165 insertions(+), 9 deletions(-) create mode 100644 site/interface/site/notification/main.js create mode 100644 site/interface/site/style/notification.css diff --git a/site/interface/site/index.html b/site/interface/site/index.html index acc459e..12dee80 100644 --- a/site/interface/site/index.html +++ b/site/interface/site/index.html @@ -6,12 +6,15 @@ Chat + +
+

CHAT

diff --git a/site/interface/site/main.js b/site/interface/site/main.js index 1cecbda..f097f48 100644 --- a/site/interface/site/main.js +++ b/site/interface/site/main.js @@ -6,12 +6,24 @@ /* By: edbernar { liveChat(); }); + + + +document.addEventListener("keydown", (e) => { + if (e.key === "/") + createNotification.info("Hello"); + if (e.key === "*") + createNotification.success("Hello"); + if (e.key === "-") + createNotification.error("Hello"); +}); \ No newline at end of file diff --git a/site/interface/site/notification/main.js b/site/interface/site/notification/main.js new file mode 100644 index 0000000..d6a2abf --- /dev/null +++ b/site/interface/site/notification/main.js @@ -0,0 +1,78 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* main.js :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: edbernar { + newNotification.style.opacity = 1; + }, 100); + setTimeout(() => { + setTimeout(() => { + divNotification.removeChild(newNotification); + }, 99); + newNotification.style.animation = "slideOut 0.11s"; + }, timer); +} + +class notification +{ + timer = 2000; + + constructor() {} + + info(message, action=null) + { + console.log("New info notification: " + message); + newNotification("info", this.timer); + } + + success(message, action=null) + { + console.log("New success notification: " + message); + newNotification("success", this.timer); + } + + warning(message, action=null) + { + console.log("New warning notification: " + message); + newNotification("warning", this.timer); + } + + error(message, action=null) + { + console.log("New error notification: " + message); + newNotification("error", this.timer); + } +} + +const createNotification = new notification(); + +export { createNotification }; \ No newline at end of file diff --git a/site/interface/site/style/notification.css b/site/interface/site/style/notification.css new file mode 100644 index 0000000..2ea1e49 --- /dev/null +++ b/site/interface/site/style/notification.css @@ -0,0 +1,57 @@ +/* ************************************************************************** */ +/* */ +/* ::: :::::::: */ +/* notification.css :+: :+: :+: */ +/* +:+ +:+ +:+ */ +/* By: edbernar { + status = 1; console.log('Connected'); if (token) sendRequest("login", {"type": "byToken", "token": token}); - }; socket.onmessage = (event) => { @@ -57,12 +59,15 @@ socket.onmessage = (event) => { }; socket.onclose = () => { + status = 0; console.log('Disconnected'); }; function sendRequest(type, content) { let coc = null; + if (status === 0) + return ; if (content instanceof Object) coc = JSON.stringify(content); else