Skip to content
This repository has been archived by the owner on Feb 6, 2024. It is now read-only.

Commit

Permalink
feat(#471): count answers with slots
Browse files Browse the repository at this point in the history
  • Loading branch information
peterpeterparker committed Nov 18, 2019
1 parent 131e2bb commit 95f36a3
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
2 changes: 0 additions & 2 deletions webcomponents/slides/poll/src/components.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export namespace Components {
'afterSwipe': () => Promise<void>;
'beforeSwipe': (_enter: boolean, _reveal: boolean) => Promise<boolean>;
'connectPollServer': boolean;
'countAnswers': number;
'customActions': boolean;
'customBackground': boolean;
'hideContent': () => Promise<void>;
Expand Down Expand Up @@ -44,7 +43,6 @@ declare global {
declare namespace LocalJSX {
interface DeckgoSlidePoll {
'connectPollServer'?: boolean;
'countAnswers'?: number;
'customActions'?: boolean;
'customBackground'?: boolean;
'imgAlt'?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export class DeckdeckgoSlidePoll implements DeckdeckgoSlideResize {
@Prop({reflectToAttr: true}) imgSrc: string;
@Prop({reflectToAttr: true}) imgAlt: string;

@Prop() countAnswers: number = 5;
@State()
private countAnswers: number = 5;

private answerSlots: number[];

Expand Down Expand Up @@ -62,7 +63,9 @@ export class DeckdeckgoSlidePoll implements DeckdeckgoSlideResize {
private subscription: Subscription;
private updateChartSubscription: Subscription;

componentWillLoad() {
async componentWillLoad() {
this.countAnswers = await this.initCountAnswers();

this.answerSlots = Array.from({length: this.countAnswers}, (_v, i) => i);

this.communicationService.watchPollKey().pipe(filter((key: string) => key !== undefined), take(1)).subscribe(async (key: string) => {
Expand All @@ -84,6 +87,23 @@ export class DeckdeckgoSlidePoll implements DeckdeckgoSlideResize {
});
}

private initCountAnswers(): Promise<number> {
return new Promise<number>((resolve) => {
const slots: NodeListOf<HTMLElement> = this.el.querySelectorAll(':scope > [slot]');

if (!slots || slots.length <= 0) {
resolve(0);
return;
}

const filterAnswers: HTMLElement[] = Array.from(slots).filter((slot: HTMLElement) => {
return slot.getAttribute('slot').indexOf('answer') > -1
});

resolve(filterAnswers ? filterAnswers.length : 0);
});
}

async componentDidLoad() {
await hideLazyLoadImages(this.el);

Expand Down
1 change: 0 additions & 1 deletion webcomponents/slides/poll/src/components/slide/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
| Property | Attribute | Description | Type | Default |
| ------------------- | --------------------- | ----------- | --------- | ----------- |
| `connectPollServer` | `connect-poll-server` | | `boolean` | `true` |
| `countAnswers` | `count-answers` | | `number` | `5` |
| `customActions` | `custom-actions` | | `boolean` | `false` |
| `customBackground` | `custom-background` | | `boolean` | `false` |
| `imgAlt` | `img-alt` | | `string` | `undefined` |
Expand Down

0 comments on commit 95f36a3

Please sign in to comment.