Big Updated, added some tests, added comments for all functions, I forgot the rest
This commit is contained in:
parent
d77271e4b7
commit
90a1059cc8
59 changed files with 1816 additions and 203 deletions
|
|
@ -1,3 +1,8 @@
|
|||
/**
|
||||
* Executes getMessages.
|
||||
* @param none This function has no parameters.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export function getMessages() {
|
||||
return 0;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,14 @@ import type { BoundSendFn } from "@tensamin/ttp/core";
|
|||
import type { Socket } from "@tensamin/shared/data";
|
||||
import type { RawMessages } from "../values";
|
||||
|
||||
/**
|
||||
* Executes getMessages.
|
||||
* @param send Parameter send.
|
||||
* @param amount Parameter amount.
|
||||
* @param offset Parameter offset.
|
||||
* @param user_id Parameter user_id.
|
||||
* @returns Promise<RawMessages>.
|
||||
*/
|
||||
export async function getMessages(
|
||||
send: BoundSendFn<Socket>,
|
||||
amount: number,
|
||||
|
|
|
|||
|
|
@ -10,6 +10,11 @@ import { useSocket } from "@tensamin/ttp/context";
|
|||
import { useCrypto } from "@tensamin/crypto/context";
|
||||
import { log, toast } from "@tensamin/shared/log";
|
||||
|
||||
/**
|
||||
* Executes InputComponent.
|
||||
* @param none This function has no parameters.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function InputComponent() {
|
||||
const [value, setValue] = React.useState("");
|
||||
const [invertEnterBehavior, setInvertEnterBehavior] = React.useState(false);
|
||||
|
|
@ -25,6 +30,11 @@ export default function InputComponent() {
|
|||
});
|
||||
}, [load]);
|
||||
|
||||
/**
|
||||
* Executes handleSubmit.
|
||||
* @param none This function has no parameters.
|
||||
* @returns unknown.
|
||||
*/
|
||||
async function handleSubmit() {
|
||||
if (value.trim() === "") return;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,11 @@ import type { RawMessage } from "../values";
|
|||
import { log } from "@tensamin/shared/log";
|
||||
import Text from "@tensamin/markdown/text";
|
||||
|
||||
/**
|
||||
* Executes Message.
|
||||
* @param props Parameter props.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function Message(props: {
|
||||
message: RawMessage;
|
||||
notEncrypted?: boolean;
|
||||
|
|
|
|||
|
|
@ -11,8 +11,13 @@ export const context = React.createContext<contextType | undefined>(undefined);
|
|||
|
||||
const queryClient = new QueryClient();
|
||||
|
||||
/**
|
||||
* Executes Provider.
|
||||
* @param props Parameter props.
|
||||
* @returns unknown.
|
||||
*/
|
||||
export default function Provider(props: { children: React.ReactNode }) {
|
||||
const { get_shared_secret } = useCrypto();
|
||||
const { getSharedSecret } = useCrypto();
|
||||
const { get } = useUser();
|
||||
const { load } = useStorage();
|
||||
const { send } = useSocket();
|
||||
|
|
@ -47,7 +52,7 @@ export default function Provider(props: { children: React.ReactNode }) {
|
|||
const ownId = await load("user_id");
|
||||
const privateKey = await load("private_key");
|
||||
const ownData = await get(ownId);
|
||||
const sharedSecret = await get_shared_secret(
|
||||
const sharedSecret = await getSharedSecret(
|
||||
privateKey,
|
||||
ownData.public_key,
|
||||
recipientData.public_key,
|
||||
|
|
@ -66,7 +71,7 @@ export default function Provider(props: { children: React.ReactNode }) {
|
|||
return () => {
|
||||
active = false;
|
||||
};
|
||||
}, [get, get_shared_secret, load, userIdValue]);
|
||||
}, [get, getSharedSecret, load, userIdValue]);
|
||||
|
||||
const customGetMessages = React.useCallback(
|
||||
async (amount: number, offset: number) => {
|
||||
|
|
@ -130,6 +135,11 @@ type contextType = {
|
|||
userId: () => number;
|
||||
};
|
||||
|
||||
/**
|
||||
* Executes useChat.
|
||||
* @param none This function has no parameters.
|
||||
* @returns contextType.
|
||||
*/
|
||||
export function useChat(): contextType {
|
||||
const ctx = React.useContext(context);
|
||||
if (!ctx) {
|
||||
|
|
|
|||
|
|
@ -8,6 +8,10 @@ import Message from "./components/message";
|
|||
|
||||
const PAGE_SIZE = 50;
|
||||
|
||||
/**
|
||||
* Renders the chat screen with virtualized history and live message updates.
|
||||
* @returns Chat screen JSX.
|
||||
*/
|
||||
export default function Screen() {
|
||||
const { getMessages, liveMessages, clearLiveMessages, userId } = useChat();
|
||||
|
||||
|
|
@ -79,6 +83,10 @@ export default function Screen() {
|
|||
overscan: 6,
|
||||
});
|
||||
|
||||
/**
|
||||
* Loads the next page when the scroll container reaches the top.
|
||||
* @returns Promise that resolves once pagination handling completes.
|
||||
*/
|
||||
const onScroll = React.useCallback(async () => {
|
||||
if (!scrollRef.current) {
|
||||
return;
|
||||
|
|
@ -159,15 +167,21 @@ export default function Screen() {
|
|||
});
|
||||
}, [messagesQuery.isFetchingNextPage, prependAnchor, virtualizer]);
|
||||
|
||||
/**
|
||||
* Triggers asynchronous scroll pagination without returning a promise to JSX.
|
||||
* @returns Void.
|
||||
*/
|
||||
const handleContainerScroll = React.useCallback((): void => {
|
||||
void onScroll();
|
||||
}, [onScroll]);
|
||||
|
||||
return (
|
||||
<div className="w-full h-full flex flex-col overflow-hidden px-2">
|
||||
<div
|
||||
ref={scrollRef}
|
||||
id="chat_container"
|
||||
className="flex-1 max-h-[calc(100vh-151px)] overflow-y-auto px-2.5"
|
||||
onScroll={() => {
|
||||
void onScroll();
|
||||
}}
|
||||
onScroll={handleContainerScroll}
|
||||
>
|
||||
<div
|
||||
className="relative w-full"
|
||||
|
|
|
|||
Loading…
Reference in a new issue