From 8bc897a1e7b9f97da6d91a35a732d93c5fb9d37c Mon Sep 17 00:00:00 2001 From: MeowcaTheoRange Date: Thu, 9 May 2024 14:31:27 -0500 Subject: [PATCH] Join page --- src/app/chat/page.tsx | 44 +++++++++++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 14 deletions(-) diff --git a/src/app/chat/page.tsx b/src/app/chat/page.tsx index 108fb9d..fd6a16c 100644 --- a/src/app/chat/page.tsx +++ b/src/app/chat/page.tsx @@ -5,7 +5,7 @@ import { useEffect, useMemo, useRef, useState } from "react"; import { getCookie } from 'cookies-next'; import styles from "./styles.module.css"; import Markdown from "react-markdown"; -import { Conditional } from "@/components/utility/Conditional"; +import { Conditional, ConditionalNull } from "@/components/utility/Conditional"; type MessageType = { channel: string, @@ -84,6 +84,8 @@ export default function Home() { const socketObject = useMemo(() => io(socketLocation), []); const socket = socketObject; + const token = getCookie('token'); + const [ connected, setConnected ] = useState(false); const [ error, _setError ] = useState(""); const [ whoami, _setWhoAmI ] = useState<{[key:string]:any}>({}); @@ -108,8 +110,6 @@ export default function Home() { const messagesRef = useRef(messages); const setMessages = (x:any) => {messagesRef.current = x;_setMessages(x);}; - const [ isLoading, setIsLoading ] = useState(false); - /* SECT: LHUA; Lord help us all these ones */ const [ textBox, setTextBox ] = useState(null); let Message = useRef<(message:MessageType) => React.ReactNode>(() => <>); @@ -166,8 +166,6 @@ export default function Home() { function onConnect() { setConnected(true); - - const token = getCookie('token'); if (token != null) socket.emit('SIG_CHAT_JOIN', { token }, joinChatRes); @@ -363,6 +361,32 @@ export default function Home() { } } + let [ messageLayout, setMessageLayout ] = useState(); + useEffect(() => { + if (messages.length > 0) + setMessageLayout(messages.map(Message.current)); + else if (whoami.admin || channels.find(x => x.name == channel)?.writable) + setMessageLayout( +
+

This channel is empty.

+

Use the bar below to post something.

+
+ ); + else if (token == null) + setMessageLayout(<> +

Join abtmtr.link Chat

+

If you'd like to participate in the chat, you should join!

+

To join with the Fediverse, enter your instance domain.
+ To join with GitHub, enter "github.com".
+ To join with Discord, enter "discord.com".

+
+ + +
+

Tested on Discord, GitHub, Mastodon, GoToSocial, Pleroma, and Misskey

+ ); + }, [messages]); + return ( - {messages.length > 0 && !isLoading ? - messages.map(Message.current) - : (whoami.admin || channels.find(x => x.name == channel)?.writable ? -
-

This channel is empty.

-

Use the bar below to post something.

-
- : <>) - } + {messageLayout}
) } \ No newline at end of file