Commit 3b6a767b authored by Grant's avatar Grant
Browse files

chat: buildable & fix ui to merge

parent b083d719
Loading
Loading
Loading
Loading
+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 }) => {
+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 = ({
@@ -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>
+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";

@@ -32,3 +30,5 @@ export const Yapper = () => {
    </div>
  );
};

export default Yapper;
+2 −2
Original line number Diff line number Diff line
@@ -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) => {},
    [],
  );

+4 −25
Original line number Diff line number Diff line
import {
  MessageFlag,
  type Message,
  type MXEventID,
  type MXRoomID,
@@ -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();
@@ -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