diff options
author | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-03 16:22:09 +0200 |
---|---|---|
committer | Zhongheng Liu <z.liu@outlook.com.gr> | 2024-01-03 16:22:09 +0200 |
commit | f90cf89b398e31338a1eb36368b0e64741967e93 (patch) | |
tree | 7247d5d47c23aed7f7d4c35e4005cf6cfacfc5b6 | |
parent | 4a7c3fbeda8bc9f1dbca151678f09db84e1a8b8e (diff) | |
download | epq-web-f90cf89b398e31338a1eb36368b0e64741967e93.tar.gz epq-web-f90cf89b398e31338a1eb36368b0e64741967e93.tar.bz2 epq-web-f90cf89b398e31338a1eb36368b0e64741967e93.zip |
Styling hacker greentext formatting
-rw-r--r-- | src/App.css | 42 | ||||
-rw-r--r-- | src/App.tsx | 1 | ||||
-rw-r--r-- | src/Chat/Chat.css | 14 | ||||
-rw-r--r-- | src/Chat/Chat.tsx | 22 | ||||
-rw-r--r-- | src/Chat/Message.tsx | 13 | ||||
-rw-r--r-- | src/Chat/MessageContainer.tsx | 15 | ||||
-rw-r--r-- | src/Chat/types.tsx | 9 |
7 files changed, 58 insertions, 58 deletions
diff --git a/src/App.css b/src/App.css index 74b5e05..9fc009f 100644 --- a/src/App.css +++ b/src/App.css @@ -1,38 +1,8 @@ -.App { - text-align: center; -} - -.App-logo { - height: 40vmin; - pointer-events: none; +body { + background-color: black; + color: #00FF33; } - -@media (prefers-reduced-motion: no-preference) { - .App-logo { - animation: App-logo-spin infinite 20s linear; - } -} - -.App-header { - background-color: #282c34; +.App { + margin: 3%; min-height: 100vh; - display: flex; - flex-direction: column; - align-items: center; - justify-content: center; - font-size: calc(10px + 2vmin); - color: white; -} - -.App-link { - color: #61dafb; -} - -@keyframes App-logo-spin { - from { - transform: rotate(0deg); - } - to { - transform: rotate(360deg); - } -} +}
\ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 56cd405..0932852 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,5 +1,6 @@ import React, { useState } from "react"; import ChatWrapper from "./Chat/Chat"; +import "./App.css"; const App = (): React.ReactElement => { const [username, setUsername] = useState<string>() if (!username) { diff --git a/src/Chat/Chat.css b/src/Chat/Chat.css new file mode 100644 index 0000000..7924811 --- /dev/null +++ b/src/Chat/Chat.css @@ -0,0 +1,14 @@ +#chat-inner { + height: 250px; + overflow-y: auto; + overflow-wrap: normal; +} +.entry-box { + position: absolute; + bottom: 0; + min-height: 20%; +} +.chat { + min-height: 80vh; + position: relative; +}
\ No newline at end of file diff --git a/src/Chat/Chat.tsx b/src/Chat/Chat.tsx index 6cb2e2d..cc185a9 100644 --- a/src/Chat/Chat.tsx +++ b/src/Chat/Chat.tsx @@ -1,8 +1,9 @@ import React, { useEffect, useState } from "react"; -import { Message } from "./Message"; -import { Client, Stomp } from "@stomp/stompjs"; -import { MessageType } from "./types"; +import { MessageContainer } from "./MessageContainer"; +import { Client, Stomp, StompHeaders } from "@stomp/stompjs"; +import { Message, MessageType } from "./types"; import { renderToStaticMarkup } from 'react-dom/server'; +import './Chat.css'; // The last bit of magic sauce to make this work // EXPLANATION // @@ -31,8 +32,9 @@ const ChatWrapper = ( stompClient.onConnect = (frame) => { stompClient.subscribe(endpoints.subscription, (message) => { console.log(`Collected new message: ${message.body}`); - const {fromUserId, toUserId, content, timeMillis} = JSON.parse(message.body) as MessageType - const messageElement = <Message sender={fromUserId} text={content} /> + const messageBody = JSON.parse(message.body) as Message + if (messageBody.type === MessageType.MESSAGE) {return;} + const messageElement = <MessageContainer {...messageBody} /> console.log(messageElement); // Temporary solution @@ -70,8 +72,9 @@ const ChatWrapper = ( // TODO Explore const entryElement: HTMLInputElement = document.getElementById("data-entry") as HTMLInputElement if (!entryElement.value) {alert("Message cannot be empty!"); return;} - const messageData: MessageType = + const messageData: Message = { + type: MessageType.HELLO, fromUserId: user, toUserId: "everyone", content: entryElement.value, @@ -80,7 +83,10 @@ const ChatWrapper = ( console.log(`STOMP connection status: ${stompClient.connected}`); stompClient.publish({ body: JSON.stringify(messageData), - destination: endpoints.destination + destination: endpoints.destination, + headers: { + 'Content-Type': 'application/json; charset=utf-8' + } }); entryElement.value = ""; } @@ -102,7 +108,7 @@ const ChatWrapper = ( <div className="chat"> <div id="chat-inner"> </div> - <span><input id="data-entry"></input><button onClick={() => sendData()}>Send</button></span> + <span className="entry-box"><input id="data-entry"></input><button onClick={() => sendData()}>Send</button></span> </div> ) } diff --git a/src/Chat/Message.tsx b/src/Chat/Message.tsx deleted file mode 100644 index ec89348..0000000 --- a/src/Chat/Message.tsx +++ /dev/null @@ -1,13 +0,0 @@ -import React from "react"; - -export const Message = ( - { - sender, text, - }: { - sender: string; - text: string; - } -): React.ReactElement<{ sender: string; text: string; }> => { - - return (<p>Message from {sender}: {text}</p>); -}; diff --git a/src/Chat/MessageContainer.tsx b/src/Chat/MessageContainer.tsx new file mode 100644 index 0000000..dc3d613 --- /dev/null +++ b/src/Chat/MessageContainer.tsx @@ -0,0 +1,15 @@ +import React from "react"; +import { Message, MessageType } from "./types"; + +export const MessageContainer = ( + { + type, + fromUserId, + toUserId, + content, + timeMillis, + }: Message +): React.ReactElement<{ sender: string; text: string; }> => { + const dateTime: Date = new Date(timeMillis); + return (<p>[{dateTime.toLocaleString(Intl.DateTimeFormat().resolvedOptions().timeZone)}] Message from {fromUserId}: {content}</p>); +}; diff --git a/src/Chat/types.tsx b/src/Chat/types.tsx index 93edcc4..53a085d 100644 --- a/src/Chat/types.tsx +++ b/src/Chat/types.tsx @@ -1,4 +1,11 @@ -export type MessageType = { +export enum MessageType { + MESSAGE, + SYSTEM, + HELLO, + DATA, +} +export type Message = { + type: MessageType, fromUserId: string, toUserId: string, content: string, |