Loading packages/chat/lib/components/ChatLog/ChatBubble.tsx +0 −2 Original line number Diff line number Diff line import { MessageFlag, type Message } from "@/lib/const"; import { useYap } from "@/context/utils"; import type React from "react"; import type { MatrixEvent } from "matrix-js-sdk"; export const ChatBubble = ({ event }: { event: MatrixEvent }) => { Loading packages/chat/lib/components/ChatLog/ChatLog.tsx +2 −3 Original line number Diff line number Diff line import React, { useEffect, useRef } from "react"; import { ChatBubble } from "./ChatBubble"; import type { Message } from "@/lib/const"; export const ChatLog = ({ Loading @@ -25,9 +24,9 @@ export const ChatLog = ({ <button onClick={loadMore}>Load More {loading && "loading"}</button> )} <React.Fragment> {messages.map((msg) => ( {/* {messages.map((msg) => ( <ChatBubble key={msg.eventId} event={msg} /> ))} ))} */} </React.Fragment> <div ref={bottom} /> </React.Fragment> Loading packages/chat/lib/components/Yapper.tsx +2 −2 Original line number Diff line number Diff line import type { MXUserID } from "@/lib/const"; import { HomeTab } from "./Tab/Home"; import { RoomTab } from "./Tab/Room"; import { getOpenRooms, useYap } from "@/context/utils"; import { useEffect } from "react"; import { LoggedOut } from "./Tab/LoggedOut"; import { InvitesTab } from "./Tab/Invites"; Loading Loading @@ -32,3 +30,5 @@ export const Yapper = () => { </div> ); }; export default Yapper; packages/chat/lib/context/YapContext.tsx +2 −2 Original line number Diff line number Diff line Loading @@ -88,10 +88,10 @@ export const YapContext = ({ children }: React.PropsWithChildren) => { window.open(client.getLoginUrl(window.location.href), "_self"); }, [client]); const openChat = useCallback((withWho: MXUserID | MXRoomID) => {}, []); const openChat = useCallback((_withWho: MXUserID | MXRoomID) => {}, []); const setSystem = useCallback( (handler: (mxid: MXUserID) => boolean) => {}, (_handler: (mxid: MXUserID) => boolean) => {}, [], ); Loading packages/chat/lib/hooks/useMessages.ts +4 −25 Original line number Diff line number Diff line import { MessageFlag, type Message, type MXEventID, type MXRoomID, Loading @@ -17,9 +16,9 @@ export const useMessages = ( loadMore: () => void; } => { const [loading, setLoading] = useState(false); const [atBeginning, setAtBeginning] = useState(false); const [atBeginning, _setAtBeginning] = useState(false); const [messages, setMessages] = useState<Message[]>([]); const [cursor, setCursor] = useState<string>(); // const [cursor, setCursor] = useState<string>(); useEffect(() => { const mxclient = MXClient.get(); Loading Loading @@ -53,31 +52,11 @@ export const useMessages = ( setLoading(true); setTimeout(() => { if (!cursor) { // load most recent const toLoad = TEST_MESSAGES.at(-1)!; setMessages((m) => [...m, toLoad]); setCursor(toLoad.eventId); } else { // load before cursor const toLoad = TEST_MESSAGES[ TEST_MESSAGES.findIndex((m) => m.eventId === cursor) - 1 ]; if (!toLoad) { // we are at the oldest message setAtBeginning(true); return; } setMessages((m) => [toLoad, ...m]); setCursor(toLoad.eventId); } // TODO: load more messages from mxclient setLoading(false); }, 2000); }, [cursor, loading]); }, [loading]); return { messages, loading, atBeginning, loadMore }; }; Loading
packages/chat/lib/components/ChatLog/ChatBubble.tsx +0 −2 Original line number Diff line number Diff line import { MessageFlag, type Message } from "@/lib/const"; import { useYap } from "@/context/utils"; import type React from "react"; import type { MatrixEvent } from "matrix-js-sdk"; export const ChatBubble = ({ event }: { event: MatrixEvent }) => { Loading
packages/chat/lib/components/ChatLog/ChatLog.tsx +2 −3 Original line number Diff line number Diff line import React, { useEffect, useRef } from "react"; import { ChatBubble } from "./ChatBubble"; import type { Message } from "@/lib/const"; export const ChatLog = ({ Loading @@ -25,9 +24,9 @@ export const ChatLog = ({ <button onClick={loadMore}>Load More {loading && "loading"}</button> )} <React.Fragment> {messages.map((msg) => ( {/* {messages.map((msg) => ( <ChatBubble key={msg.eventId} event={msg} /> ))} ))} */} </React.Fragment> <div ref={bottom} /> </React.Fragment> Loading
packages/chat/lib/components/Yapper.tsx +2 −2 Original line number Diff line number Diff line import type { MXUserID } from "@/lib/const"; import { HomeTab } from "./Tab/Home"; import { RoomTab } from "./Tab/Room"; import { getOpenRooms, useYap } from "@/context/utils"; import { useEffect } from "react"; import { LoggedOut } from "./Tab/LoggedOut"; import { InvitesTab } from "./Tab/Invites"; Loading Loading @@ -32,3 +30,5 @@ export const Yapper = () => { </div> ); }; export default Yapper;
packages/chat/lib/context/YapContext.tsx +2 −2 Original line number Diff line number Diff line Loading @@ -88,10 +88,10 @@ export const YapContext = ({ children }: React.PropsWithChildren) => { window.open(client.getLoginUrl(window.location.href), "_self"); }, [client]); const openChat = useCallback((withWho: MXUserID | MXRoomID) => {}, []); const openChat = useCallback((_withWho: MXUserID | MXRoomID) => {}, []); const setSystem = useCallback( (handler: (mxid: MXUserID) => boolean) => {}, (_handler: (mxid: MXUserID) => boolean) => {}, [], ); Loading
packages/chat/lib/hooks/useMessages.ts +4 −25 Original line number Diff line number Diff line import { MessageFlag, type Message, type MXEventID, type MXRoomID, Loading @@ -17,9 +16,9 @@ export const useMessages = ( loadMore: () => void; } => { const [loading, setLoading] = useState(false); const [atBeginning, setAtBeginning] = useState(false); const [atBeginning, _setAtBeginning] = useState(false); const [messages, setMessages] = useState<Message[]>([]); const [cursor, setCursor] = useState<string>(); // const [cursor, setCursor] = useState<string>(); useEffect(() => { const mxclient = MXClient.get(); Loading Loading @@ -53,31 +52,11 @@ export const useMessages = ( setLoading(true); setTimeout(() => { if (!cursor) { // load most recent const toLoad = TEST_MESSAGES.at(-1)!; setMessages((m) => [...m, toLoad]); setCursor(toLoad.eventId); } else { // load before cursor const toLoad = TEST_MESSAGES[ TEST_MESSAGES.findIndex((m) => m.eventId === cursor) - 1 ]; if (!toLoad) { // we are at the oldest message setAtBeginning(true); return; } setMessages((m) => [toLoad, ...m]); setCursor(toLoad.eventId); } // TODO: load more messages from mxclient setLoading(false); }, 2000); }, [cursor, loading]); }, [loading]); return { messages, loading, atBeginning, loadMore }; };