Skip to content

Commit

Permalink
lint, docs, format
Browse files Browse the repository at this point in the history
  • Loading branch information
vladvelici committed Nov 7, 2024
1 parent 51247a5 commit 0f23f59
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 16 deletions.
23 changes: 16 additions & 7 deletions demo/src/components/MessageComponent/MessageComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ interface MessageProps {

const shortDateTimeFormatter = new Intl.DateTimeFormat('default', {
hour: '2-digit',
minute: '2-digit'
minute: '2-digit',
});

const shortDateFullFormatter = new Intl.DateTimeFormat('default', {
day: '2-digit',
month: '2-digit',
year: 'numeric',
hour: '2-digit',
minute: '2-digit'
minute: '2-digit',
});

function shortDate(date: Date): string {
Expand Down Expand Up @@ -79,16 +79,19 @@ export const MessageComponent: React.FC<MessageProps> = ({
<span className="short">{shortDate(message.createdAt)}</span>
<span className="long">{message.createdAt.toLocaleString()}</span>
</span>
{ (message.isUpdated && message.updatedAt) ? <>
{message.isUpdated && message.updatedAt ? (
<>
{' '}
&middot; Edited{' '}
<span className="sent-at-time">
<span className="short">{shortDate(message.updatedAt)}</span>
<span className="long">{message.updatedAt.toLocaleString()}</span>
</span>
{ message.updatedBy ? <span> by {message.updatedBy}</span> : '' }
</> : ''
}
{message.updatedBy ? <span> by {message.updatedBy}</span> : ''}
</>
) : (
''
)}
</div>
<div
className={clsx('px-4 py-2 rounded-lg inline-block', {
Expand All @@ -98,14 +101,20 @@ export const MessageComponent: React.FC<MessageProps> = ({
>
{message.text}
</div>
<div className="buttons">
<div
className="buttons"
role="group"
aria-label="Message actions"
>
<FaPencil
className="cursor-pointer text-gray-100 m-1 hover:text-gray-500 inline-block"
onClick={handleMessageUpdate}
aria-label="Edit message"
></FaPencil>
<FaTrash
className="cursor-pointer text-red-500 m-1 hover:text-red-700 inline-block"
onClick={handleMessageDelete}
aria-label="Delete message"
/>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion demo/src/containers/Chat/Chat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const Chat = () => {
}

// if the message is not in the list, add it
const newArray = [...prevMessages, message.message];
const newArray = [...prevMessages, message.message];

// and put it at the right place
for (let i = newArray.length - 1; i > 1; i--) {
Expand Down
2 changes: 2 additions & 0 deletions src/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ export type {
MessageSubscriptionResponse,
QueryOptions,
SendMessageParams,
UpdateMessageDetails,
UpdateMessageParams,
} from './messages.js';
export type { Metadata } from './metadata.js';
export type { Occupancy, OccupancyEvent, OccupancyListener, OccupancySubscriptionResponse } from './occupancy.js';
Expand Down
3 changes: 1 addition & 2 deletions src/core/messages.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import * as Ably from 'ably';

import { ActionMetadata } from './action-metadata.js';
import { getChannel, messagesChannelName } from './channel.js';
import { ChatApi } from './chat-api.js';
import {
Expand Down Expand Up @@ -146,7 +145,7 @@ export interface SendMessageParams {
// eslint-disable-next-line @typescript-eslint/no-empty-object-type
export interface UpdateMessageParams extends SendMessageParams {}

/*
/**
* Allows setting optional details about the update operation itself.
*/
export interface UpdateMessageDetails {
Expand Down
2 changes: 1 addition & 1 deletion test/core/message.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ describe('ChatMessage', () => {
timeserial,
);

expect(message.createdAt).toEqual(new Date(1672531200000))
expect(message.createdAt).toEqual(new Date(1672531200000));
});

it('is the same as another message', () => {
Expand Down
4 changes: 2 additions & 2 deletions test/core/messages.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,9 +171,9 @@ describe('messages integration', () => {
// send a message, and then delete it
const message1 = await room.messages.send({ text: 'Hello there!' });
await new Promise((resolve) => setTimeout(resolve, 100));
const updated1 = await room.messages.update(message1, { text: "bananas" });
const updated1 = await room.messages.update(message1, { text: 'bananas' });

expect(updated1.text).toBe("bananas");
expect(updated1.text).toBe('bananas');
expect(updated1.timeserial).toBe(message1.timeserial);
expect(updated1.createdAt.getTime()).toBe(message1.createdAt.getTime());
expect(updated1.updatedAt).toBeDefined();
Expand Down
6 changes: 3 additions & 3 deletions test/core/messages.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describe('Messages', () => {
it<TestContext>('should be able to send message and get it back from response', async (context) => {
const { chatApi } = context;
const timestamp = Date.now();
const timeserial = 'abcdefghij@'+timestamp+'-123';
const timeserial = 'abcdefghij@' + String(timestamp) + '-123';
vi.spyOn(chatApi, 'sendMessage').mockResolvedValue({
timeserial: timeserial,
createdAt: timestamp,
Expand All @@ -89,7 +89,7 @@ describe('Messages', () => {
it<TestContext>('should be able to delete a message and get it back from response', async (context) => {
const { chatApi } = context;
const sendTimestamp = Date.now();
const sendTimeserial = 'abcdefghij@'+sendTimestamp+'-123';
const sendTimeserial = 'abcdefghij@' + String(sendTimestamp) + '-123';
vi.spyOn(chatApi, 'sendMessage').mockResolvedValue({
timeserial: sendTimeserial,
createdAt: sendTimestamp,
Expand Down Expand Up @@ -122,7 +122,7 @@ describe('Messages', () => {
it<TestContext>('should be able to send message with headers and metadata and get it back from response', async (context) => {
const { chatApi, realtime } = context;
const timestamp = Date.now();
const timeserial = 'abcdefghij@'+timestamp+'-123';
const timeserial = 'abcdefghij@' + String(timestamp) + '-123';
vi.spyOn(chatApi, 'sendMessage').mockResolvedValue({
timeserial: timeserial,
createdAt: timestamp,
Expand Down

0 comments on commit 0f23f59

Please sign in to comment.