Skip to content

Commit a5898fa

Browse files
authored
Merge pull request #407 from GetStream/new-content-injection-points
New content injection points
2 parents 93ed9f0 + 790c158 commit a5898fa

File tree

8 files changed

+76
-11
lines changed

8 files changed

+76
-11
lines changed

docusaurus/docs/Angular/components/ChannelListComponent.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,5 +32,18 @@ The `ChannelList` component uses the [`Icon`](./IconComponent.mdx) component to
3232

3333
If you only want to customize the channel preview items (not the whole list), see the [channel preview customization](./ChannelPreviewComponent.mdx/#customization) guide.
3434

35+
**Example 3** - Content injection points
36+
37+
It's possible to inject your own content to the top or to the bottom of the channel list:
38+
39+
```html
40+
<stream-channel-list>
41+
<input channel-list-top placeholder="Search" />
42+
<button channel-list-bottom>Add new channel</button>
43+
</stream-channel-list>
44+
```
45+
46+
Use the `channel-list-top` attribute to inject content at the top of the channel list, and the `channel-list-bottom` to display content at the bottom of the channel list.
47+
3548
[//]: # "Start of generated content"
3649
[//]: # "End of generated content"

projects/customizations-example/src/app/app.component.html

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<div id="root">
2-
<stream-channel-list></stream-channel-list>
2+
<stream-channel-list>
3+
<input channel-list-top placeholder="Search" />
4+
<button channel-list-bottom>Add new channel</button>
5+
</stream-channel-list>
36
<stream-channel>
47
<stream-channel-header></stream-channel-header>
58
<stream-message-list></stream-message-list>
@@ -225,3 +228,7 @@
225228
(closeThread)="closeThreadHandler()"
226229
></app-thread-header>
227230
</ng-template>
231+
232+
<ng-template #customChannelInfo let-channel="channel">
233+
This channel has {{ channel?.data?.member_count }} members
234+
</ng-template>

projects/customizations-example/src/app/app.component.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import {
44
TemplateRef,
55
ViewChild,
66
} from '@angular/core';
7+
import { ChannelHeaderInfoContext } from 'projects/stream-chat-angular/src/public-api';
78
import { Channel } from 'stream-chat';
89
import {
910
ChatClientService,
@@ -79,6 +80,8 @@ export class AppComponent implements AfterViewInit {
7980
private notificationTemplate!: TemplateRef<NotificationContext>;
8081
@ViewChild('threadHeaderTemplate')
8182
private threadHeaderTemplate!: TemplateRef<ThreadHeaderContext>;
83+
@ViewChild('customChannelInfo')
84+
private chstomChannelInfoTemplate!: TemplateRef<ChannelHeaderInfoContext>;
8285

8386
constructor(
8487
private chatService: ChatClientService,
@@ -149,6 +152,9 @@ export class AppComponent implements AfterViewInit {
149152
this.customTemplatesService.threadHeaderTemplate$.next(
150153
this.threadHeaderTemplate
151154
);
155+
this.customTemplatesService.channelHeaderInfoTemplate$.next(
156+
this.chstomChannelInfoTemplate
157+
);
152158
}
153159

154160
inviteClicked(channel: Channel) {

projects/stream-chat-angular/src/lib/channel-header/channel-header.component.html

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,25 @@
2424
>
2525
{{ displayText }}
2626
</p>
27-
<p
28-
data-testid="info"
29-
class="
30-
str-chat__header-livestream-left--members str-chat__channel-header-info
27+
<ng-container
28+
*ngTemplateOutlet="
29+
channelHeaderInfoTemplate || defaultChannelInfo;
30+
context: getChannelInfoContext()
3131
"
32-
>
33-
{{'streamChat.{{ memberCount }} members' | translate:memberCountParam}}
34-
{{canReceiveConnectEvents ? ('streamChat.{{ watcherCount }} online' |
35-
translate:watcherCountParam) : ''}}
36-
</p>
32+
></ng-container>
33+
<ng-template #defaultChannelInfo>
34+
<p
35+
data-testid="info"
36+
class="
37+
str-chat__header-livestream-left--members
38+
str-chat__channel-header-info
39+
"
40+
>
41+
{{'streamChat.{{ memberCount }} members' | translate:memberCountParam}}
42+
{{canReceiveConnectEvents ? ('streamChat.{{ watcherCount }} online' |
43+
translate:watcherCountParam) : ''}}
44+
</p>
45+
</ng-template>
3746
</div>
3847
<ng-container *ngIf="channelActionsTemplate">
3948
<ng-container

projects/stream-chat-angular/src/lib/channel-header/channel-header.component.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import { ChannelService } from '../channel.service';
1212
import { ChatClientService } from '../chat-client.service';
1313
import { CustomTemplatesService } from '../custom-templates.service';
1414
import { getChannelDisplayText } from '../get-channel-display-text';
15-
import { ChannelActionsContext, DefaultStreamChatGenerics } from '../types';
15+
import {
16+
ChannelActionsContext,
17+
ChannelHeaderInfoContext,
18+
DefaultStreamChatGenerics,
19+
} from '../types';
1620

1721
/**
1822
* The `ChannelHeader` component displays the avatar and name of the currently active channel along with member and watcher information. You can read about [the difference between members and watchers](https://getstream.io/chat/docs/javascript/watch_channel/?language=javascript#watchers-vs-members) in the platform documentation. Please note that number of watchers is only displayed if the user has [`connect-events` capability](https://getstream.io/chat/docs/javascript/channel_capabilities/?language=javascript)
@@ -24,6 +28,7 @@ import { ChannelActionsContext, DefaultStreamChatGenerics } from '../types';
2428
})
2529
export class ChannelHeaderComponent implements OnInit, OnDestroy {
2630
channelActionsTemplate?: TemplateRef<ChannelActionsContext>;
31+
channelHeaderInfoTemplate?: TemplateRef<ChannelHeaderInfoContext>;
2732
activeChannel: Channel<DefaultStreamChatGenerics> | undefined;
2833
canReceiveConnectEvents: boolean | undefined;
2934
private subscriptions: Subscription[] = [];
@@ -55,6 +60,14 @@ export class ChannelHeaderComponent implements OnInit, OnDestroy {
5560
}
5661
)
5762
);
63+
this.subscriptions.push(
64+
this.customTemplatesService.channelHeaderInfoTemplate$.subscribe(
65+
(template) => {
66+
this.channelHeaderInfoTemplate = template;
67+
this.cdRef.detectChanges();
68+
}
69+
)
70+
);
5871
}
5972

6073
ngOnDestroy(): void {
@@ -70,6 +83,10 @@ export class ChannelHeaderComponent implements OnInit, OnDestroy {
7083
return { channel: this.activeChannel! };
7184
}
7285

86+
getChannelInfoContext(): ChannelHeaderInfoContext {
87+
return { channel: this.activeChannel! };
88+
}
89+
7390
get memberCountParam() {
7491
return { memberCount: this.activeChannel?.data?.member_count || 0 };
7592
}

projects/stream-chat-angular/src/lib/channel-list/channel-list.component.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
>
3232
{{ "streamChat.You have no channels currently" | translate }}
3333
</p>
34+
<ng-content select="[channel-list-top]"></ng-content>
3435
<ng-container
3536
*ngFor="let channel of channels$ | async; trackBy: trackByChannelId"
3637
>
@@ -69,6 +70,7 @@
6970
></ng-template>
7071
</button>
7172
</div>
73+
<ng-content select="[channel-list-bottom]"></ng-content>
7274
</div>
7375
</div>
7476
</div>

projects/stream-chat-angular/src/lib/custom-templates.service.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
AttachmentPreviewListContext,
66
AvatarContext,
77
ChannelActionsContext,
8+
ChannelHeaderInfoContext,
89
ChannelPreviewContext,
910
CommandAutocompleteListItemContext,
1011
DeliveredStatusContext,
@@ -211,6 +212,12 @@ export class CustomTemplatesService {
211212
readStatusTemplate$ = new BehaviorSubject<
212213
TemplateRef<ReadStatusContext> | undefined
213214
>(undefined);
215+
/**
216+
* The template used to display additional information about a channel under the channel name inside the [channel header component](../components/ChannelHeaderComponent.mdx)
217+
*/
218+
channelHeaderInfoTemplate$ = new BehaviorSubject<
219+
TemplateRef<ChannelHeaderInfoContext> | undefined
220+
>(undefined);
214221

215222
constructor() {}
216223
}

projects/stream-chat-angular/src/lib/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,7 @@ export type ReadStatusContext = {
289289
message: StreamMessage;
290290
readByText: string;
291291
};
292+
293+
export type ChannelHeaderInfoContext<
294+
T extends DefaultStreamChatGenerics = DefaultStreamChatGenerics
295+
> = { channel: Channel<T> };

0 commit comments

Comments
 (0)