aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZhongheng Liu <z.liu@outlook.com.gr>2024-01-20 11:26:57 +0200
committerZhongheng Liu <z.liu@outlook.com.gr>2024-01-20 11:26:57 +0200
commit7d4953fea6d50eb15120f2be34ffa22302fb4713 (patch)
tree212e14acc35acb489e189bb6f1065f8a213ce394
parent5a40882dd7747d50c5333f213c0517710a7eb858 (diff)
downloadepq-web-7d4953fea6d50eb15120f2be34ffa22302fb4713.tar.gz
epq-web-7d4953fea6d50eb15120f2be34ffa22302fb4713.tar.bz2
epq-web-7d4953fea6d50eb15120f2be34ffa22302fb4713.zip
Refactor and cleanup code
-rw-r--r--src/App.tsx4
-rw-r--r--src/Chat/Chat.tsx4
-rw-r--r--src/Login/Login.tsx2
-rw-r--r--src/MessageDisplay/MessageDisplay.css (renamed from src/Chat/MessageDisplay.css)0
-rw-r--r--src/MessageDisplay/MessageDisplay.tsx (renamed from src/Chat/MessageDisplay.tsx)2
-rw-r--r--src/context.ts2
-rw-r--r--src/handlers/server.ts47
-rw-r--r--src/type/messageTypes.ts (renamed from src/Chat/messageTypes.ts)0
-rw-r--r--src/type/userTypes.ts (renamed from src/Chat/userTypes.tsx)0
9 files changed, 7 insertions, 54 deletions
diff --git a/src/App.tsx b/src/App.tsx
index 70d41b2..47d2f05 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -1,8 +1,8 @@
import React, { useContext, useEffect, useState } from "react";
import Chat from "./Chat/Chat";
import "./App.css";
-import { LangType, Message } from "./Chat/messageTypes";
-import { MessageDisplay } from "./Chat/MessageDisplay";
+import { LangType, Message } from "./type/messageTypes";
+import { MessageDisplay } from "./MessageDisplay/MessageDisplay";
import strings from "./Intl/strings.json";
import { LangContext, LoginContext, LoginType } from "./context";
import { contentTypes, domain, endpoints, port } from "./consts";
diff --git a/src/Chat/Chat.tsx b/src/Chat/Chat.tsx
index aa19502..00e0d0f 100644
--- a/src/Chat/Chat.tsx
+++ b/src/Chat/Chat.tsx
@@ -5,9 +5,9 @@ import React, {
useRef,
useState,
} from "react";
-import { MessageDisplay } from "./MessageDisplay";
+import { MessageDisplay } from "../MessageDisplay/MessageDisplay";
import { Client } from "@stomp/stompjs";
-import { Message, MessageType } from "./messageTypes";
+import { Message, MessageType } from "../type/messageTypes";
import "./Chat.css";
import strings from "../Intl/strings.json";
import { LangContext } from "../context";
diff --git a/src/Login/Login.tsx b/src/Login/Login.tsx
index 6629f4c..6de932c 100644
--- a/src/Login/Login.tsx
+++ b/src/Login/Login.tsx
@@ -1,7 +1,7 @@
import { useState } from "react";
import { contentTypes, domain, endpoints, port } from "../consts";
import { LoginType } from "../context";
-import { User } from "../Chat/userTypes";
+import { User } from "../type/userTypes";
import "./Login.css";
const encrypt = (rawPasswordString: string) => {
// TODO Encryption method stub
diff --git a/src/Chat/MessageDisplay.css b/src/MessageDisplay/MessageDisplay.css
index 15af7eb..15af7eb 100644
--- a/src/Chat/MessageDisplay.css
+++ b/src/MessageDisplay/MessageDisplay.css
diff --git a/src/Chat/MessageDisplay.tsx b/src/MessageDisplay/MessageDisplay.tsx
index d4a6e2b..19853ca 100644
--- a/src/Chat/MessageDisplay.tsx
+++ b/src/MessageDisplay/MessageDisplay.tsx
@@ -1,5 +1,5 @@
import React, { useContext } from "react";
-import { Message, MessageType } from "./messageTypes";
+import { Message, MessageType } from "../type/messageTypes";
import { LangContext } from "../context";
import strings from "../Intl/strings.json";
import "./MessageDisplay.css";
diff --git a/src/context.ts b/src/context.ts
index b826fb8..25d2cf5 100644
--- a/src/context.ts
+++ b/src/context.ts
@@ -1,5 +1,5 @@
import { createContext } from "react";
-import { LangType } from "./Chat/messageTypes";
+import { LangType } from "./type/messageTypes";
export type LoginType = {
username: string;
lastSeen: number;
diff --git a/src/handlers/server.ts b/src/handlers/server.ts
deleted file mode 100644
index 494614b..0000000
--- a/src/handlers/server.ts
+++ /dev/null
@@ -1,47 +0,0 @@
-import { Client } from "@stomp/stompjs";
-import { Message, MessageType } from "../Chat/messageTypes";
-const domain = window.location.hostname;
-const port = "8080";
-const connectionAddress = `ws://${domain}:${port}/ws`;
-const endpoints = {
- destination: "/app/chat",
- subscription: "/sub/chat",
- history: "/api/v1/msg/",
-};
-export const createStompConnection = (
- user: string,
- subUpdateHandler: (message: Message) => void
-) => {
- const stompClient = new Client({
- brokerURL: connectionAddress,
- });
- stompClient.onConnect = (frame) => {
- stompClient.subscribe(endpoints.subscription, (message) => {
- console.log(`Collected new message: ${message.body}`);
- const messageBody = JSON.parse(message.body) as Message;
- console.log(messageBody);
- subUpdateHandler(messageBody);
- });
- stompClient.publish({
- body: JSON.stringify({
- type: MessageType.HELLO,
- fromUserId: user,
- toUserId: "everyone",
- content: `${user} has joined the server!`,
- timeMillis: Date.now(),
- }),
- destination: endpoints.destination,
- });
- };
-
- // Generic error handlers
- stompClient.onWebSocketError = (error) => {
- console.error("Error with websocket", error);
- };
-
- stompClient.onStompError = (frame) => {
- console.error("Broker reported error: " + frame.headers["message"]);
- console.error("Additional details: " + frame.body);
- };
- return stompClient;
-};
diff --git a/src/Chat/messageTypes.ts b/src/type/messageTypes.ts
index 3243d25..3243d25 100644
--- a/src/Chat/messageTypes.ts
+++ b/src/type/messageTypes.ts
diff --git a/src/Chat/userTypes.tsx b/src/type/userTypes.ts
index 7d03592..7d03592 100644
--- a/src/Chat/userTypes.tsx
+++ b/src/type/userTypes.ts