Skip to content

Commit 63a61b5

Browse files
author
Ruslan Farkhutdinov
committed
Chat: Add generic attachments
1 parent 1e08f95 commit 63a61b5

5 files changed

Lines changed: 217 additions & 185 deletions

File tree

packages/devextreme-angular/src/ui/chat/index.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
QueryList
2222
} from '@angular/core';
2323

24+
export { ExplicitTypes } from 'devextreme/ui/chat';
2425

2526
import DataSource from 'devextreme/data/data_source';
2627
import dxChat from 'devextreme/ui/chat';
@@ -88,7 +89,7 @@ import {
8889
IterableDifferHelper
8990
]
9091
})
91-
export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges, DoCheck {
92+
export class DxChatComponent<TAttachment = any> extends DxComponent implements OnDestroy, OnChanges, DoCheck {
9293

9394
@ContentChildren(PROPERTY_TOKEN_alerts)
9495
set _alertsContentChildren(value: QueryList<CollectionNestedOption>) {
@@ -110,7 +111,7 @@ export class DxChatComponent extends DxComponent implements OnDestroy, OnChanges
110111
this.setChildren('typingUsers', value);
111112
}
112113

113-
instance: DxChat = null;
114+
instance: DxChat<TAttachment> = null;
114115

115116
/**
116117
* [descr:WidgetOptions.accessKey]

packages/devextreme-react/src/chat.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"use client"
2+
export { ExplicitTypes } from "devextreme/ui/chat";
23
import * as React from "react";
34
import { memo, forwardRef, useImperativeHandle, useRef, useMemo, ForwardedRef, Ref, ReactElement } from "react";
45
import dxChat, {
@@ -18,22 +19,23 @@ type ReplaceFieldTypes<TSource, TReplacement> = {
1819
[P in keyof TSource]: P extends keyof TReplacement ? TReplacement[P] : TSource[P];
1920
}
2021

21-
type IChatOptionsNarrowedEvents = {
22-
onAttachmentDownload?: ((e: AttachmentDownloadEvent) => void) | undefined;
23-
onDisposing?: ((e: DisposingEvent) => void);
24-
onInitialized?: ((e: InitializedEvent) => void);
25-
onMessageDeleted?: ((e: MessageDeletedEvent) => void) | undefined;
26-
onMessageDeleting?: ((e: MessageDeletingEvent) => void) | undefined;
27-
onMessageEditCanceled?: ((e: MessageEditCanceledEvent) => void) | undefined;
28-
onMessageEditingStart?: ((e: MessageEditingStartEvent) => void) | undefined;
29-
onMessageEntered?: ((e: MessageEnteredEvent) => void) | undefined;
30-
onMessageUpdated?: ((e: MessageUpdatedEvent) => void) | undefined;
31-
onMessageUpdating?: ((e: MessageUpdatingEvent) => void) | undefined;
32-
onTypingEnd?: ((e: TypingEndEvent) => void) | undefined;
33-
onTypingStart?: ((e: TypingStartEvent) => void) | undefined;
22+
type IChatOptionsNarrowedEvents<TAttachment = any> = {
23+
onAttachmentDownload?: ((e: AttachmentDownloadEvent<TAttachment>) => void) | undefined;
24+
onDisposing?: ((e: DisposingEvent<TAttachment>) => void);
25+
onInitialized?: ((e: InitializedEvent<TAttachment>) => void);
26+
onMessageDeleted?: ((e: MessageDeletedEvent<TAttachment>) => void) | undefined;
27+
onMessageDeleting?: ((e: MessageDeletingEvent<TAttachment>) => void) | undefined;
28+
onMessageEditCanceled?: ((e: MessageEditCanceledEvent<TAttachment>) => void) | undefined;
29+
onMessageEditingStart?: ((e: MessageEditingStartEvent<TAttachment>) => void) | undefined;
30+
onMessageEntered?: ((e: MessageEnteredEvent<TAttachment>) => void) | undefined;
31+
onMessageUpdated?: ((e: MessageUpdatedEvent<TAttachment>) => void) | undefined;
32+
onMessageUpdating?: ((e: MessageUpdatingEvent<TAttachment>) => void) | undefined;
33+
onTypingEnd?: ((e: TypingEndEvent<TAttachment>) => void) | undefined;
34+
onTypingStart?: ((e: TypingStartEvent<TAttachment>) => void) | undefined;
3435
}
3536

36-
type IChatOptions = React.PropsWithChildren<ReplaceFieldTypes<Properties, IChatOptionsNarrowedEvents> & IHtmlOptions & {
37+
type IChatOptions<TAttachment = any> = React.PropsWithChildren<ReplaceFieldTypes<Properties<TAttachment>, IChatOptionsNarrowedEvents<TAttachment>> & IHtmlOptions & {
38+
dataSource?: Properties<TAttachment>["dataSource"];
3739
emptyViewRender?: (...params: any) => React.ReactNode;
3840
emptyViewComponent?: React.ComponentType<any>;
3941
messageRender?: (...params: any) => React.ReactNode;
@@ -42,13 +44,13 @@ type IChatOptions = React.PropsWithChildren<ReplaceFieldTypes<Properties, IChatO
4244
onItemsChange?: (value: Array<Message>) => void;
4345
}>
4446

45-
interface ChatRef {
46-
instance: () => dxChat;
47+
interface ChatRef<TAttachment = any> {
48+
instance: () => dxChat<TAttachment>;
4749
}
4850

4951
const Chat = memo(
5052
forwardRef(
51-
(props: React.PropsWithChildren<IChatOptions>, ref: ForwardedRef<ChatRef>) => {
53+
<TAttachment = any>(props: React.PropsWithChildren<IChatOptions<TAttachment>>, ref: ForwardedRef<ChatRef<TAttachment>>) => {
5254
const baseRef = useRef<ComponentRef>(null);
5355

5456
useImperativeHandle(ref, () => (
@@ -91,7 +93,7 @@ const Chat = memo(
9193
]), []);
9294

9395
return (
94-
React.createElement(BaseComponent<React.PropsWithChildren<IChatOptions>>, {
96+
React.createElement(BaseComponent<React.PropsWithChildren<IChatOptions<TAttachment>>>, {
9597
WidgetClass: dxChat,
9698
ref: baseRef,
9799
subscribableOptions,
@@ -104,7 +106,7 @@ const Chat = memo(
104106
);
105107
},
106108
),
107-
) as (props: React.PropsWithChildren<IChatOptions> & { ref?: Ref<ChatRef> }) => ReactElement | null;
109+
) as <TAttachment = any>(props: React.PropsWithChildren<IChatOptions<TAttachment>> & { ref?: Ref<ChatRef<TAttachment>> }) => ReactElement | null;
108110

109111

110112
// owners:

packages/devextreme-vue/src/chat.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
export { ExplicitTypes } from "devextreme/ui/chat";
12
import { PropType } from "vue";
23
import { defineComponent } from "vue";
34
import { prepareComponentConfig } from "./core/index";

0 commit comments

Comments
 (0)