diff --git a/apps/web/tsconfig.app.json b/apps/web/tsconfig.app.json index 381e35c..a514d29 100644 --- a/apps/web/tsconfig.app.json +++ b/apps/web/tsconfig.app.json @@ -24,7 +24,6 @@ "noFallthroughCasesInSwitch": true, "noUncheckedSideEffectImports": true, - "baseUrl": ".", "paths": { "@/*": ["./src/*"] } diff --git a/eslint.config.ts b/eslint.config.ts index 61efd0d..2209bf9 100644 --- a/eslint.config.ts +++ b/eslint.config.ts @@ -3,6 +3,10 @@ import globals from "globals"; import tseslint from "typescript-eslint"; import reactHooks from "eslint-plugin-react-hooks"; import * as tsParser from "@typescript-eslint/parser"; +import { dirname } from "node:path"; +import { fileURLToPath } from "node:url"; + +const tsconfigRootDir = dirname(fileURLToPath(import.meta.url)); export default [ { @@ -14,6 +18,9 @@ export default [ files: ["**/*.{ts,tsx}"], languageOptions: { parser: tsParser, + parserOptions: { + tsconfigRootDir, + }, globals: { ...globals.browser, ...globals.node, diff --git a/packages/chat/src/components/input.tsx b/packages/chat/src/components/input.tsx index 774d575..f447988 100644 --- a/packages/chat/src/components/input.tsx +++ b/packages/chat/src/components/input.tsx @@ -74,7 +74,7 @@ export default function InputComponent({ const reference = addLiveMessage({ height, not_encrypted: true, - timestamp: time, + send_time: time, content: currentValue, sent_by_self: true, message_state: "awaiting", @@ -86,13 +86,13 @@ export default function InputComponent({ height, content: encryptedContext, receiver_id: userId, - timestamp: time, + send_time: time, }).catch((e) => { log(0, "Chat", "red", "Failed to send message", e, { content: currentValue, encryptedContext, receiver_id: userId, - timestamp: time, + send_time: time, }); reference.setFailed(true); toast("error", "Failed to send message"); @@ -108,7 +108,7 @@ export default function InputComponent({ className={cn( "rounded-none border-b-0 pt-0 pb-[env(safe-area-inset-bottom)]", isMobile - ? "border-0 border-t-1 fixed w-full bottom-0 left-0 px-2" + ? "border-0 border-t fixed w-full bottom-0 left-0 px-2" : "rounded-t-xl", )} > @@ -123,7 +123,7 @@ export default function InputComponent({ message={{ height: 0, not_encrypted: true, - timestamp: 0, + send_time: 0, content: value, sent_by_self: true, message_state: "awaiting", diff --git a/packages/chat/src/components/message.tsx b/packages/chat/src/components/message.tsx index 6815e13..0e2e81f 100644 --- a/packages/chat/src/components/message.tsx +++ b/packages/chat/src/components/message.tsx @@ -157,7 +157,7 @@ export default React.memo(MessageComponent, (prev, next) => { return ( prev.notEncrypted === next.notEncrypted && prev.measureRef === next.measureRef && - prev.message.timestamp === next.message.timestamp && + prev.message.send_time === next.message.send_time && prev.message.content === next.message.content && prev.message.height === next.message.height && prev.message.sent_by_self === next.message.sent_by_self && diff --git a/packages/chat/src/context.tsx b/packages/chat/src/context.tsx index 2002191..738211b 100644 --- a/packages/chat/src/context.tsx +++ b/packages/chat/src/context.tsx @@ -22,17 +22,17 @@ export const context = createContext(undefined); const queryClient = new QueryClient(); -function updateMessageStateByTimestamp< - T extends { timestamp: number; message_state: RawMessage["message_state"] }, +function updateMessageStateBySendTime< + T extends { send_time: number; message_state: RawMessage["message_state"] }, >( messages: T[], - timestamp: number, + sendTime: number, messageState: RawMessage["message_state"], ): { next: T[]; updated: boolean } { let updated = false; const next = messages.map((item) => { - if (item.timestamp !== timestamp || item.message_state === messageState) { + if (item.send_time !== sendTime || item.message_state === messageState) { return item; } @@ -54,7 +54,7 @@ function updateMessageStateByTimestamp< * @param props Parameter props. * @returns unknown. */ -export function Provider(props: { children: ReactNode }) { +export default function Provider(props: { children: ReactNode }) { const { getSharedSecret } = useCrypto(); const { get } = useUser(); const { load } = useStorage(); @@ -141,14 +141,14 @@ export function Provider(props: { children: ReactNode }) { } const rawMessages = messages.data.messages; - const sorted = [...rawMessages].sort((a, b) => a.timestamp - b.timestamp); + const sorted = [...rawMessages].sort((a, b) => a.send_time - b.send_time); if (sorted.length > 0) { - const fetchedTimestamps = new Set(sorted.map((item) => item.timestamp)); + const fetchedSendTimes = new Set(sorted.map((item) => item.send_time)); setLiveMessagesState((prev) => { const filtered = prev.filter( - (liveMessage) => !fetchedTimestamps.has(liveMessage.timestamp), + (liveMessage) => !fetchedSendTimes.has(liveMessage.send_time), ); return filtered.length === prev.length ? prev : filtered; @@ -200,19 +200,19 @@ export function Provider(props: { children: ReactNode }) { const rawData = message.data as { chat_partner_id: unknown; - timestamp: unknown; + send_time: unknown; message_state: RawMessage["message_state"]; }; const nextState = { chat_partner_id: Number(rawData.chat_partner_id), - timestamp: Number(rawData.timestamp), + send_time: Number(rawData.send_time), message_state: rawData.message_state, }; if ( !Number.isFinite(nextState.chat_partner_id) || - !Number.isFinite(nextState.timestamp) + !Number.isFinite(nextState.send_time) ) { log( 3, @@ -238,9 +238,9 @@ export function Provider(props: { children: ReactNode }) { } setLiveMessagesState((prev) => { - const { next, updated } = updateMessageStateByTimestamp( + const { next, updated } = updateMessageStateBySendTime( prev, - nextState.timestamp, + nextState.send_time, nextState.message_state, ); return updated ? next : prev; @@ -257,9 +257,9 @@ export function Provider(props: { children: ReactNode }) { let updated = false; const pages = current.pages.map((page) => { - const nextPage = updateMessageStateByTimestamp( + const nextPage = updateMessageStateBySendTime( page, - nextState.timestamp, + nextState.send_time, nextState.message_state, ); diff --git a/packages/chat/src/screen.tsx b/packages/chat/src/screen.tsx index 395e518..60e3f00 100644 --- a/packages/chat/src/screen.tsx +++ b/packages/chat/src/screen.tsx @@ -80,11 +80,11 @@ export default function Screen() { return liveMessagesSnapshot; } - const historicalTimestamps = new Set( - historicalMessages.map((message) => message.timestamp), + const historicalSendTimes = new Set( + historicalMessages.map((message) => message.send_time), ); const liveWithoutDuplicates = liveMessagesSnapshot.filter( - (message) => !historicalTimestamps.has(message.timestamp), + (message) => !historicalSendTimes.has(message.send_time), ); return [...historicalMessages, ...liveWithoutDuplicates]; @@ -97,7 +97,7 @@ export default function Screen() { }, [messages]); const getItemKey = React.useCallback((index: number) => { - return messagesRef.current[index]?.timestamp ?? index; + return messagesRef.current[index]?.send_time ?? index; }, []); // eslint-disable-next-line react-hooks/incompatible-library @@ -167,7 +167,11 @@ export default function Screen() { } setLastLiveMessageCount(count); - }, [lastLiveMessageCount, liveMessagesSnapshot.length, stickyBottomThreshold]); + }, [ + lastLiveMessageCount, + liveMessagesSnapshot.length, + stickyBottomThreshold, + ]); React.useLayoutEffect(() => { if ( @@ -291,7 +295,7 @@ export default function Screen() { return (
(undefined); * @param props Component props with children. * @returns Loading, error, or provider-wrapped JSX. */ -export default function Provider(props: { +export function Provider(props: { children: ReactNode; blockConnection?: boolean; }) { diff --git a/tsconfig.json b/tsconfig.json deleted file mode 100644 index b2e1f1a..0000000 --- a/tsconfig.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "compilerOptions": { - "module": "esnext", - "baseUrl": ".", - "paths": { - "@app/*": ["packages/*/src", "apps/*/src"] - } - } -}