Skip to content

Commit b921937

Browse files
committed
Channel preview supports polls, quote poll preview
1 parent 100468b commit b921937

File tree

9 files changed

+99
-11
lines changed

9 files changed

+99
-11
lines changed

angular.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@
1313
"@schematics/angular:component": {
1414
"style": "scss",
1515
"inlineStyle": true,
16-
"export": true
16+
"export": true,
17+
"changeDetection": "OnPush"
1718
}
1819
},
1920
"root": "projects/stream-chat-angular",
@@ -219,8 +220,7 @@
219220
"projectType": "application",
220221
"schematics": {
221222
"@schematics/angular:component": {
222-
"style": "scss",
223-
"changeDetection": "OnPush"
223+
"style": "scss"
224224
},
225225
"@schematics/angular:application": {
226226
"strict": true

projects/sample-app/src/app/app.component.html

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@
5555
<app-emoji-picker [emojiInput$]="emojiInput$"></app-emoji-picker>
5656
</ng-template>
5757

58-
<ng-template #pollTemplate let-pollId="pollId" let-messageId="messageId">
59-
<stream-poll [pollId]="pollId" [messageId]="messageId"> </stream-poll>
58+
<ng-template
59+
#pollTemplate
60+
let-pollId="pollId"
61+
let-messageId="messageId"
62+
let-isQuote="isQuote"
63+
>
64+
<ng-container *ngIf="isQuote; else poll">
65+
<stream-poll-preview
66+
[pollId]="pollId"
67+
[messageId]="messageId"
68+
></stream-poll-preview>
69+
</ng-container>
70+
<ng-template #poll>
71+
<stream-poll [pollId]="pollId" [messageId]="messageId"> </stream-poll>
72+
</ng-template>
6073
</ng-template>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ export class ChannelPreviewComponent implements OnInit, OnDestroy {
169169
) || message.text;
170170
} else if (message?.attachments && message.attachments.length) {
171171
this.latestMessageText = 'streamChat.🏙 Attachment...';
172+
} else if (message?.poll_id) {
173+
this.latestMessageText = `📊 ${message.poll?.name}`;
172174
}
173175
if (this.latestMessage && this.latestMessage.type === 'regular') {
174176
this.latestMessageTime = isOnSeparateDate(

projects/stream-chat-angular/src/lib/message-input/message-input.component.html

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,23 @@
9191
[attachments]="quotedMessageAttachments"
9292
[messageId]="quotedMessage.id"
9393
></stream-attachment-list>
94+
<ng-container
95+
*ngIf="
96+
quotedMessage?.poll_id &&
97+
(customTemplatesService.pollTemplate$ | async)
98+
"
99+
>
100+
<ng-container
101+
*ngTemplateOutlet="
102+
(customTemplatesService.pollTemplate$ | async)!;
103+
context: {
104+
pollId: quotedMessage?.poll_id,
105+
messageId: quotedMessage?.id,
106+
isQuote: true
107+
}
108+
"
109+
></ng-container>
110+
</ng-container>
94111
<div class="str-chat__quoted-message-text">
95112
<ng-container
96113
*ngTemplateOutlet="

projects/stream-chat-angular/src/lib/message/message.component.html

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,11 @@
199199
<ng-container
200200
*ngTemplateOutlet="
201201
(customTemplatesService.pollTemplate$ | async)!;
202-
context: { pollId: message?.poll_id, messageId: message?.id }
202+
context: {
203+
pollId: message?.poll_id,
204+
messageId: message?.id,
205+
isQuote: false
206+
}
203207
"
204208
></ng-container>
205209
</ng-container>
@@ -380,6 +384,23 @@
380384
"
381385
></ng-container>
382386
</ng-container>
387+
<ng-container
388+
*ngIf="
389+
message?.quoted_message?.poll_id &&
390+
(customTemplatesService.pollTemplate$ | async)
391+
"
392+
>
393+
<ng-container
394+
*ngTemplateOutlet="
395+
(customTemplatesService.pollTemplate$ | async)!;
396+
context: {
397+
pollId: message?.quoted_message?.poll_id,
398+
messageId: message?.quoted_message?.id,
399+
isQuote: true
400+
}
401+
"
402+
></ng-container>
403+
</ng-container>
383404
<ng-container *ngIf="message?.quoted_message">
384405
<ng-container
385406
*ngTemplateOutlet="

projects/stream-chat-angular/src/lib/polls/poll-actions/poll-actions.component.html

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,11 @@
123123
<stream-notification-list></stream-notification-list>
124124
</ng-template>
125125
<ng-template #endVote>
126-
<div class="str-chat__dialog">
127-
<div class="str-chat__dialog__body str-chat-angular__dialog-body">
126+
<div
127+
class="str-chat__dialog str-chat__dialog--prompt str-chat__modal__end-vote"
128+
>
129+
<div class="str-chat__dialog__body">
130+
<div class="str-chat__dialog__title" translate>End poll</div>
128131
<div class="str-chat__dialog__prompt" translate>
129132
After a poll is closed, no more votes can be cast
130133
</div>
Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
<p>poll-preview works!</p>
1+
<div
2+
class="str-chat__quoted-poll-preview"
3+
[class.str-chat__quoted-poll-preview--closed]="isClosed"
4+
>
5+
<div class="str-chat__quoted-poll-preview__icon">📊</div>
6+
<div class="str-chat__quoted-poll-preview__name">{{ name }}</div>
7+
</div>
Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,33 @@
1-
import { Component } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component } from '@angular/core';
2+
import { BasePollComponent } from '../base-poll.component';
3+
import { Poll } from 'stream-chat';
24

35
@Component({
46
selector: 'stream-poll-preview',
57
templateUrl: './poll-preview.component.html',
68
styles: [],
9+
changeDetection: ChangeDetectionStrategy.OnPush,
710
})
8-
export class PollPreviewComponent {}
11+
export class PollPreviewComponent extends BasePollComponent {
12+
name = '';
13+
isClosed = false;
14+
15+
protected stateStoreSelector(
16+
poll: Poll,
17+
markForCheck: () => void
18+
): () => void {
19+
const unsubscribe = poll.state.subscribeWithSelector(
20+
(state) => ({
21+
name: state.name,
22+
is_closed: state.is_closed,
23+
}),
24+
(state) => {
25+
this.name = state.name;
26+
this.isClosed = state.is_closed ?? false;
27+
markForCheck();
28+
}
29+
);
30+
31+
return unsubscribe;
32+
}
33+
}

projects/stream-chat-angular/src/public-api.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,3 +100,4 @@ export * from './lib/polls/poll-actions/poll-results/poll-vote/poll-vote.compone
100100
export * from './lib/polls/poll-actions/poll-answers-list/poll-answers-list.component';
101101
export * from './lib/polls/poll-actions/upsert-answer/upsert-answer.component';
102102
export * from './lib/polls/poll-actions/add-option/add-option.component';
103+
export * from './lib/polls/poll-preview/poll-preview.component';

0 commit comments

Comments
 (0)