Skip to content

Commit

Permalink
refactor: combine react and core packages into one
Browse files Browse the repository at this point in the history
This change combines the core and react packages into one - so that one import is required to use the full suite of functionality.

It also updates the build:

dist/core is the core libraries only, which are used for the CDN upload.
dist/chat is the entire library - both react and chat.
  • Loading branch information
AndyTWF committed Jan 16, 2025
1 parent 192eed9 commit 6b6948c
Show file tree
Hide file tree
Showing 61 changed files with 16,201 additions and 9,622 deletions.
19,726 changes: 12,565 additions & 7,161 deletions demo/package-lock.json

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions demo/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@ import { FC, useEffect, useState } from 'react';
import { Chat } from './containers/Chat';
import { OccupancyComponent } from './components/OccupancyComponent';
import { UserPresenceComponent } from './components/UserPresenceComponent';
import { ChatRoomProvider } from '@ably/chat/react';
import { RoomOptionsDefaults } from '@ably/chat';
import { RoomOptionsDefaults, ChatRoomProvider } from '@ably/chat';

// We read the roomID from the URL query string and default to 'abcd' if none
// provided. We make sure the URL is updated to always include the roomId. This
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from 'react';
import { useChatConnection } from '@ably/chat/react';
import { ConnectionStatus } from '@ably/chat';
import { ConnectionStatus, useChatConnection } from '@ably/chat';

export const ConnectionStatusComponent: React.FC = () => {
const { currentStatus } = useChatConnection();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FC } from 'react';
import { useOccupancy } from '@ably/chat/react';
import { useOccupancy } from '@ably/chat';
import './OccupancyComponent.css';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import { FC, useState } from 'react';
import { useChatClient, useChatConnection, usePresence, usePresenceListener } from '@ably/chat/react';
import '../../../styles/global.css';
import './UserPresenceComponent.css';
import { ConnectionStatus, PresenceMember } from '@ably/chat';
import {
ConnectionStatus,
PresenceMember,
useChatClient,
useChatConnection,
usePresence,
usePresenceListener,
} from '@ably/chat';

interface UserListComponentProps {}

Expand Down
20 changes: 14 additions & 6 deletions demo/src/containers/Chat/Chat.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,21 @@
import { useCallback, useEffect, useRef, useState } from 'react';
import { MessageComponent } from '../../components/MessageComponent';
import { MessageInput } from '../../components/MessageInput';
import { useChatClient, useChatConnection, useMessages, useRoomReactions, useTyping } from '@ably/chat/react';
import { ReactionInput } from '../../components/ReactionInput';
import { ConnectionStatusComponent } from '../../components/ConnectionStatusComponent';
import { ConnectionStatus, Message, MessageEventPayload, MessageEvents, PaginatedResult, Reaction } from '@ably/chat';
import {
ConnectionStatus,
Message,
MessageEventPayload,
MessageEvents,
PaginatedResult,
Reaction,
useChatClient,
useChatConnection,
useMessages,
useRoomReactions,
useTyping,
} from '@ably/chat';

export const Chat = (props: { roomId: string; setRoomId: (roomId: string) => void }) => {
const chatClient = useChatClient();
Expand All @@ -16,16 +27,14 @@ export const Chat = (props: { roomId: string; setRoomId: (roomId: string) => voi
const isConnected: boolean = currentStatus === ConnectionStatus.Connected;

const backfillPreviousMessages = (getPreviousMessages: ReturnType<typeof useMessages>['getPreviousMessages']) => {
chatClient.logger.debug('backfilling previous messages');
if (getPreviousMessages) {
getPreviousMessages({ limit: 50 })
.then((result: PaginatedResult<Message>) => {
chatClient.logger.debug('backfilled messages', result.items);
setMessages(result.items.filter((m) => !m.isDeleted).reverse());
setLoading(false);
})
.catch((error: unknown) => {
chatClient.logger.error('Error fetching initial messages', error);
console.error('Failed to backfill previous messages', error);
});
}
};
Expand Down Expand Up @@ -131,7 +140,6 @@ export const Chat = (props: { roomId: string; setRoomId: (roomId: string) => voi
const messagesEndRef = useRef<HTMLDivElement | null>(null);

useEffect(() => {
chatClient.logger.debug('updating getPreviousMessages useEffect', { getPreviousMessages });
backfillPreviousMessages(getPreviousMessages);
}, [getPreviousMessages]);

Expand Down
3 changes: 1 addition & 2 deletions demo/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ import React from 'react';
import ReactDOM from 'react-dom/client';
import * as Ably from 'ably';
import { ClientOptions } from 'ably';
import { ChatClient, LogLevel } from '@ably/chat';
import { ChatClient, LogLevel, ChatClientProvider } from '@ably/chat';
import { nanoid } from 'nanoid';
import App from './App.tsx';
import './index.css';
import { ChatClientProvider } from '@ably/chat/react';
import { AblyProvider } from 'ably/react';

// Generate a random clientId and remember it for the length of the session, so
Expand Down
Loading

0 comments on commit 6b6948c

Please sign in to comment.